Ticket #5 (new defect)
Opened 3 years ago
matplotlib figtext and figline
| Reported by: | emuller | Owned by: | somebody |
|---|---|---|---|
| Priority: | major | Milestone: | |
| Component: | component1 | Version: | |
| Keywords: | Cc: |
Description
I'm just polishing up some plots for publication, and instead of adding various labels and legends after the fact with XFig, I've found some idioms to do it comfortably using matplotlib, resulting in reproducible figure scripts and better quality fonts, due to latex rendering built in.
I'm sure you're all aware of pylab.figtext to add text to figures. I was unable to find a "figline" so I looked at the code for figtext and wrote one:
def figline(*args,**kwargs): '''figline(xdata,ydata,linewidth=None, linestyle=None, color=None, mar ker=None, markersize=None, markeredgewidth=None, markeredgecolor=None, markerfac ecolor=None, antialiased=None, dash_capstyle=None, solid_capstyle=None, dash_joi nstyle=None, solid_joinstyle=None, **kwarg) xdata, ydata are in figure coordinations (0,1) example: figline([0.9,0.1],[0.1,0.9],linestyle='-',color='r') ''' import matplotlib.lines as lines l = lines.Line2D(*args,**kwargs) f = pylab.gcf() l.set_transform(f.transFigure) f.lines.append(l) pylab.draw_if_interactive()
Next, you can remove lines plotted with figline if you didn't like the result of the last command. Here's the basic idea:
import pylab # pick out a subset of the lines you want to keep pylab.gcf().lines = pylab.gcf().lines[:-1] # update the plot pylab.draw_if_interactive()
The same applies for figtext text (use gcf().texts).
