wxpython使用matplot_WXPython with MatPlotLib

You made class p1 with matplot but you didn't use it in TestFrame.

I changed some names to make it more clear import wx import numpy import matplotlib from matplotlib.figure import Figure from matplotlib.backends.backend_wxagg import FigureCanvasWxAgg as FigureCanvas class TestFrame(wx.Frame): def __init__(self,parent,title): wx.Frame.__init__(self,parent,title=title,size=(500,500)) self.sp = wx.SplitterWindow(self) self.p1 = wx.Panel(self.sp, style=wx.SUNKEN_BORDER) self.p2 = MatplotPanel(self.sp) self.sp.SplitVertically(self.p1,self.p2,100) self.statusbar = self.CreateStatusBar() self.statusbar.SetStatusText('Oi') class MatplotPanel(wx.Panel): def __init__(self, parent): wx.Panel.__init__(self, parent,-1,size=(50,50)) self.figure = Figure() self.axes = self.figure.add_subplot(111) t = numpy.arange(0.0,10,1.0) s = [0,1,0,1,0,2,1,2,1,0] self.y_max = 1.0 self.axes.plot(t,s) self.canvas = FigureCanvas(self,-1,self.figure) app = wx.App(redirect=False) frame = TestFrame(None, 'Hello World!') frame.Show() app.MainLoop()

EDIT:

MatplotPanel with NavigationToolbar and wx.Button to change plot. from matplotlib.backends.backend_wxagg import NavigationToolbar2Wx as NavigationToolbar class MatplotPanel(wx.Panel): def __init__(self, parent): wx.Panel.__init__(self, parent,-1,size=(50,50)) self.sizer = wx.BoxSizer(wx.VERTICAL) self.SetSizer(self.sizer) self.figure = Figure() self.axes = self.figure.add_subplot(111) self.canvas = FigureCanvas(self, -1, self.figure) self.toolbar = NavigationToolbar(self.canvas) self.button = wx.Button(self, -1, "Change plot") self.button.Bind(wx.EVT_BUTTON, self.changePlot) self.sizer.Add(self.toolbar, 0, wx.EXPAND) self.sizer.Add(self.button, 0, wx.EXPAND) self.sizer.Add(self.canvas, 1, wx.LEFT | wx.TOP | wx.GROW) self.drawSin() self.current_draw = 'sin' # self.drawLines() def changePlot(self, event): if self.current_draw == 'sin' : self.drawLines() self.current_draw = 'lines' else: self.drawSin() self.current_draw = 'sin' self.Layout() def drawLines(self): x = numpy.arange(0.0,10,1.0) y = [0,1,0,1,0,2,1,2,1,0] self.axes.clear() self.axes.plot(x, y) def drawSin(self): x = numpy.arange(0.0,10,0.1) y = numpy.sin(x) self.axes.clear() self.axes.plot(x, y)

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值