SourceForge logo
SourceForge logo
Menu

matplotlib-users

From: Steve C. <ste...@ya...> - 2004年03月31日 13:02:13
John,
I noticed that when plotting sine waves (simple_plot.py for example)
with the gtk backend that the lowest points are not plotted.
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.
Test program:
from matplotlib.matlab import *
figure(1)
x = arange(0, 10+1, 1)
plot(x, x*0+10, 'r-',
 x, x*0, 'r-',
 x*0, x, 'r-',
 x*0+10, x, 'r-')
show()
Regards,
Steve
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
Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.
Thanks for helping keep SourceForge clean.
X





Briefly describe the problem (required):
Upload screenshot of ad (required):
Select a file, or drag & drop file here.
Screenshot instructions:

Click URL instructions:
Right-click on the ad, choose "Copy Link", then paste here →
(This may not be possible with some types of ads)

More information about our ad policies

Ad destination/click URL:

AltStyle によって変換されたページ (->オリジナル) /