更改matplotlib中虚线中虚线的间距

2024-05-23 14:55:24 发布

您现在位置:Python中文网/ 问答频道 /正文

在Python中,使用matplotlib可以更改不同线型的虚线距离,例如,使用以下命令:

plt.plot(x,y,linestyle='--')

Tags: 命令距离plotmatplotlibplt虚线线型linestyle
1条回答
网友
1楼 · 发布于 2024-05-23 14:55:24

可以使用plot命令中的dashes=(length, interval space)参数直接指定虚线长度/空格。

import matplotlib.pyplot as plt

fig,ax = plt.subplots()
ax.plot([0, 1], [0, 1], linestyle='--', dashes=(5, 1)) #length of 5, space of 1
ax.plot([0, 1], [0, 2], linestyle='--', dashes=(5, 5)) #length of 5, space of 5
ax.plot([0, 1], [0, 3], linestyle='--', dashes=(5, 10)) #length of 5, space of 10
ax.plot([0, 1], [0, 4], linestyle='--', dashes=(5, 20)) #length of 5, space of 20

lines

相关问题 更多 >