|
From: Nicholas K. <n....@us...> - 2010-08-19 15:58:20
|
Hello-- I've been following the sample code given in the wxPython distribution to embed a wxPython window in wxGTK. The following links to the wxPython SVN demonstrate this technique: http://svn.wxwidgets.org/viewvc/wx/wxPython/trunk/samples/embedded/embedded_sample.py?revision=47031&view=markup http://svn.wxwidgets.org/viewvc/wx/wxPython/trunk/samples/embedded/embedded.cpp?revision=52947&view=markup The main program (embedded.cpp) interacts with an embedded wxPython script (embedded_sample.py). What I would like to do is embed matplotlib within a wxPanel of this wxPython script. The following code snippet shows exactly what I would like to do: # Begin Python code snippet import matplotlib matplotlib.interactive( True ) matplotlib.use( 'WXAgg' ) import numpy as num import wx class MyPanel(wx.Panel): def __init__(self, parent): wx.Panel.__init__(self, parent, -1, style=wx.SUNKEN_BORDER) # what do I do down here to be able to embed matplotlib within the wxPanel? # end code snippet In a similar fashion to the Matlab imagesc() function, I would like to embed a matplotlib image which displays a 2D matrix as a colormapped image. How might I be able to do this? Nicholas |
|
From: Christopher B. <Chr...@no...> - 2010-08-19 16:18:17
|
Nicholas Kinar wrote: > I've been following the sample code given in the wxPython distribution > to embed a wxPython window in wxGTK. As in embedding some wxPython in a C++ wxGTK program? > What I would like to do is embed > matplotlib within a wxPanel of this wxPython script. once you've got wxPython working, using MPL should be exactly t he same as with a pure wxPyton app -- take a look at the "embedded_in_wx" examples, and/or use wxMPL -- it provides a nice interactive MPL window out of the box: http://agni.phys.iit.edu/~kmcivor/wxmpl/ -Chris -- Christopher Barker, Ph.D. Oceanographer Emergency Response Division NOAA/NOS/OR&R (206) 526-6959 voice 7600 Sand Point Way NE (206) 526-6329 fax Seattle, WA 98115 (206) 526-6317 main reception Chr...@no... |
|
From: Nicholas K. <n....@us...> - 2010-08-19 16:42:34
|
> As in embedding some wxPython in a C++ wxGTK program? > Yes, that is exactly what I am doing. > >> What I would like to do is embed >> matplotlib within a wxPanel of this wxPython script. >> > once you've got wxPython working, using MPL should be exactly t he same > as with a pure wxPyton app -- take a look at the "embedded_in_wx" > examples, and/or use wxMPL -- it provides a nice interactive MPL window > out of the box: > > http://agni.phys.iit.edu/~kmcivor/wxmpl/ > > -Chris > > Chris, thank you very much for your response, and for the link. I've taken a look at the wxMPL library and it looks extremely useful and interesting. But how would I work with the class MyPanel(wx.Panel), and embed wxMPL directly into MyPanel? Could you give an extremely simple example (i.e. 2D plot of a sine wave)? Nicholas |
|
From: Christopher B. <Chr...@no...> - 2010-08-19 17:14:25
|
Nicholas Kinar wrote: > Chris, thank you very much for your response, and for the link. I've > taken a look at the wxMPL library and it looks extremely useful and > interesting. But how would I work with the class MyPanel(wx.Panel), and > embed wxMPL directly into MyPanel? Could you give an extremely simple > example (i.e. 2D plot of a sine wave)? sorry -- very short on time -- look at the wxMPL examples, understand them with pure Python, and they it should be straightforward to transfer to your situation. Note that you can put a wx.Panel in a wx.Panel, which is what you may want to do it your case. -Chris -- Christopher Barker, Ph.D. Oceanographer Emergency Response Division NOAA/NOS/OR&R (206) 526-6959 voice 7600 Sand Point Way NE (206) 526-6329 fax Seattle, WA 98115 (206) 526-6317 main reception Chr...@no... |
|
From: Nicholas K. <n....@us...> - 2010-08-19 17:18:17
|
> > Note that you can put a wx.Panel in a wx.Panel, which is what you may > want to do it your case. > > -Chris > > Hello Chris, Thank you for your response; I think this is what I would like to do. Once again, thank you. Nicholas |
|
From: Nicholas K. <n....@us...> - 2010-08-19 16:43:25
|
On 10-08-19 10:08 AM, C M wrote: >> I've been following the sample code given in the wxPython distribution >> to embed a wxPython window in wxGTK. The following links to the >> wxPython SVN demonstrate this technique: >> >> http://svn.wxwidgets.org/viewvc/wx/wxPython/trunk/samples/embedded/embedded_sample.py?revision=47031&view=markup >> http://svn.wxwidgets.org/viewvc/wx/wxPython/trunk/samples/embedded/embedded.cpp?revision=52947&view=markup >> > Not sure what that is, but it doesn't look very helpful for your > needs. Instead, see below... > > >> The main program (embedded.cpp) interacts with an embedded wxPython >> script (embedded_sample.py). What I would like to do is embed >> matplotlib within a wxPanel of this wxPython script. The following code >> snippet shows exactly what I would like to do: >> >> >> # Begin Python code snippet >> import matplotlib >> matplotlib.interactive( True ) >> matplotlib.use( 'WXAgg' ) >> >> import numpy as num >> import wx >> >> >> class MyPanel(wx.Panel): >> def __init__(self, parent): >> wx.Panel.__init__(self, parent, -1, style=wx.SUNKEN_BORDER) >> >> # what do I do down here to be able to embed matplotlib >> within the wxPanel? >> > See this page: > http://www.scipy.org/Matplotlib_figure_in_a_wx_panel > > Basically the idea is you make a matplotlib canvas, and then add that > to a wxPanel. > > Che > > Hello Che-- Thank you very much for your response; this is greatly appreciated, and thank you for the link to the scipy website. I've read over the example, but I cannot understand how I would start with just a wxPanel and then add the embedded matplotlib just to the panel (as per the code snippet above). In the example on the scipy website, it appears that class DemoPlotPanel(PlotPanel) takes as input class PlotPanel. How would I do this with the MyPanel class as shown above? Nicholas |