Ban*_*Gap 20 python matplotlib
我想在我的一个地块中指出一个距离.我想到的是他们在技术图纸中的方式,显示一个双头箭头,旁边有文字.
例:
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")
Run Code Online (Sandbox Code Playgroud)
这导致类似这样的事情(两个hlines不是真的需要,它们只是增加了绘图区域......): 
有没有更快的方法来做到这一点,最好是箭头在确切的位置结束,而不是低于/高于应该的位置?用于自动放置文本的额外点.
编辑:
我一直在玩,annotate但由于字符串必须被牺牲,这个解决方案对我失去了一些吸引力.感谢指出箭头风格,当我尝试类似的东西时它没有工作.我想用一个电话来编写一个小函数是没有办法做的...
unu*_*tbu 24
import matplotlib.pyplot as plt
plt.hlines(7, 0, 2, linestyles='dashed')
plt.hlines(11, 0, 2, linestyles='dashed')
plt.hlines(10, 0, 2, linestyles='dashed')
plt.hlines(8, 0, 2, linestyles='dashed')
plt.annotate(
'', xy=(1, 10), xycoords='data',
xytext=(1, 8), textcoords='data',
arrowprops={'arrowstyle': '<->'})
plt.annotate(
'D = 1', xy=(1, 9), xycoords='data',
xytext=(5, 0), textcoords='offset points')
# alternatively,
# plt.text(1.01, 9, 'D = 1')
plt.show()
Run Code Online (Sandbox Code Playgroud)
产量

有关可用的许多选项的更多信息plt.annotate,请参阅此页面.
如上所示,文本可以使用plt.annotate或放置plt.text.随着plt.annotate您可以指定偏移(例如(5, 0)在点),而与plt.text您可以指定数据坐标中的文本位置(例如(1.01, 9)).
lxo*_*xop 11
尝试使用annotate:
annotate ('', (0.4, 0.2), (0.4, 0.8), arrowprops={'arrowstyle':'<->'})
Run Code Online (Sandbox Code Playgroud)

我不确定自动文本放置.
| 归档时间: |
|
| 查看次数: |
13164 次 |
| 最近记录: |