Clipping

Hi,

Can anyone explain how the clipping code works? Or maybe how the backends decide whether to draw a line? In working on drawing skewT's, I need slanted gridlines. Through proper setting of transforms, I can get them to draw slanted fine, but because they are slanted, the data x range at the top of the plot is not equal to the data x range at the bottom.

One issue that crops up as a result (which I've mentioned before) is that the tickmarks at the top get drawn off past the right end of the plot (enabling clipping of ticklines fixes this).

The second issue, which is the focus here, is that it seems impossible to get matplotlib to draw any gridlines that start before the left side of the chart. I can tweak Axis.draw() and get it to draw *all* the currently set tick marks and I can disable clipping so that the gridlines draw past the *right* side of the plot, but I can't seem to figure out how to draw a grid lines that starts from off the left side.

I've attached a small example of what I'm trying to do and an example of the results I'm getting with a few of the mods I've done to MPL (also attached).

Can anybody point me where I've gone wrong? I traced the calls down to the renderer (in this case GTK), but they for some reason won't trace down any further.

Ryan

axis_draw_changes.diff (923 Bytes)

skew.png

skew-example.py (3.4 KB)

···

--
Ryan May
Graduate Research Assistant
School of Meteorology
University of Oklahoma

Hi,

Can anyone explain how the clipping code works? Or maybe how the backends
decide whether to draw a line? In working on drawing skewT's, I need
slanted gridlines. Through proper setting of transforms, I can get them to
draw slanted fine, but because they are slanted, the data x range at the top
of the plot is not equal to the data x range at the bottom.

The clipping code works as you would expect -- you pass it a path and
the artist is clipped to that path. I think you are being bitten by
something else (see below)

One issue that crops up as a result (which I've mentioned before) is that
the tickmarks at the top get drawn off past the right end of the plot
(enabling clipping of ticklines fixes this).

Yes, you probably want to clip them

The second issue, which is the focus here, is that it seems impossible to
get matplotlib to draw any gridlines that start before the left side of the
chart. I can tweak Axis.draw() and get it to draw *all* the currently set
tick marks and I can disable clipping so that the gridlines draw past the
*right* side of the plot, but I can't seem to figure out how to draw a grid
lines that starts from off the left side.

Look in the axis at the method:

    def draw(self, renderer):
        if not self.get_visible(): return
        renderer.open_group(self.__name__)
        midPoint =
mtransforms.interval_contains(self.get_view_interval(),
self.get_loc())

        if midPoint:
            if self.gridOn:
                self.gridline.draw(renderer)
            if self.tick1On:
                self.tick1line.draw(renderer)
            if self.tick2On:
                self.tick2line.draw(renderer)

The is midPoint is causing your troubles. Replace that with 'if 1 or
midPoint' and your grids magically appear. You may want to insert
some logic here so that custom classes can override this behavior.

You mentioned you were using GTK -- clipping is not properly supported
using the gdk renderer, so make sure you are using GTKAgg (or some
other Agg variant) for your UI while testing clipping.

JDH

···

On Sun, Jul 27, 2008 at 3:57 PM, Ryan May <rmay31@...149...> wrote:

For a little extra color on what is going on here -- we don't want to
automatically clip the tick lines to the axes bounding box because
someone might choose the tick direction 'out'. Since we can't use
graphical clipping, this test is trying to make sure the tick location
is in the view interval before drawing it. You may want to consider a
overridable method 'is_draw_tick' or something along those lines,
which defaults to::

  mtransforms.interval_contains(self.get_view_interval(), self.get_loc())

JDH

···

On Sun, Jul 27, 2008 at 4:24 PM, John Hunter <jdh2358@...149...> wrote:

       if midPoint:
           if self.gridOn:
               self.gridline.draw(renderer)
           if self.tick1On:
               self.tick1line.draw(renderer)
           if self.tick2On:
               self.tick2line.draw(renderer)