Python 更改matplotlib中虚线中破折号的间距
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/35099130/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Change spacing of dashes in dashed line in matplotlib
提问by grover
In Python, using matplotlib, is there a way to change the distance of the dashes for different linestyles, for example, using the following command:
在 Python 中,使用 matplotlib,有没有办法改变不同线型的破折号的距离,例如,使用以下命令:
plt.plot(x,y,linestyle='--')
回答by gcalmettes
You can directly specify the dashes length/space using the dashes=(length, interval space)
argument inside the plot command.
您可以使用dashes=(length, interval space)
plot 命令中的参数直接指定破折号长度/空间。
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