![](/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.