![](/img/trans.png)
[英]How to put variable length tick labels inside the plot canvas in matplotlib?
[英]How to put text inside a box on a plot in matplotlib
以下是示例中的代码:
# these are matplotlib.patch.Patch properties
props = dict(boxstyle='round', facecolor='wheat', alpha=0.5)
# place a text box in upper left in axes coords
ax.text(0.05, 0.95, textstr, transform=ax.transAxes, fontsize=14,
verticalalignment='top', bbox=props)
Matplotlib坐标
使用transform=ax.transAxes
我们可以使用坐标系将元素放入绘图中,其中点(0,0)是左下角,(0,1)左上角,(1,1)是右上角,依此类推。
具体来说:如果我们使用位置(0,0)放置一个文本框,则会在左下角放置一个名为anchor
的特定点。 要更改锚点,您需要为函数调用添加两个参数: verticalalignment
(可能的值: center
, top
, bottom
, baseline
)和horizontalalignment
(可能的值: center
, right
, left
)。
因此,要将框放在左下角,您需要将框的左下角放在图的左下角:
# place a text box in lower left in axes coords
ax.text(0.05, 0.05, textstr, transform=ax.transAxes, fontsize=14,
verticalalignment='bottom', bbox=props)
无论如何,这里是ipython-notebook的链接, 其中包含所有展示位置的示例 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.