python - 在matplotlib中更改虚线中的破折号间距

标签 python matplotlib plot line subplot

在 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

lines

关于python - 在matplotlib中更改虚线中的破折号间距,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35099130/

相关文章:

python - 将 imshow 与共享 x 轴与 matplotlib 一起使用

python - 导入 matplotlib.pyplot Python 时出错

r - 绘图轴不在原点相交

plot - 如何在 gnuplot 中使标签和标题加粗?

python - QGIS 在 python 中导入 opencv 时终止

python - 矩阵中的行相乘

python - 使用带有 Tipfy 的任何 OpenID 进行身份验证

python - 如何在散点图的顶部绘制附加点?

r - R 中的堆积条形图,每天多行

Python Selenium Webdriver : finding #document element