在 Python 中,使用 matplotlib,有没有办法改变不同线条样式的虚线距离,例如,使用以下命令:
plt.plot(x,y,linestyle='--')
最佳答案
您可以使用 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
关于python - 在matplotlib中更改虚线中的破折号间距,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35099130/