Python 使用matplotlib打印虚线二维向量?
我正在使用Python 使用matplotlib打印虚线二维向量?,python,matplotlib,Python,Matplotlib,我正在使用quiver在matplotlib中绘制向量: from itertools import chain import matplotlib.pyplot as pyplot pyplot.figure() pyplot.axis('equal') axis = pyplot.gca() axis.quiver(*zip(*map(lambda l: chain(*l), [ ((0, 0), (3, 1)), ((0, 0), (1, 0)), ])), angles=
quiver
在matplotlib中绘制向量:
from itertools import chain
import matplotlib.pyplot as pyplot
pyplot.figure()
pyplot.axis('equal')
axis = pyplot.gca()
axis.quiver(*zip(*map(lambda l: chain(*l), [
((0, 0), (3, 1)),
((0, 0), (1, 0)),
])), angles='xy', scale_units='xy', scale=1)
axis.set_xlim([-4, 4])
axis.set_ylim([-4, 4])
pyplot.draw()
pyplot.show()
这给了我漂亮的箭头,但我如何才能将它们的线条样式更改为虚线、虚线等?啊!实际上,
linestyle='Dash'
确实有效,只是箭袋箭头在默认情况下是填充的,没有设置线宽。它们是补丁而不是路径
如果您这样做:
import matplotlib.pyplot as plt
fig, ax = plt.subplots()
ax.axis('equal')
ax.quiver((0,0), (0,0), (3,1), (1,0), angles='xy', scale_units='xy', scale=1,
linestyle='dashed', facecolor='none', linewidth=1)
ax.axis([-4, 4, -4, 4])
plt.show()
你会得到虚线箭头,但可能不是你想的那样
您可以使用一些参数来更接近,但它仍然不太好看:
import matplotlib.pyplot as plt
fig, ax = plt.subplots()
ax.axis('equal')
ax.quiver((0,0), (0,0), (3,1), (1,0), angles='xy', scale_units='xy', scale=1,
linestyle='dashed', facecolor='none', linewidth=2,
width=0.0001, headwidth=300, headlength=500)
ax.axis([-4, 4, -4, 4])
plt.show()
因此,另一种解决方法是使用图案填充:
import matplotlib.pyplot as plt
fig, ax = plt.subplots()
ax.axis('equal')
ax.quiver((0,0), (0,0), (3,1), (1,0), angles='xy', scale_units='xy', scale=1,
hatch='ooo', facecolor='none')
ax.axis([-4, 4, -4, 4])
plt.show()
linestyle='虚线'
应该可以工作。然而,很明显,它不起作用。这可能是一个错误。@JoeKington::(有什么解决办法的建议吗?不幸的是,我没有想到……另一个问题是:如果我们缩放到不同的纵横比,箭头就会扭曲。