1

I want the text to appear beside the box instead of inside it:

Here is what I did:

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)

Here is what it gives me:

enter image description here

Note: custombox is similar to the file that is written in this link: http://matplotlib.org/1.3.1/users/annotations_guide.html

My ultimate aim is to make it look legend like where the symbol (angled box) appears beside the text that represents it.

EDIT 1: As suggested by Ajean I have annotated text separately but I can't turn of the text within the arrow

user2998764
  • 445
  • 1
  • 6
  • 22
  • Why don't you just annotate with the angled box and with the text separately? That way you can put them exactly where you want them... – Ajean Jun 03 '14 at 20:12
  • when I annotate with angled box and make the text empty like below, I lose the box as well.legend_ax.annotate("",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')) – user2998764 Jun 03 '14 at 20:14

1 Answers1

1

One way to do it would be to separate the text and the bbox (which you can reproduce using an arrow). The following gives me something close to what you want, I think.

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()

You can futz with the exact placement as needed. I'm not an expert on all the kwargs, so this may not be the best solution, but it will work.

Ajean
  • 5,528
  • 14
  • 46
  • 69