Change spacing of dashes in dashed line in matplotlib [duplicate]

…衆ロ難τιáo~ 提交于 2019-12-20 16:46:28

问题


In Python, using matplotlib, is there a way to change the distance of the dashes for different linestyles, for example, using the following command:

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

回答1:


You can directly specify the dashes length/space using the dashes=(length, interval space) argument inside the plot command.

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



来源:https://stackoverflow.com/questions/35099130/change-spacing-of-dashes-in-dashed-line-in-matplotlib

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!