matplotlib嵌入到wxpython

來源:互聯網
上載者:User

2009-07-13 javaeye http://angeloce.iteye.com/admin/blogs/425180

===========================    

 

matplotlib(mpl)本身支援wxpython作為backends。但是直接使用import pylab時調用的wx表單不能自訂和改制。跟蹤下pylab模組的show方法,最終找到表單類為backend_wx(agg)下的FigureFrameWx(FigureFrameWxAgg).我想把這個類單獨拽出來,但關聯太多,實在力不從心,後來發現類FigureCanvasWx(FigureCanvasWxAgg),繼承了wx.Panel類,圖表顯示應該跟此有關。(搞不太懂尾碼agg的含義……)

 

FigureCanvasWx 需要三個參數:parent, id ,figure. 前兩個與wx.Panel相同,後一個是Figure執行個體(參照matploglab.figure模組),鼓搗一陣,寫出一個簡單可顯示表單。

 

import wx   from matplotlib.backends import backend_wxagg   from matplotlib.figure import Figure     class TestFrame(wx.Frame):       def __init__(self):           wx.Frame.__init__(self, None)                      self.panel = backend_wxagg.FigureCanvasWxAgg(self, -1, Figure())           axes = self.panel.figure.gca()           axes.cla()           axes.plot([1,2,3],[1,2,3])                      self.panel.draw()               app = wx.App()   f= TestFrame()   f.Show(True)   app.MainLoop()

  


 

這個代碼只實現了一張極簡單的x=y直線圖,如果需要添加相應事件和顯示,請參照backend_wx內的代碼。

 

當然已經有人替我們做好一些, wxmpl http://agni.phys.iit.edu/~kmcivor/wxmpl/

參看源碼,其實mpl嵌入wxpython不是難事。

 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.