我想在我的一幅图中指出距离。我想到的是他们在技术图纸中的做法,显示一个双头箭头,其旁边的距离为文本。
Example:
from matplotlib.pyplot import *
hlines(7,0,2, linestyles='dashed')
hlines(11,0,2, linestyles='dashed')
hlines(10,0,2, linestyles='dashed')
hlines(8,0,2, linestyles='dashed')
plot((1,1),(8,10), 'k',) # arrow line
plot((1,1),(8,8), 'k', marker='v',) # lower arrowhead
plot((1,1),(10,10), 'k', marker='^',) # upper arrowhead
text(1.1,9,"D=1")
This results in something like this (two of the hlines are not really needed, they just increase the drawing area...):
有没有更快的方法来做到这一点,最好是使用在确切位置结束的箭头,而不是低于/高于它们应该在的位置?
自动放置文本也有额外的好处。
Edit:我一直在玩annotate
但由于必须牺牲绳子,所以这个解决方案对我失去了一些吸引力。不过,感谢您指出箭头样式,当我尝试类似的操作时它不起作用。
我想没有办法编写一个小函数来通过一次调用来完成它......