From: John H. <jdh...@ac...> - 2004-05-14 16:00:33
|
>>>>> "Perry" == Perry Greenfield <pe...@st...> writes: Perry> Is there a means of using alternate rcParams dictionaries Perry> for use with different backends, say as a parameter to the Perry> print_figure method? It doesn't look like it at the Perry> moment. I'd guess to do that now means replacing rcParams Perry> temporarily, rendering the plot to the file, and resetting Perry> rcParams to what it was (I haven't actually tried it), but Perry> that seems clumsier than it should be. There are a few ways to go here. Probably the best is based on the answer to "How do I customize the default behavior of a single figure?" http://matplotlib.sourceforge.net/faq.html#CUSTOM Ie, you can set the rc params for a given session by updating the rc dict before importing matplotlib. You could set up a module like plot_contexts plot_contexts.py:: from matplotlib import rcParams def use(s): if s == 'powerpoint': rcParams['figure.facecolor'] = 'b' rcParams['text.fontname'] = 'cmr10' rcParams['lines.linewidth'] = 2.0 elif s = 'some journal' and so on And at the script level you could do import plot_contexts plot_contexts.use('powerpoint') from matplotlib.matlab import * The one down side of the rcParams approach is that currently all the object defaults are evaluated at module load time, so you can only switch at the start of your python session. Eg, the current constructors look like class Line2D(Artist): def __init__(self, xdata, ydata, linewidth=rcParams['lines.linewidth'], linestyle=rcParams['lines.linestyle'], ) By changing all the constructor defaults to def __init__(self, xdata, ydata, linewidth=None, linestyle=None, ): if linewidth is None: linewidth = rcParams['lines.linewidth'], if linestyle is None: linestyle = rcParams['lines.linestyle'], we could defer those evaluations to construction time, so you could switch contexts in the middle of an interactive session >>> plot_contexts.use('power point') >>> make_some_figs() >>> plot_contexts.use('some journal') >>> make_some_figs() # again I already did this for the FontProperties so you can have context fonts, as in examples/font_properties_demo.py. It wouldn't be much work to do the same for the other properties controlled by rc. As another approach, I have considered making the matplotlibrc finder check the current dir first, and using that file if it finds one. Then you could have dir based contexts. JDH |