我想绘制一个箭头,文字可以横跨多个轴线。阅读http://matplotlib.org/users/annotations_guide.html用轴线外的文字绘制箭头
我那么远:
fig,ax = plt.subplots(2,3)
bbox_props = dict(boxstyle="rarrow,pad=0.2", fc="cyan", ec="b", lw=1)
t = ax[0,1].text(-0.8, 1.2, "Mag", ha="center", va="center", rotation=0, size=15, bbox=bbox_props)
这使得
我从text docs发现BBOX是Rectangle一本字典,它具有宽度和高度,但我当套装
bbox_props = dict(boxstyle="rarrow,pad=0.2", fc="cyan", ec="b", lw=1, width=3)
t = ax[0,1].text(-0.8, 1.2, "Mag", ha="center", va="center", rotation=0, size=15, bbox=bbox_props)
我得到一个冲突:
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
<ipython-input-255-006733283545> in <module>()
13 # properties of a rectangle : http://matplotlib.org/api/patches_api.html#matplotlib.patches.Rectangle
14
---> 15 t = ax[0,1].text(-0.8, 1.2, "Mag", ha="center", va="center", rotation=0, size=15, bbox=bbox_props)
16 plt.savefig('example.png', bbox_inches='tight')
/Users/chris/anaconda3/lib/python3.5/site-packages/matplotlib/axes/_axes.py in text(self, x, y, s, fontdict, withdash, **kwargs)
626 if fontdict is not None:
627 t.update(fontdict)
--> 628 t.update(kwargs)
629
630 t.set_clip_path(self.patch)
/Users/chris/anaconda3/lib/python3.5/site-packages/matplotlib/text.py in update(self, kwargs)
242 super(Text, self).update(kwargs)
243 if bbox:
--> 244 self.set_bbox(bbox) # depends on font properties
245
246 def __getstate__(self):
/Users/chris/anaconda3/lib/python3.5/site-packages/matplotlib/text.py in set_bbox(self, rectprops)
514 bbox_transmuter=bbox_transmuter,
515 transform=mtransforms.IdentityTransform(),
--> 516 **props)
517 else:
518 self._bbox_patch = None
TypeError: __init__() got multiple values for argument 'width'
如何用bbox控制我的箭头大小?有没有办法将它扩展到正确的位置?
谢谢! 克里斯
非常感谢你,这是一个非常整洁的解决方案,因为文本保持以箭头为中心,我可以轻松控制其宽度。这比我想象的要复杂,但我学到了一些关于箭头的新东西。那很棒! – scichris