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

import wx
import networkx as nx
import matplotlib.pylab as plt
from matplotlib.backends.backend_wxagg import FigureCanvasWxAgg as FigureCanvas

def my_plot(figure):
    figure.clear()
    G = nx.star_graph(15)
    axes = figure.add_subplot(1,1,1)
    nx.draw_networkx(G, ax=axes)
        
class PanelOne(wx.Panel):
    def __init__(self, my_parent, my_id=wx.ID_ANY):
        wx.Panel.__init__(self, parent=my_parent, id=my_id)
        self.figure = plt.figure()
        self.figure.add_subplot(1,1,1)
        self.canvas = FigureCanvas(self, wx.ID_ANY, self.figure)
    def update_display(self):
        my_plot(self.figure)
    def close(self):
        plt.close()
        
class PanelTwo(wx.Panel):
    def __init__(self, my_parent, my_id=wx.ID_ANY):
        wx.Panel.__init__(self, parent=my_parent, id=my_id)
        self.figure = plt.figure()
        self.figure.add_subplot(1,1,1)
        self.canvas = FigureCanvas(self, wx.ID_ANY, self.figure)
    def update_display(self):
        my_plot(self.figure)
    def close(self):
        plt.close()

class MyFrame(wx.Frame):
    def __init__(self, parent):
        wx.Frame.__init__(self,parent=parent)
        self.h_sizer = wx.BoxSizer(wx.HORIZONTAL)
        self.panel1 = PanelOne(self)
        self.panel2 = PanelTwo(self)
        self.h_sizer.Add(self.panel1)
        self.h_sizer.Add(self.panel2)
        self.panel1.update_display()
        self.SetSizer(self.h_sizer)
        self.Fit()
        self.Bind(wx.EVT_CLOSE, self.OnExit)
              
    def OnExit(self, event):
        self.panel1.close()
        self.panel2.close()
        self.Destroy()        
         
if __name__ == "__main__":
    app = wx.App(False)
    frame = MyFrame(None)
    frame.Show(True)
    app.MainLoop()
      
    
         

------------------------------------------------------------------------------
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

Reply via email to