python - 绘制箭头时设置破折号长度

标签 python matplotlib

使用 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/

相关文章:

python - Python按列合并不同大小的表

python - 如何从 Python 程序中创建自定义系统命令?

python - 如何在 matplotlib 中为数据帧中的多个组添加误差线?

python - 如何在 matplotlib 配置文件中定义次要刻度数

python - 如何重置 python tkinter 按钮的背景颜色?

python - 如何在 Python 中解压复杂的嵌套列(字典的字典列表)? [推特广告 API]

python - 保持 OrderedDict 内元素的顺序

python - 如何为许多子图制作一个图例?

python - 使用 matplotlib 绘制动态数据

python - 如何在python中的散点图上绘制一条线?