[SciPy-user] gplt and xplt

David M. Cooke cookedm at physics.mcmaster.ca
Thu Aug 12 18:47:24 EDT 2004


On Thu, Aug 12, 2004 at 04:36:20PM -0500, John Hunter wrote:
> >>>>> "David" == David M Cooke <cookedm at physics.mcmaster.ca> writes:
>     David> In essence, can I build up two plots independently
>     David> at the same time? Then save them?
> 
> Not a problem - here the matlab interface is not imported or used.
> The use of a separate Figure and FigureCanvas below results from
> trying to keep a clean separation from the frontend (Figure) and
> backend (Canvas)
> 
>     from matplotlib.backends.backend_agg import FigureCanvasAgg as FigureCanvas
>     from matplotlib.figure import Figure
>     from matplotlib.numerix import rand
> 
>     fig1 = Figure()
>     fig2 = Figure()
> 
>     canvas1 = FigureCanvas(fig1)
>     canvas2 = FigureCanvas(fig2)
> 
>     ax1 = fig1.add_subplot(111)
>     ax2 = fig2.add_axes([0.2, 0.2, 0.5, 0.5])  # a custom axes in fig2
> 
>     ax1.plot([1,2,3])
> 
>     ax2.scatter(rand(12), rand(12))
> 
>     canvas1.print_figure('fig1.svg')  # switches to the svg backend
>     canvas1.print_figure('fig1.png')  # native agg saves png
>     canvas2.print_figure('fig2.eps')  # switches to the PS backend
>
> No call to show, etc....  The hardcopy is created upon executing this
> script.  Here I take advantage of the fact that most backends (agg in
> this case) can switch backends to render to PS/EPS/SVG/PNG depending
> on the extension.  You don't need to use the switching feature - you
> could have directly imported the SVG or PS backend canvas, but I
> included it for illustration.

Hmm, ok. I like that better. Thanks!

-- 
|>|\/|<
/--------------------------------------------------------------------------\
|David M. Cooke                      http://arbutus.physics.mcmaster.ca/dmc/
|cookedm at physics.mcmaster.ca




More information about the SciPy-User mailing list