From: Roman B. <be...@sm...> - 2006-11-17 13:07:17
|
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. Whats the correct solution for my problem? Best Regards, Roman |
From: Roman B. <be...@sm...> - 2006-11-22 20:05:10
|
Hello, i had problems subscribing to the list, maybe the mail below I sent last week, was not delivered. Hence I send it again: --------------------------------------------------- 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. Whats the correct solution for my problem? Best Regards, Roman |
From: <be...@kp...> - 2006-11-17 13:15:36
|
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. Whats the correct solution for my problem? Best Regards, Roman |
From: Roman B. <be...@sm...> - 2006-12-04 10:45:09
|
Hello, i made some progress which this issue, but it does still not work completely: * Roman Bertle <be...@sm...> [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 |