我想使用单个注释文本用多个箭头注释多个数据点。我做了一个简单的解决方法:
ax = plt.gca()
ax.plot([1,2,3,4],[1,4,2,6])
an1 = ax.annotate('Test',
xy=(2,4), xycoords='data',
xytext=(30,-80), textcoords='offset points',
arrowprops=dict(arrowstyle="-|>",
connectionstyle="arc3,rad=0.2",
fc="w"))
an2 = ax.annotate('Test',
xy=(3,2), xycoords='data',
xytext=(0,0), textcoords=an1,
arrowprops=dict(arrowstyle="-|>",
connectionstyle="arc3,rad=0.2",
fc="w"))
plt.show()
产生以下结果:
但我不太喜欢这个解决方案,因为它。。。好吧,一个丑陋肮脏的黑客。在
此外,它还会影响注释的外观(主要是使用半透明的bboxes等)。在
所以,如果有人得到了一个实际的解决方案,或者至少有一个如何实现它的想法,请分享。在
我想正确的解决方案将需要太多的努力-子类化_annotationbase并添加对多个箭头的支持。但是我通过添加
alpha=0.0
来消除影响视觉外观的第二个注释的问题。因此,如果没有人能提供更好的解决方案:结果图片:
就个人而言,我会使用set axes fraction coordinates来保证文本标签的位置,然后通过使用color关键字参数使除了一个标签之外的所有标签都可见。在
相关问题 更多 >
编程相关推荐