John, I noticed that when plotting sine waves
> (simple_plot.py for example) with the gtk backend that the
> 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 -
> So I wrote a test script to plot a square, the result is
> that the left and top edges are plotted and the bottom and
> right edges are clipped off (I can pan the view to display
> the missing lines). I can't think of any reason why you
> would plot data points and then expect them to be clipped
> 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))
x, y = int(x), self.height-int(y+height)
and the GraphicsContext.set_clip_rectangle method to
def set_clip_rectangle(self, rectangle):
l,b,w,h = rectangle
rectangle = (int(l), self.renderer.height-int(b+h)+1,
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),
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.