This is generally a very difficult thing to do, as the position and the extent of the text is determined when the figure is drawn.
The best way, I guess, is to create a customized Text class, but I do not recommend this unless you're familiar with matplotlib internals. If you're using svn version, you can use patheffect. Otherwise, the easiest workaround is calling "draw" twice (or "savefig" twice). But, getting this right is a bit tricky. For your example, adding another "p.draw()" right after "p.text" will work. Also note that your current code has some issues with zorder, facecolor of the shadow and too small shadow offsets. -JJ On Tue, Jan 19, 2010 at 7:11 AM, Jens_M <jens.melin...@gmail.com> wrote: > > I'm trying to make a shadow effect behind text boxes in a plot (similarly to > what can be done with legends). > > After a fair bit of searching around I found the matplotlib.patches.Shadow > class which seems to be good for this. But I cannot get it to work properly. > I suspect it has something to do with different transforms being used for > the text itself and the actual bbox that surrounds it. This is what I have > tried: > > import numpy as n > import pylab as p > import matplotlib.patches as pt > > p.figure() > p.plot([0,1],[0,1]) > ax=p.gca() > tb=p.text(0.9,0.2,'test',horizontalalignment='center',verticalalignment='center',fontsize='small', > > color='green',weight='bold',bbox=dict(boxstyle="round,pad=0.5",ec='black',fill=False)) > bb=tb.get_bbox_patch() > sh=pt.Shadow(bb,0.1,0.1) > ax.add_patch(sh) > p.draw() > p.show() > > This seems to produce nothing at all (or maybe something that is far outside > the axis limits). > Am I missing something obvious here? Is there some other method that will do > this in an easier way? > > Would appreciate any help, cheers > -- > View this message in context: > http://old.nabble.com/text-box-shadow-tp27224851p27224851.html > Sent from the matplotlib - users mailing list archive at Nabble.com. > > > ------------------------------------------------------------------------------ > Throughout its 18-year history, RSA Conference consistently attracts the > world's best and brightest in the field, creating opportunities for Conference > attendees to learn about information security's most important issues through > interactions with peers, luminaries and emerging and established companies. > http://p.sf.net/sfu/rsaconf-dev2dev > _______________________________________________ > Matplotlib-users mailing list > Matplotlib-users@lists.sourceforge.net > https://lists.sourceforge.net/lists/listinfo/matplotlib-users > ------------------------------------------------------------------------------ Throughout its 18-year history, RSA Conference consistently attracts the world's best and brightest in the field, creating opportunities for Conference attendees to learn about information security's most important issues through interactions with peers, luminaries and emerging and established companies. http://p.sf.net/sfu/rsaconf-dev2dev _______________________________________________ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users