[matplotlib-devel] Bug with restore_background when mpl is embedded in wxpython
Hi, Restore_region does not appear to work when embedding mpl into wxpython. Attached is a simple modification of the cookbook animation (http://www.scipy.org/Cookbook/Matplotlib/Animations) to illustrate this problem. I modified the example so it is updated on mouse movements (followed by idle time) so that the problem is more visual. There is also a flag to add one second timeouts between commands in the update method. When looking at the slowed animation it is clear that the background is never restored. Michiel Hoon thinks that the problem is due to the fact that restore_region is not implemented within the event loop and that the proper solution requires discussion:) Elan --- Of joys departed, not to return, how painful the remembrance. - Robert Blair #!/usr/bin/env python import matplotlib matplotlib.use('WXAgg') import matplotlib.numerix as nx from matplotlib.backends.backend_wxagg import FigureCanvasWxAgg as FigCanvas import wx import time # A flag to pause between every command in the update stage slowdown=False #-- class MainFrame(wx.Frame,matplotlib.figure.Figure): """Main frame for a simple graph.""" def __init__(self, parent, id): wx.Frame.__init__(self,None,-1) # creating the matplotlib figure and canvas. self._fig = matplotlib.figure.Figure( None) self.canvas = FigCanvas(self, wx.ID_ANY, self._fig ) # creating some data self.x = nx.arange(0,2*nx.pi,0.01) # adding the suplot and a line. self.ax = self._fig.add_subplot(111) self.line, = self.ax.plot(self.x, nx.sin(self.x), animated=True) if slowdown==True: time.sleep(1) # save the clean slate background -- everything but the animated line # is drawn and saved in the pixel buffer background self.background = self._fig.canvas.copy_from_bbox(self.ax.bbox) # Update when there is idle time. Note that this will only refire when # something happens (such as a mouse movement) this will allow # a better view of the dynamics of the updates. self.Bind(wx.EVT_IDLE, self.update_line) # a variable to induce change self.update_line_cnt=0 return #-- def update_line(self,event): """ This function will update and redraw the data""" # update the data self.line.set_ydata(nx.sin(self.x+self.update_line_cnt/20.0)) # restore the clean slate background self._fig.canvas.restore_region(self.background) if slowdown==True: time.sleep(1) # just draw the animated artist self.ax.draw_artist(self.line) if slowdown==True: time.sleep(1) # just redraw the axes rectangle self._fig.canvas.blit(self.ax.bbox) if slowdown==True: time.sleep(1) # Uncomment to speed up updates without actions. #event.RequestMore(True) #Getting some changes self.update_line_cnt+=1 return True #-- if __name__ == '__main__': App=wx.App() frame=MainFrame(None,-1) frame.Show(True) App.MainLoop() -- The NEW KODAK i700 Series Scanners deliver under ANY circumstances! Your production scanning environment may not be a perfect world - but thanks to Kodak, there's a perfect scanner to get the job done! With the NEW KODAK i700 Series Scanner you'll get full speed at 300 dpi even with all image processing features enabled. http://p.sf.net/sfu/kodak-com___ Matplotlib-devel mailing list Matplotlib-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-devel
[matplotlib-devel] Cairo Backend and Subpixel Rendering
Hi all, As some of you probably know I am working on the GSoC project to externalise the Mathtex engine from Matplotlib. Today I have been toying around with the renderer using various backends. One of the interesting things that I discovered was that the Cairo backend was making use of subpixel rendering. (Or 'ClearType' as Microsoft call it.) This is not surprising -- by default Cairo will respect a users fontconfig settings when rendering text. Since I have subpixel rendering enabled all text rendered by Cairo is subpixel rendered. While this is fantastic for on screen text -- being significantly more pleasing to look at that the text produced by the AGG backend -- it is unsuitable for print. Now it is not too difficult to disable this, Cairo has an API call: cairo_font_options_set_antialias to deal with this. While I could write a quick patch to always disable subpixel rendering it would be something off a loss to those who either view their graphs onscreen or export them for the web -- where using subpixel rendering is now surprisingly common. Is it worth looking into adding subpixel rendering as a configuration option? Regards, Freddie. -- The NEW KODAK i700 Series Scanners deliver under ANY circumstances! Your production scanning environment may not be a perfect world - but thanks to Kodak, there's a perfect scanner to get the job done! With the NEW KODAK i700 Series Scanner you'll get full speed at 300 dpi even with all image processing features enabled. http://p.sf.net/sfu/kodak-com ___ Matplotlib-devel mailing list Matplotlib-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-devel
Re: [matplotlib-devel] Bug with restore_background when mpl is embedded in wxpython
Here is a slightly modified version of your script which works for me. I don't think this is the bug in mpl. Note that the ax.bbox does change if the canvas size change. In your original script, the copy_from_bbox is called before frame.Show() and this seems to cause a mismatching bbox. My modified example is also not perfect. A new background image needs to be saved whenever ax.bbox changes (e.g. when resizing canvas). -JJ On Fri, May 8, 2009 at 5:02 PM, Elan Pavlov wrote: > Hi, > Restore_region does not appear to work when embedding mpl into > wxpython. Attached is a simple modification of the cookbook animation > (http://www.scipy.org/Cookbook/Matplotlib/Animations) to illustrate > this problem. I modified the example so it is updated on mouse > movements (followed by idle time) so that the problem is more visual. > There is also a flag to add one second timeouts between commands in > the update method. When looking at the slowed animation it is clear > that the background is never restored. > Michiel Hoon thinks that the problem is due to the fact that > restore_region is not implemented within the event loop and that the > proper solution requires discussion:) > > Elan > --- > Of joys departed, not to return, how painful the remembrance. > - Robert Blair > > -- > The NEW KODAK i700 Series Scanners deliver under ANY circumstances! Your > production scanning environment may not be a perfect world - but thanks to > Kodak, there's a perfect scanner to get the job done! With the NEW KODAK i700 > Series Scanner you'll get full speed at 300 dpi even with all image > processing features enabled. http://p.sf.net/sfu/kodak-com > ___ > Matplotlib-devel mailing list > Matplotlib-devel@lists.sourceforge.net > https://lists.sourceforge.net/lists/listinfo/matplotlib-devel > > #!/usr/bin/env python import matplotlib matplotlib.use('WXAgg') import matplotlib.numerix as nx from matplotlib.backends.backend_wxagg import FigureCanvasWxAgg as FigCanvas import wx import time # A flag to pause between every command in the update stage slowdown=False #-- class MainFrame(wx.Frame,matplotlib.figure.Figure): """Main frame for a simple graph.""" def __init__(self, parent, id): wx.Frame.__init__(self,None,-1) # creating the matplotlib figure and canvas. self._fig = matplotlib.figure.Figure( None) self.canvas = FigCanvas(self, wx.ID_ANY, self._fig ) # creating some data self.x = nx.arange(0,2*nx.pi,0.01) # adding the suplot and a line. self.ax = self._fig.add_subplot(111) self.line, = self.ax.plot(self.x, nx.sin(self.x), animated=True) if slowdown==True: time.sleep(1) # Update when there is idle time. Note that this will only refire when # something happens (such as a mouse movement) this will allow # a better view of the dynamics of the updates. self.Bind(wx.EVT_IDLE, self.update_line) # a variable to induce change self.update_line_cnt=0 return def savebg(self): # save the clean slate background -- everything but the animated line # is drawn and saved in the pixel buffer background self._fig.canvas.draw() self.background = self._fig.canvas.copy_from_bbox(self.ax.bbox) #-- def update_line(self,event): """ This function will update and redraw the data""" # update the data self.line.set_ydata(nx.sin(self.x+self.update_line_cnt/20.0)) # restore the clean slate background self._fig.canvas.restore_region(self.background) if slowdown==True: time.sleep(1) # just draw the animated artist self.ax.draw_artist(self.line) if slowdown==True: time.sleep(1) # just redraw the axes rectangle self._fig.canvas.blit(self.ax.bbox) if slowdown==True: time.sleep(1) # Uncomment to speed up updates without actions. #event.RequestMore(True) #Getting some changes self.update_line_cnt+=1 return True #-- if __name__ == '__main__': App=wx.App() frame=MainFrame(None,-1) frame.Show(True) frame.savebg() App.MainLoop() -- The NEW KODAK i700 Series Scanners deliver under ANY circumstances! Your production scanning environment may not be a perfect world - but thanks to Kodak, there's a perfect scanner to get the job done! With the NEW KODAK i700 Series Scanner you'll get full speed at 300 dpi even with al
Re: [matplotlib-devel] Bug with restore_background when mpl is embedded in wxpython
On Sat, May 9, 2009 at 12:08 PM, Jae-Joon Lee wrote: > Here is a slightly modified version of your script which works for me. > > I don't think this is the bug in mpl. Note that the ax.bbox does > change if the canvas size change. In your original script, the > copy_from_bbox is called before frame.Show() and this seems to cause a > mismatching bbox. > > My modified example is also not perfect. A new background image needs > to be saved whenever ax.bbox changes (e.g. when resizing canvas). probably best way to do this is to connect to the draw_event, and update the background on the draw_event. I've updated the example and attached it -- do you mind if I commit it to the mpl examples dir (and does this solve all the issues you are having)? JDH anim3.py Description: Binary data -- The NEW KODAK i700 Series Scanners deliver under ANY circumstances! Your production scanning environment may not be a perfect world - but thanks to Kodak, there's a perfect scanner to get the job done! With the NEW KODAK i700 Series Scanner you'll get full speed at 300 dpi even with all image processing features enabled. http://p.sf.net/sfu/kodak-com___ Matplotlib-devel mailing list Matplotlib-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-devel
Re: [matplotlib-devel] Cairo Backend and Subpixel Rendering
John Hunter wrote: > On Sat, May 9, 2009 at 9:32 AM, Freddie Witherden > wrote: >> Hi all, >> >> As some of you probably know I am working on the GSoC project to >> externalise the Mathtex engine from Matplotlib. Today I have been >> toying around with the renderer using various backends. >> >> One of the interesting things that I discovered was that the Cairo >> backend was making use of subpixel rendering. (Or 'ClearType' as >> Microsoft call it.) This is not surprising -- by default Cairo will >> respect a users fontconfig settings when rendering text. Since I have >> subpixel rendering enabled all text rendered by Cairo is subpixel >> rendered. >> >> While this is fantastic for on screen text -- being significantly more >> pleasing to look at that the text produced by the AGG backend -- it is >> unsuitable for print. Now it is not too difficult to disable this, >> Cairo has an API call: cairo_font_options_set_antialias to deal with >> this. >> >> While I could write a quick patch to always disable subpixel rendering >> it would be something off a loss to those who either view their graphs >> onscreen or export them for the web -- where using subpixel rendering >> is now surprisingly common. >> >> Is it worth looking into adding subpixel rendering as a configuration >> option? > > The matplotlib.lines.Line2D objects has an antialiased property -- we > could add the same property to matplotlib.text.Text to turn on/off > subpixel rendering (which could also be supported as an rc param) I haven't poked around, so this may be a stupid question, but: for cairo, can subpixel rendering simply be left on for screen display and automatically turned off when writing to a file via savefig? If this can be done, it seems like a better solution than requiring to the user to turn the parameter on and off manually, depending on whether show() or savefig() is being called. Eric > > JDH -- The NEW KODAK i700 Series Scanners deliver under ANY circumstances! Your production scanning environment may not be a perfect world - but thanks to Kodak, there's a perfect scanner to get the job done! With the NEW KODAK i700 Series Scanner you'll get full speed at 300 dpi even with all image processing features enabled. http://p.sf.net/sfu/kodak-com ___ Matplotlib-devel mailing list Matplotlib-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-devel
Re: [matplotlib-devel] Cairo Backend and Subpixel Rendering
On Sat, May 9, 2009 at 9:32 AM, Freddie Witherden wrote: > Hi all, > > As some of you probably know I am working on the GSoC project to > externalise the Mathtex engine from Matplotlib. Today I have been > toying around with the renderer using various backends. > > One of the interesting things that I discovered was that the Cairo > backend was making use of subpixel rendering. (Or 'ClearType' as > Microsoft call it.) This is not surprising -- by default Cairo will > respect a users fontconfig settings when rendering text. Since I have > subpixel rendering enabled all text rendered by Cairo is subpixel > rendered. > > While this is fantastic for on screen text -- being significantly more > pleasing to look at that the text produced by the AGG backend -- it is > unsuitable for print. Now it is not too difficult to disable this, > Cairo has an API call: cairo_font_options_set_antialias to deal with > this. > > While I could write a quick patch to always disable subpixel rendering > it would be something off a loss to those who either view their graphs > onscreen or export them for the web -- where using subpixel rendering > is now surprisingly common. > > Is it worth looking into adding subpixel rendering as a configuration > option? The matplotlib.lines.Line2D objects has an antialiased property -- we could add the same property to matplotlib.text.Text to turn on/off subpixel rendering (which could also be supported as an rc param) JDH -- The NEW KODAK i700 Series Scanners deliver under ANY circumstances! Your production scanning environment may not be a perfect world - but thanks to Kodak, there's a perfect scanner to get the job done! With the NEW KODAK i700 Series Scanner you'll get full speed at 300 dpi even with all image processing features enabled. http://p.sf.net/sfu/kodak-com ___ Matplotlib-devel mailing list Matplotlib-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-devel
Re: [matplotlib-devel] Bug with restore_background when mpl is embedded in wxpython
On Sat, May 9, 2009 at 7:05 PM, Elan Pavlov wrote: > As for committing it to the repository I'd be honored if Jae Joon agrees. Sure, -JJ -- The NEW KODAK i700 Series Scanners deliver under ANY circumstances! Your production scanning environment may not be a perfect world - but thanks to Kodak, there's a perfect scanner to get the job done! With the NEW KODAK i700 Series Scanner you'll get full speed at 300 dpi even with all image processing features enabled. http://p.sf.net/sfu/kodak-com ___ Matplotlib-devel mailing list Matplotlib-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-devel