SourceForge logo
SourceForge logo
Menu

matplotlib-users

From: Mark E. <ma...@st...> - 2004年07月26日 20:53:52
Hi,
Two quick little issues I haven't been able to figure out how to fix on 
my own so far:
1. Is there an easy way to change the spacing between subplots, so 
that they aren't so crammed together? It's none too pretty when the 
x-axis text for the upper plot is overlapping or even below the title 
for the lower plot.
2. Is there a way to make the 'show()' command execute so that the 
script keeps running (instead of waiting for the windows to be closed), 
and to have the output persist past the end of the run?
Thanks,
Mark
From: John H. <jdh...@ac...> - 2004年07月26日 21:31:06
>>>>> "Mark" == Mark Engelhardt <ma...@st...> writes:
 Mark> Hi, Two quick little issues I haven't been able to figure
 Mark> out how to fix on my own so far:
 Mark> 1. Is there an easy way to change the spacing between
 Mark> subplots, so that they aren't so crammed together? It's
 Mark> none too pretty when the x-axis text for the upper plot is
 Mark> overlapping or even below the title for the lower plot.
Which backend are you using? Chris Fuller submitted a tk widget for
just this purpose -
http://sourceforge.net/mailarchive/message.php?msg_id=8901913. It
would be fairly easy to port to other GUIs. It's on the list of things
to do, but I haven't had time. Other than that, your best option is
to manually set the axes size, eg using the 'axes' command or calling
 ax.set_position
 Mark> 2. Is there a way to make the 'show()' command execute so
 Mark> that the script keeps running (instead of waiting for the
 Mark> windows to be closed), and to have the output persist past
 Mark> the end of the run?
You should only call show once per script. I repeat, you should only
call show once per script -
http://matplotlib.sourceforge.net/faq.html#SHOW
matplotlib-0.60.2 has a "draw" command to force a canvas redraw. This
is non blocking. Earlier versions allow you to do, equivalently,
get_current_fig_manager().canvas.draw(). Does this do what you want?
I am not sure what you are after when you write "have the output
persist past the end of the run". Launch the python interpreter?
Please let me know what backend you are using and explain a bit more
what it is you are trying to do. Are you running in interactive mode?
JDH
From: Mark E. <ma...@st...> - 2004年07月28日 05:44:12
Hi,
I am not in interactive mode, I am writing scripts that handle a bunch 
of data and then plot it all. However, when show() is called, the 
script stops and waits for all the windows it opens to be closed before 
continuing. What I was hoping for was a way to have the plots be drawn 
in windows that were no longer hooked into the script, such that the 
script could continue running (to completion) regardless of what 
happened to the open windows. I did try 'draw()', which does not 
appear to open any new windows.
In answer to your questions, here are the relevant lines from my 
.matplotlibrc:
backend : GTKAgg # the default backend
numerix : numarray #Numeric # Numeric or numarray
interactive : False # see 
http://matplotlib.sourceforge.net/interactive.htm
Thanks for everyone's help on subplot positioning (or avoidance ;)) - 
I'll take a look.
- Mark
On Jul 26, 2004, at 2:06 PM, John Hunter wrote:
> Mark> 2. Is there a way to make the 'show()' command execute so
> Mark> that the script keeps running (instead of waiting for the
> Mark> windows to be closed), and to have the output persist past
> Mark> the end of the run?
>
> You should only call show once per script. I repeat, you should only
> call show once per script -
> http://matplotlib.sourceforge.net/faq.html#SHOW
>
> matplotlib-0.60.2 has a "draw" command to force a canvas redraw. This
> is non blocking. Earlier versions allow you to do, equivalently,
> get_current_fig_manager().canvas.draw(). Does this do what you want?
> I am not sure what you are after when you write "have the output
> persist past the end of the run". Launch the python interpreter?
>
> Please let me know what backend you are using and explain a bit more
> what it is you are trying to do. Are you running in interactive mode?
>
> JDH
>
From: John H. <jdh...@ac...> - 2004年07月28日 12:35:27
>>>>> "Mark" == Mark Engelhardt <ma...@st...> writes:
 Mark> Hi, I am not in interactive mode, I am writing scripts that
 Mark> handle a bunch of data and then plot it all. However, when
 Mark> show() is called, the script stops and waits for all the
 Mark> windows it opens to be closed before continuing. What I was
 Mark> hoping for was a way to have the plots be drawn in windows
 Mark> that were no longer hooked into the script, such that the
 Mark> script could continue running (to completion) regardless of
 Mark> what happened to the open windows. I did try 'draw()',
 Mark> which does not appear to open any new windows.
Hi Mark, 
Thanks for the explanation. Now I understand what you are trying to
do. You are right about draw, all it does is redraw an existing
figure, eg if you have changed some data in it.
You have to get a little bit into the GTK API / event handling
mechanism to do this right. One way is to use the full blown gtk API
with matplotlib, as in examples/embedding_in_gtk*.py.
The easier way is to just use as much of the API as you need, and take
over the function of the backend 'show' function. You'll be doing an
end run around the matplotlib.matlab figure manager, which means some
of these won't work (like gcf, close, etc.). That's OK, because you
won't be using the matplotlib.matlab interface. Do not import
matplotlib.matlab with this approach as the result is undefined!
There are a few things you need to do
 * Define function(s) / class(es) which create your figures
 * Define a main function which call these functions as necessary.
 Return False from this function
 * Add main to the gtk idle handler. Returning False in 'main' will
 cause this function to be called only once.
 * Start the gtk mainloop yourself. After gtk is started, your
 'main' function will be called and you're off to the races.
 * If there is something you want from matplotlib.matlab, say the
 'axis' command, just look at the src code to see how axis is
 implemented with the matplotlib API and make those calls yourself.
You may want to spend some time with the pygtk class reference at
http://www.pygtk.org/pygtk2reference/gtk-class-reference.html and the
matplotlib class reference at
http://matplotlib.sourceforge.net/classdocs.html. In the example
below
 * canvas inherits from gtk.DrawingArea and
 backends.FigureCanvasGTK (which in turn derives from 
 backend_bases.FigureCanvasBase)
 * manager is a backends.backend_gtk.FigureManagerGTK
 which inherits from backend_bases.FigureManagerBase
 * manager.window is a gtk.Window() (you can also hide or close this
 window with pygtk API calls)
 * ax is a axes.Subplot which inherits from axes.Axes
Here is an example
#!/usr/bin/env python
import matplotlib
matplotlib.use('GTKAgg')
from matplotlib.backends.backend_gtkagg import new_figure_manager
from matplotlib.numerix import *
import gtk
def main(*args):
 manager1 = new_figure_manager(1)
 canvas1 = manager1.canvas
 fig1 = canvas1.figure
 ax1 = fig1.add_subplot(111)
 ax1.plot([1,2,3])
 manager1.window.show() # non blocking
 manager2 = new_figure_manager(2)
 canvas2 = manager2.canvas
 fig2 = canvas2.figure
 ax2 = fig2.add_subplot(111)
 ax2.plot([6,5,4])
 manager2.window.show()
 return False
gtk.idle_add(main)
gtk.mainloop()
From: Gregory L. <gre...@ff...> - 2004年07月28日 12:56:51
On Wed, 2004年07月28日 at 14:11, John Hunter wrote:
> >>>>> "Mark" == Mark Engelhardt <ma...@st...> writes:
> 
> Mark> Hi, I am not in interactive mode, I am writing scripts that
> Mark> handle a bunch of data and then plot it all. However, when
> Mark> show() is called, the script stops and waits for all the
> Mark> windows it opens to be closed before continuing. What I was
> Mark> hoping for was a way to have the plots be drawn in windows
> Mark> that were no longer hooked into the script, such that the
> Mark> script could continue running (to completion) regardless of
> Mark> what happened to the open windows. I did try 'draw()',
> Mark> which does not appear to open any new windows.
> 
> Hi Mark, 
> 
> Thanks for the explanation. Now I understand what you are trying to
> do. You are right about draw, all it does is redraw an existing
> figure, eg if you have changed some data in it.
Hi,
I think I recall I observed the requested behavior (i.e. get hand back
in interractive window or script after a show()) in previous version of
matplotlib.
I remember this cause reproducing this non-blocking behavior of show()
has proven to be a little bit hard to reproduce when developing FltkAgg
backend (I have done it using thread, and it works, so a solution would
be to use this backend when it is integrated).
But with TkAgg and GTKAgg, cvs version, on linux, it does not work
anymore (i.e. show() do not return hand, as mentioned)
I tested some earlier version (0.54 on windows, TkAgg) to see if I have
so false souvenir, but it indeed work as Mark want (i.e. show() is
non-blocking )...So I guess something has changed in the show()
mechanism since, maybe to deal with the new event mechanism?
Best regards,
Greg.
Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.
Thanks for helping keep SourceForge clean.
X





Briefly describe the problem (required):
Upload screenshot of ad (required):
Select a file, or drag & drop file here.
Screenshot instructions:

Click URL instructions:
Right-click on the ad, choose "Copy Link", then paste here →
(This may not be possible with some types of ads)

More information about our ad policies

Ad destination/click URL:

AltStyle によって変換されたページ (->オリジナル) /