【问题标题】:putting a matplotlib graph into wxpython将 matplotlib 图放入 wxpython
【发布时间】:2013-01-24 16:52:01
【问题描述】:

我有这段代码可以创建一个交互式散点图:

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 中

我该怎么做?

【问题讨论】:

标签: python matplotlib wxpython


【解决方案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))

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-05-31
    • 2023-03-17
    • 1970-01-01
    • 2012-07-30
    • 2020-08-15
    • 2012-08-23
    • 1970-01-01
    相关资源
    最近更新 更多