May I suggest that you take a look at refigure2
(http://rschroll.github.com/refigure2/), which is my (second) attempt to
provide a pylab-like plotting interface for Reinteract. If you're using
Reinteract 0.5, the released version of refigure2 is for you. But if
you're using 0.5.9 or .10, you might want to checkout the git version.
It allows you to do stuff like this:
build figure():
subplot(121)
plot(x, y)
...
Hopefully this will be somewhat useful for you.
If you're still interested in why your method didn't work, I might be
able to offer some insight. But not right now, because I have to run.
Hope that helps,
Robert
It looks like you found the primary problem (which was not what I was
expecting, but it does ring a bell now that you mention it). But there
are a few other problems refigure2 has to deal with. I'll mention them
here briefly. Hopefully with the code, one can see how these were dealt
with. But if you, or anyone else, has further questions, I'm happy to
try to answer them.
1) Don't do anything GTK-related until the create_widget method call.
The create_widget method is called in the main thread, so GTK calls are
safe there. But all other code is called from worker threads, from
which you shouldn't make GTK calls. Doing so leads to subtle and
hard-to-trace bugs, like this:
https://github.com/rschroll/refigure2/issues/1
2) Dealing with re-execution partway through a figure creation.
Matplotlib keeps quite a bit of state behind the scenes about what's
going on to the current figure. Reinteract doesn't track this, so if
you were to go back and tweak a plot command, you're apt to end up with
two lines on your figure. replot deals with this is a clever manner, by
recording the plotting commands in a way the Reinteract can trace, and
then playing to back during figure creation. refigure2 adopts a
stupider, but robust, method: putting all the plotting commands within a
single block, so they are all executed each time any one of them is edited.
3) Keeping track of the current figure. This isn't a problem when using
the object-oriented interface to matplotlib, but the pylab interface
keeps track of the current figure and axes behind the scenes, and sends
plotting commands to them. If multiple worksheets are executing at
once, plotting commands could end up affecting random figures.
refigure2 deals with this by creating a lock inside of which all the
plotting is done.
Hopefully this is of interest to anyone making an extension around a
Python module that keeps state internally.
Robert
I attached a hacked version of the git file with some minor
adjustments for my usage. Please feel welcome to add them to the
official version.
It has the following adjustments:
1. The user can choose if a toolbar should be displayed upon figure
initialization:
with figure(toolbar=False) as f:
...
The default is True.
2. If the toolbar is not displayed AND the facecolor is not explicitly
set by the user as a keyword argument (e.g. figure(facecolor='red')),
the facecolor defaults to white.
This is just cosmetics so that the figure integrates IMO nicer into
the worksheet.
Best,
Joerg
> --
> You received this message because you are subscribed to the Google Groups
> "Reinteract" group.
> To post to this group, send email to reint...@googlegroups.com.
> To unsubscribe from this group, send email to
> reinteract+...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/reinteract?hl=en.
>