在框外注释框,matplotlib

在框外注释框,matplotlib,matplotlib,patch,annotate,Matplotlib,Patch,Annotate,我希望文本显示在框旁边,而不是框内: 以下是我所做的: import matplotlib as mpl import matplotlib.pyplot as plt from custombox import MyStyle fig = plt.figure(figsize=(10,10)) legend_ax = plt.subplot(111) legend_ax.annotate("Text",xy=(0.5,0.5),xycoords='data',xytext=(0.5, 0.5

我希望文本显示在框旁边,而不是框内:

以下是我所做的:

import matplotlib as mpl
import matplotlib.pyplot as plt
from custombox import MyStyle
fig = plt.figure(figsize=(10,10))
legend_ax = plt.subplot(111) 
legend_ax.annotate("Text",xy=(0.5,0.5),xycoords='data',xytext=(0.5, 0.5),textcoords= ('data'),ha="center",rotation = 180,bbox=dict(boxstyle="angled, pad=0.5", fc='white', lw=4, ec='Black'))    
legend_ax.text(0.6,0.5,"Text", ha="center",size=15)
这是它给我的:

注意:custombox与此链接中写入的文件类似:

我的最终目标是使它看起来像一个传奇,符号(斜角框)出现在代表它的文本旁边


编辑1:正如Ajean所建议的,我已经分别对文本进行了注释,但我无法在箭头中旋转文本。一种方法是将文本和bbox分开(可以使用箭头复制)。我认为,下面的内容与您想要的内容非常接近

import matplotlib.pyplot as plt
from matplotlib import patches

fig = plt.figure(figsize=(5,5))
ax = fig.add_subplot(111)

ax.annotate("Text", (0.4,0.5))
bb = patches.FancyArrow(0.5,0.5,0.1,0.0,length_includes_head=True, width=0.05,
                        head_length=0.03, head_width=0.05, fc='white', ec='black',
                        lw=4)

ax.add_artist(bb)

plt.show()

您可以根据需要对确切的位置进行调整。我不是所有KWARG的专家,因此这可能不是最好的解决方案,但它会起作用。

为什么不分别使用带角度的框和文本进行注释?这样你就可以把它们准确地放在你想要的地方…当我用斜角框注释并使文本如下图所示为空时,我也丢失了框。图例注释(“,xy=(0.5,0.5),xycoords='data',xytext=(0.5,0.5),textcoords=('data'),ha=(center),rotation=180,bbox=dict(boxstyle=“angled,pad=0.5”,fc='white','lw=4,ec='Black'))