2013-01-24 22 views
2

我有這樣的代碼創建一個交互式的散點圖:把一個matplotlib圖分成的wxPython

if 1: # picking on a scatter plot (matplotlib.collections.RegularPolyCollection) 

x, y, c, s = rand(4, 100) 
def onpick3(event): 
    ind = event.ind 
    print('onpick3 scatter:', ind, np.take(x, ind), np.take(y, ind)) 

fig = figure() 
ax1 = fig.add_subplot(111) 
col = ax1.scatter(x, y, 100*s, c, picker=True) 
#fig.savefig('pscoll.eps') 
fig.canvas.mpl_connect('pick_event', onpick3) 

我想要做的就是這個圖融入wxPython的

我怎麼能去這樣做?

+0

您可能會覺得這篇博文有用:http://eli.thegreenplace.net/2008/08/01/matplotlib-with-wxpython-guis/ – milancurcic

回答

1

你想要做的是把數字放在一個wxPanel中。見here for a good example

class CanvasPanel(wx.Panel): 
    def __init__(self, parent): 
     wx.Panel.__init__(self, parent) 

     self.figure = Figure() 
     self.axes1 = self.figure.add_subplot(211) 
     self.axes2 = self.figure.add_subplot(212) 
     self.canvas = FigureCanvas(self, -1, self.figure) 
     self.sizer.Add(self.canvas, 1, wx.LEFT | wx.TOP | wx.GROW) 
     self.SetSizer(self.sizer) 
     self.Fit() 
     self.figure.tight_layout() 
     self.canvas.mpl_connect('motion_notify_event', self.onMotion) 

    def onMotion(self, event): 
     if event.inaxes: 
      xpos = event.xdata 
      print(' %0.1f' % (xpos))