From: John H. <jdh...@ac...> - 2004-03-31 14:02:04
|
>>>>> "Steve" == Steve Chaplin <ste...@ya...> writes: Steve> John, I noticed that when plotting sine waves Steve> (simple_plot.py for example) with the gtk backend that the Steve> lowest points are not plotted. Hi Steve, thanks for letting me know. There is an off-by-one error and it looks like and easy fix. For future reference, you may want to consider using GTKAgg as your default GUI. This has the GTK widget but uses agg for rendering. Agg supports subpixel rendering and so isn't susceptible to one pixel errors that crop up in GTK in a number of contexts. At low resolutions, these become particularly noticeable. Other benefits over the GTK backend are alpha blending, anti-aliased drawing, and faster image support - http://matplotlib.sourceforge.net/backends.html#GTKAgg Steve> So I wrote a test script to plot a square, the result is Steve> that the left and top edges are plotted and the bottom and Steve> right edges are clipped off (I can pan the view to display Steve> the missing lines). I can't think of any reason why you Steve> would plot data points and then expect them to be clipped Steve> off, so to me it looks like an off-by-one error. Now on to your problem. In backend_gtk draw_rectangle, change x, y = int(x), self.height-int(math.ceil(y+height)) to x, y = int(x), self.height-int(y+height) and the GraphicsContext.set_clip_rectangle method to def set_clip_rectangle(self, rectangle): GraphicsContextBase.set_clip_rectangle(self, rectangle) l,b,w,h = rectangle rectangle = (int(l), self.renderer.height-int(b+h)+1, int(w), int(h)) self.gdkGC.set_clip_rectangle(rectangle) This fixes the bug, but doesn't handle your test case. The lines in your example are still clipped, but there is a reason for that. In your example, the lines are exactly where the axes lines will be drawn. It's a judgment call whether you want to see the axes line or your line at that location. In interactive navigation when you pan and zoom around, it often happens that your data extend beyond the axes lines; in this case you usually want a clean axes line not partially obscured by your data. If I set the clip so that the lines in your example are plotted, then the axes lines are also overridden in other where the data extend beyond the axes. By tweaking the clip rectangle, eg rectangle = (int(l), self.renderer.height-int(b+h), int(w+1), int(h+2)) you can get your lines drawn but then the axes lines are obscured, eg in subplot_demo and arctest. Try experimenting with a few different demos and clip settings to see what you think is the best compromise; let me know. In Agg this is less of a problem since agg uses pixel blending when two pixels are drawn at the same location so the data pixel over the axes line pixel is less glaring. Cheers, JDH |