Hello,
i made some progress which this issue, but it does still not work
completely:
* Roman Bertle <[EMAIL PROTECTED]> [061117 11:04]:
> Hello,
>
> i try to write a module which evaluates various Data, and occasionally
> creates a plot, which is returned to the user. At the discretion of the
> user, he should be able to show selected plots. This is an example
> module with two approaches for this problem:
>
> -----------------
> import pylab
> import matplotlib
>
> def makeplot1():
> pylab.ioff()
> fig = pylab.figure()
> spl1 = fig.add_subplot(211)
> spl2 = fig.add_subplot(212)
> spl1.plot([1,4,9,16])
> spl2.plot([1,3,5,7])
> pylab.ion()
> return fig
>
> def makeplot2():
> fig = matplotlib.figure.Figure()
> spl1 = fig.add_subplot(211)
> spl2 = fig.add_subplot(212)
> spl1.plot([1,4,9,16])
> spl2.plot([1,3,5,7])
> return fig
> ----------------------
>
> The user fires up ipython and imports my module:
> ipython -pylab
> >>> import plotgen
>
> After analysizing various data, he wants to look at a particular plot:
> >>> fig = plotgen.makeplot1()
>
> Now can one make pop up this plot? I tried to make this figure current:
> >>> figure(fig.number)
> but nothing to see. Then:
> >>> draw()
> >>> ion()
> Only show() works, but this pops up all figures defined, and this can be
> a large number of figures if makeplot1() has been called often, or I
> have many figures. I only want to see this particular figure.
>
> So next try with the object oriented interface:
> >>> fig = plotgen.makeplot2()
> >>> figure(fig.number)
> AttributeError: Figure instance has no attribute 'number'
>
> Ok, this does not work. In a cookbook i saw that one needs something
> like "canvas = FigureCanvasAgg(fig)". But i cannot use it: As writer of
> module "plotgen" i dont know what backend (Agg) is used by the user. And
> the user simply uses "ipython -pylab" and should not care about the
> backend.
Here i made some progress. One needs a "FigureManager", and in
"ipython -pylab" there is a function "get_current_fig_manager()"; so
here comes my next try:
ipython -pylab
>>> import plotgen
>>> fig = plotgen.makeplot1()
>>> canvas = get_current_fig_manager().canvas
>>> canvas.figure = fig
>>> canvas.print_figure('test')
And the figure is saved into file 'test.png'! The problem is, after
"canvas = get_current_fig_manager().canvas" a plot window appears, but
it is not updated when the figure is changed. I tried methods "show",
"show_all" and "show_now", but nothing is drawn. How can i see the
figure?
Regards, Roman
-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys - and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
Matplotlib-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/matplotlib-users