Re: [Matplotlib-users] x and ylabel problem when embedding in wx
Le Vendredi 10 Novembre 2006 00:50, vous avez écrit : John == John Hunter [EMAIL PROTECTED] writes: John It's not about wx or wxpython, it's a matplotlib issue. Let me add some color to that statement -- when I took a look at your screenshot, I realized you are using the WX backend and not the WXAgg backend. If you don't understand the difference, peruse http://matplotlib.sf.net/backends.html . WXAgg may have the same problem (and the same solution from my last post) but will give you more consistent rendering and layout. JDH Thank you John!! In fact WXAgg does not have the same problems. I mean, there is no problem with WXAgg and fig.subplots_adjust(left=0.15, bottom=0.15) is even not needed! It looks much nicer : http://emmanuelfavrenicolin.free.fr/Public/Divers/Snapshots1/wx_snap1.png It means that WXAgg is to be the recommend way for embedding in wxpython? Just for reference, a sample code derived from dynamic_image_wxagg.py : #!/usr/bin/env python import sys, time, os, gc import matplotlib matplotlib.use('WXAgg') from matplotlib import rcParams rcParams['numerix'] = 'numarray' import matplotlib.cm as cm from matplotlib.backends.backend_wxagg import Toolbar, FigureCanvasWxAgg from matplotlib.figure import Figure import matplotlib.numerix as numpy from wxPython.wx import * TIMER_ID = wxNewId() class PlotFigure(wxFrame): def __init__(self): wxFrame.__init__(self, None, -1, Test embedded wxFigure) self.fig = Figure((7,5), 75) #self.fig.subplots_adjust(left=0.15, bottom=0.15) self.canvas = FigureCanvasWxAgg(self, -1, self.fig) self.toolbar = Toolbar(self.canvas) self.toolbar.Realize() # On Windows, default frame size behaviour is incorrect # you don't need this under Linux tw, th = self.toolbar.GetSizeTuple() fw, fh = self.canvas.GetSizeTuple() self.toolbar.SetSize(wxSize(fw, th)) # Create a figure manager to manage things # Now put all into a sizer sizer = wxBoxSizer(wxVERTICAL) # This way of adding to sizer allows resizing sizer.Add(self.canvas, 1, wxLEFT|wxTOP|wxGROW) # Best to allow the toolbar to resize! sizer.Add(self.toolbar, 0, wxGROW) self.SetSizer(sizer) self.Fit() EVT_TIMER(self, TIMER_ID, self.onTimer) def init_plot_data(self): # jdh you can add a subplot directly from the fig rather than # the fig manager a = self.fig.add_subplot(111) a.set_title('Title') a.set_xlabel('Xaxis [u.a.]') a.set_ylabel('Yaxis [u.a.]') #a.xaxis.set_major_formatter(matplotlib.ticker.FormatStrFormatter('%5.2f')) #a.yaxis.set_major_formatter(matplotlib.ticker.FormatStrFormatter('%5.2f')) self.ind = numpy.arange(60) tmp = [] for i in range(60): tmp.append(numpy.sin((self.ind+i)*numpy.pi/15)) self.X = numpy.array(tmp) self.lines = a.plot(self.X[:,0],'o') self.count = 0 def GetToolBar(self): # You will need to override GetToolBar if you are using an # unmanaged toolbar in your frame return self.toolbar def onTimer(self, evt): self.count += 1 if self.count = 60: self.count = 0 self.lines[0].set_data(self.ind, self.X[:,self.count]) self.canvas.draw() #self.canvas.gui_repaint() # jdh wxagg_draw calls this already def onEraseBackground(self, evt): # this is supposed to prevent redraw flicker on some X servers... pass if __name__ == '__main__': app = wxPySimpleApp() frame = PlotFigure() frame.init_plot_data() # Initialise the timer - wxPython requires this to be connected to # the receiving event handler t = wxTimer(frame, TIMER_ID) t.Start(100) frame.Show() app.MainLoop() - Using Tomcat but need to do more? Need to support web services, security? Get stuff done quickly with pre-integrated technology to make your job easier Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo http://sel.as-us.falkag.net/sel?cmd=lnkkid=120709bid=263057dat=121642 ___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users
[Matplotlib-users] x and ylabel problem when embedding in wx
I have problem with xlabel and ylabel when embedding in wx. See snapshot : http://emmanuelfavrenicolin.free.fr/Public/Divers/Snapshots1/wx_snap.png I put a test code which is based on dynamic_demo_wx.py, adding only the 3 lines : a.set_title('Title') a.set_xlabel('Xaxis [u.a.]') a.set_ylabel('Yaxis [u.a.]') Just to add title, and label. In this case Ylabel is superposed on ytics labels and xlabel is hidden by the navigation toolbar. Do I need twiking and/or understand better wxpython ? Anyone can help me? sample code : import matplotlib matplotlib.use('WX') from matplotlib.backends.backend_wx import FigureCanvasWx,\ FigureManager, NavigationToolbar2Wx from matplotlib.figure import Figure from matplotlib.axes import Subplot import matplotlib.numerix as numpy from wxPython.wx import * TIMER_ID = wxNewId() class PlotFigure(wxFrame): def __init__(self): wxFrame.__init__(self, None, -1, Test embedded wxFigure) self.fig = Figure((6,4), 75) self.canvas = FigureCanvasWx(self, -1, self.fig) self.toolbar = NavigationToolbar2Wx(self.canvas) self.toolbar.Realize() # On Windows, default frame size behaviour is incorrect # you don't need this under Linux tw, th = self.toolbar.GetSizeTuple() fw, fh = self.canvas.GetSizeTuple() self.toolbar.SetSize(wxSize(fw, th)) # Create a figure manager to manage things self.figmgr = FigureManager(self.canvas, 1, self) # Now put all into a sizer sizer = wxBoxSizer(wxVERTICAL) # This way of adding to sizer allows resizing sizer.Add(self.canvas, 1, wxLEFT|wxTOP|wxGROW) # Best to allow the toolbar to resize! sizer.Add(self.toolbar, 0, wxGROW) self.SetSizer(sizer) self.Fit() EVT_TIMER(self, TIMER_ID, self.onTimer) def init_plot_data(self): a = self.fig.add_subplot(111) a.set_title('Title') a.set_xlabel('Xaxis [u.a.]') a.set_ylabel('Yaxis [u.a.]') self.ind = numpy.arange(60) tmp = [] for i in range(60): tmp.append(numpy.sin((self.ind+i)*numpy.pi/15)) self.X = numpy.array(tmp) self.lines = a.plot(self.X[:,0],'o') self.count = 0 def GetToolBar(self): # You will need to override GetToolBar if you are using an # unmanaged toolbar in your frame return self.toolbar def onTimer(self, evt): self.count += 1 if self.count = 60: self.count = 0 self.lines[0].set_data(self.ind, self.X[:,self.count]) self.canvas.draw() self.canvas.gui_repaint() if __name__ == '__main__': app = wxPySimpleApp() frame = PlotFigure() frame.init_plot_data() # Initialise the timer - wxPython requires this to be connected to the # receivicng event handler t = wxTimer(frame, TIMER_ID) t.Start(100) frame.Show() app.MainLoop() - Using Tomcat but need to do more? Need to support web services, security? Get stuff done quickly with pre-integrated technology to make your job easier Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo http://sel.as-us.falkag.net/sel?cmd=lnkkid=120709bid=263057dat=121642 ___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users
[Matplotlib-users] x and ylabel problem when embedding in wx
Hi, (I'm sending again because email was probably filtered?) I have problem with xlabel and ylabel when embedding in wx. See snapshot : http://emmanuelfavrenicolin.free.fr/Public/Divers/Snapshots1/wx_snap.png I put a test code which is based on dynamic_demo_wx.py, adding only the 3 lines : a.set_title('Title') a.set_xlabel('Xaxis [u.a.]') a.set_ylabel('Yaxis [u.a.]') Just to add title, and label. In this case Ylabel is superposed on ytics labels and xlabel is hidden by the navigation toolbar. Do I need twiking and/or understand better wxpython ? Anyone can help me? sample code : import matplotlib matplotlib.use('WX') from matplotlib.backends.backend_wx import FigureCanvasWx,\ FigureManager, NavigationToolbar2Wx from matplotlib.figure import Figure from matplotlib.axes import Subplot import matplotlib.numerix as numpy from wxPython.wx import * TIMER_ID = wxNewId() class PlotFigure(wxFrame): def __init__(self): wxFrame.__init__(self, None, -1, Test embedded wxFigure) self.fig = Figure((6,4), 75) self.canvas = FigureCanvasWx(self, -1, self.fig) self.toolbar = NavigationToolbar2Wx(self.canvas) self.toolbar.Realize() # On Windows, default frame size behaviour is incorrect # you don't need this under Linux tw, th = self.toolbar.GetSizeTuple() fw, fh = self.canvas.GetSizeTuple() self.toolbar.SetSize(wxSize(fw, th)) # Create a figure manager to manage things self.figmgr = FigureManager(self.canvas, 1, self) # Now put all into a sizer sizer = wxBoxSizer(wxVERTICAL) # This way of adding to sizer allows resizing sizer.Add(self.canvas, 1, wxLEFT|wxTOP|wxGROW) # Best to allow the toolbar to resize! sizer.Add(self.toolbar, 0, wxGROW) self.SetSizer(sizer) self.Fit() EVT_TIMER(self, TIMER_ID, self.onTimer) def init_plot_data(self): a = self.fig.add_subplot(111) a.set_title('Title') a.set_xlabel('Xaxis [u.a.]') a.set_ylabel('Yaxis [u.a.]') self.ind = numpy.arange(60) tmp = [] for i in range(60): tmp.append(numpy.sin((self.ind+i)*numpy.pi/15)) self.X = numpy.array(tmp) self.lines = a.plot(self.X[:,0],'o') self.count = 0 def GetToolBar(self): # You will need to override GetToolBar if you are using an # unmanaged toolbar in your frame return self.toolbar def onTimer(self, evt): self.count += 1 if self.count = 60: self.count = 0 self.lines[0].set_data(self.ind, self.X[:,self.count]) self.canvas.draw() self.canvas.gui_repaint() if __name__ == '__main__': app = wxPySimpleApp() frame = PlotFigure() frame.init_plot_data() # Initialise the timer - wxPython requires this to be connected to the # receivicng event handler t = wxTimer(frame, TIMER_ID) t.Start(100) frame.Show() app.MainLoop() - Using Tomcat but need to do more? Need to support web services, security? Get stuff done quickly with pre-integrated technology to make your job easier Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo http://sel.as-us.falkag.net/sel?cmd=lnkkid=120709bid=263057dat=121642 ___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users
Re: [Matplotlib-users] x and ylabel problem when embedding in wx
John == John Hunter [EMAIL PROTECTED] writes: John It's not about wx or wxpython, it's a matplotlib issue. Let me add some color to that statement -- when I took a look at your screenshot, I realized you are using the WX backend and not the WXAgg backend. If you don't understand the difference, peruse http://matplotlib.sf.net/backends.html . WXAgg may have the same problem (and the same solution from my last post) but will give you more consistent rendering and layout. JDH - Using Tomcat but need to do more? Need to support web services, security? Get stuff done quickly with pre-integrated technology to make your job easier Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo http://sel.as-us.falkag.net/sel?cmd=lnkkid=120709bid=263057dat=121642 ___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users