使用 matplotlib 可以很容易地使用自定义破折号样式绘制一条线
plt.plot([0, 5], [0, 5], dashes=(20.0, 20.0))
plt.show()
或
lines = plt.plot([0, 5], [0, 5])
lines[0].set_dashes((20.0, 20.0))
plt.show()
虽然可以用虚线样式绘制箭头
plt.arrow(0, 0, 5, 5, linestyle='dashed')
plt.show()
我似乎无法弄清楚如何使用自定义破折号样式绘制箭头
arrow = plt.arrow(0, 0, 5, 5)
?
plt.show()
使用 plot 函数的 dashes
参数给出
AttributeError: 'FancyArrow' object has no attribute 'set_dashes'
并且由于错误提到返回的 FancyArrow
没有 set_dashes()
方法。可能吗?
最佳答案
你可以传递一个(offset, onoffseq),
where onoffseq is an even length tuple of on and off ink in points.
参见 set_linestyle .
例如,ax.arrow(0, 0, 3, 3, linestyle=(5, (3,6)))
创建一个虚线箭头,墨水上的箭头的长度相对加倍脱墨;使用 ax.arrow(0, 0, 3, 3, linestyle=(5, (3,9)))
,on ink 相对于 off ink 的长度增加了三倍。
此外,offset
参数似乎对设置箭头的 linestyle
没有任何影响,至少在 3.0.3 中,matplotlib
我使用的版本。
关于python - 绘制箭头时设置破折号长度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23264976/