Hello, I finally got around to play with matplotlib and
> try to create node for using it within Vision (my visual
> programming environemnt).
It's excellent to hear that you are trying to incorporate matplotlib!
Only good things can come of stress testing matplotlib in such a
> I was wondering if there is a way the clear the area used
> by a given subplot. cla() seesm the clear the data, but
> the axis and background remain. The reason I am asking is
> that I envisioned that in my networks I would like to be
> able to create a Figure using one node and then have say a
> Histogram node be placed in a subplot and a scatter plot
> in another subplot (in the same figure). Now if the
> Histogram node has a subplot parameter which can be
> modified by the user to move this particular graph to
> another location in the picture I need to get ride of what
> I drew in the previous location, but since parts of the
> figure might be generated by other nodes in the network I
> would not want to clear the whole figure.
I see what you are trying to do and there is no support in the current
release for this. However, it will be mostly trivial to add, and
definitely useful, so I can quickly put it in for the next release.
Before doing so, it would help for me to know if you are using the OO
interface (eg examples/embedding_in_tk.py) or the pylab (formerly
matplotlib.matlab). The latter does a fair amount of magic under the
scenes managing the current figure and axes and so is not the best for
embedding in an application. It thus requires more work to delete an
axes, since there is a separate figure/axes management layer.
Do you envision providing a scripting interface to your Vision users,
in which case the pylab interface probably makes sense, or will you
ultimately be maintaining control over the creation of figure windows
and axes and providing a GUI layer to your users, in which case the OO
embedded approach makes sense.
Note that if all you want to do is move the subplot in a figure, all
you need to do is call
ax = subplot(211)
where l,b,w,h are fractions of the figure width and height. If you
want to drag and drop axes from one figure to another, which is
reasonable, then additional work will need to be done to remove the
axes from one and add to another. Sharing a subplot in two figures
will probably remain unsupported, but with a little work you could
move one from one figure to another. Note that
matplotlib.axes.Subplot is a special case of matplotlib.axes.Axes, and
each are placed with l,b,w,h. The difference is that subplot does the
l,b,w,h computation for you -- see examples/axes_demo.py.
On an related note, the ticklabels in your screenshot appeared a
little crowded. You may want to take a look at
> Another question was whether it is possible to find out
> the figure number from the figure handle ? If I pass the
> Figure instance between nodes to tell drawing node in
> which figure to place their graphical output I need a way
> to active the figure that comes as an input. Currently I
> add a number attribute to the figure when I create it in
> the figure node.
The Figure class doesn't have a concept of number, but the
FigureManager does. In the pylab interface, calls to make a new
figure create a new FigureManager (abstract class in
backend_bases.FigureManager, concrete classes in the various
matplotlib/backends/backend_something.py). The figure manager has a
few public attributes you can access
manager = get_current_fig_manager()
manager.num # what you are after
manager.canvas # a backend_bases.FigureCanvasBase concrete impl
manager.window # the GUI window, eg tk.Window
As I alluded to above though, depending on your ultimate goals, once
you get past the playing stage you *may* want to forgo the pylab
interface (which the figure manager is designed for) in exchange for
the control of the OO interface. Note that a new
examples/embedding_in_tk2.py was recently added to CVS which shows how
to use tk matplotlib with the default toolbar in a tk app.
There is an unreleased users guide in progress, and it has some more
details and schematics on how matplotlib is organized.
> Thanks for any input .. and congratualtion on the very
> nice package !
High praise coming from you! Thanks.