Just from morbid curiosity, I installed networkx to see if I could see what
is going on. And the answer to your original question is that no,
matplotlib doesn't have problems with multiple wx panels; I do this all the
time.
Basically what is going on is that pylab is being used inside of networkx
to issue the plotting commands. That's a bad idea in general, because of
just this type of situation. Without getting in there and trying to fix
networkx, I can at least make your script work by inserting this line:
def my_plot(figure):
figure.clear()
plt.figure(figure.number) <-------------------------------
G = nx.star_graph(15)
axes = figure.add_subplot(1,1,1)
nx.draw_networkx(G, ax=axes)
to make sure that before nx.draw_networkx is invoked, the correct figure is
current. That's a kludge, but it does work. The proper solution is to
modify networkx to use the api's properly. In particular, the glaring one
is right at the top of
site-packages/networkx/drawing/nx_pylab.py, line 119; that
cf = pylab.gcf()
should at least be
if ax is None:
cf = pylab.gcf()
else:
cf = ax.get_figure()
[I think]
The above should be reported to the networkx authors.
On Wed, Jul 11, 2012 at 1:02 PM, Daniel Hyams <dhy...@gmail.com> wrote:
> To get rid of the networkx dependency, I just replaced my_plot() with this:
>
> def my_plot(figure):
> figure.clear()
> axes = figure.add_subplot(1,1,1)
> axes.plot([0,1,2],[2,3,4])
>
> and also added "self.panel2.update_display()" in the constructor for
> MyFrame, and everything worked fine. Could it be networkx caching a
> reference to a figure or axes that is really the problem? Can you post the
> full stack trace instead of just the last line?
>
>
>
> On Wed, Jul 11, 2012 at 12:45 PM, Joshua Koehler <jjkoehl...@gmail.com>wrote:
>
>> Hi all,
>>
>> I am currently trying to have two panels each with their own figure
>> instance so they can have separate plots.
>>
>> I can successfully update a plot if there is only one panel. As soon as I
>> add a second panel, I get the following error when I try to update (replot)
>> a plot (Showing last message only):
>>
>> File
>> "/Library/Frameworks/Python.framework/Versions/7.3/lib/python2.7/site-packages/matplotlib/axes.py",
>> line 1374, in _sci
>> "Argument must be an image, collection, or ContourSet in this Axes")
>> ValueError: Argument must be an image, collection, or ContourSet in this
>> Axes
>>
>> I looked online first and one site suggested it was because I was using
>> matplotlib.Figure instead of pylab.Figure. I switched and the problem still
>> occurs. I was curious to see if this problem had to do with how I set up my
>> program, not with matplotlib, so I wrote a little test program. The exact
>> same problem occurs. I have attached the test program. To see that it does
>> work with just one panel comment out lines 39, 41, and 49. When put back
>> in, I get the above error message.
>>
>> Any suggestions as to how to fix this?
>>
>> Thanks!
>>
>> Josh
>>
>>
>>
>>
>>
>>
>> ------------------------------------------------------------------------------
>> Live Security Virtual Conference
>> Exclusive live event will cover all the ways today's security and
>> threat landscape has changed and how IT managers can respond. Discussions
>> will include endpoint security, mobile security and the latest in malware
>> threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
>> _______________________________________________
>> Matplotlib-users mailing list
>> Matplotlib-users@lists.sourceforge.net
>> https://lists.sourceforge.net/lists/listinfo/matplotlib-users
>>
>>
>
>
> --
> Daniel Hyams
> dhy...@gmail.com
>
--
Daniel Hyams
dhy...@gmail.com
------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and
threat landscape has changed and how IT managers can respond. Discussions
will include endpoint security, mobile security and the latest in malware
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users