partial ring patch

Hi,

We found we needed to draw a partial ring, but didn't see one in patches.py.

Attached is a generalization of Wedge to accept an inner and an outer radius.

Should I add this to patches?

Note that rather saving the unit ring and constructing a transform as in Wedge:

     def get_patch_transform(self):
         x = self.convert_xunits(self.center[0])
         y = self.convert_yunits(self.center[1])
         rx = self.convert_xunits(self.r2)
         ry = self.convert_yunits(self.r2)
         self._patch_transform = transforms.Affine2D() \
             .scale(rx, ry).translate(x, y)
         return self._patch_transform

I just transform the coordinates directly:

         v *= r2
         v += numpy.array(center)
         self._path = Path(v,c)
         self._patch_transform = transforms.IdentityTransform()

Any reason to prefer one over the other?

   - Paul

ring.py (3.4 KB)

Paul Kienzle wrote:

Hi,

We found we needed to draw a partial ring, but didn't see one in patches.py.

Attached is a generalization of Wedge to accept an inner and an outer radius.

Should I add this to patches?

Looks like a useful feature to me. Could be used for doing these sort of "hierarchical pie chart" graphs:

http://linux.byexamples.com/wp-content/uploads/2007/04/baobab.png

Any reason not to implement this simply as an additional kwarg to Wedge, rather than a new class -- since Ring with a r2 == 0 is equivalent to Wedge anyway? Just thinking of having less code to maintain...but maybe that's more confusing for end users.

Note that rather saving the unit ring and constructing a transform as in Wedge:

    def get_patch_transform(self):
        x = self.convert_xunits(self.center[0])
        y = self.convert_yunits(self.center[1])
        rx = self.convert_xunits(self.r2)
        ry = self.convert_yunits(self.r2)
        self._patch_transform = transforms.Affine2D() \
            .scale(rx, ry).translate(x, y)
        return self._patch_transform

I just transform the coordinates directly:

        v *= r2
        v += numpy.array(center)
        self._path = Path(v,c)
        self._patch_transform = transforms.IdentityTransform()

Any reason to prefer one over the other?

No strong reason. The reason I did it that way was so that if the patch were scaled or translated in an animation, the transformation of the wedge vertices would happen on-the-fly within backend_agg. It's not based on any benchmarking, but probably more on old habits from game programming (where it's common practice to keep shapes and transforms separated and let the hardware apply them). I doubt it matters here.

Mike

···

  - Paul

------------------------------------------------------------------------

One problem is that I had to explicitly set the axes limits 1because add_patch

wasn't updating the limits to include the bounds of the new patch.
------------------------------------------------------------------------

-------------------------------------------------------------------------
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK & win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/
------------------------------------------------------------------------

_______________________________________________
Matplotlib-devel mailing list
Matplotlib-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-devel

--
Michael Droettboom
Science Software Branch
Operations and Engineering Division
Space Telescope Science Institute
Operated by AURA for NASA

Paul Kienzle wrote:

Hi,

We found we needed to draw a partial ring, but didn't see one in patches.py.

Attached is a generalization of Wedge to accept an inner and an outer radius.

Should I add this to patches?

Looks like a useful feature to me. Could be used for doing these sort of "hierarchical pie chart" graphs:

http://linux.byexamples.com/wp-content/uploads/2007/04/baobab.png

That's pretty, though I have no idea what it is supposed to represent.

Any reason not to implement this simply as an additional kwarg to Wedge, rather than a new class -- since Ring with a r2 == 0 is equivalent to Wedge anyway? Just thinking of having less code to maintain...but maybe that's more confusing for end users.

Okay, I will replace Wedge on svn.

     - Paul

···

On Nov 14, 2008, at 9:59 AM, Michael Droettboom wrote:

Paul Kienzle wrote:

Paul Kienzle wrote:

Hi,

We found we needed to draw a partial ring, but didn't see one in patches.py.

Attached is a generalization of Wedge to accept an inner and an outer radius.

Should I add this to patches?

Looks like a useful feature to me. Could be used for doing these sort of "hierarchical pie chart" graphs:

http://linux.byexamples.com/wp-content/uploads/2007/04/baobab.png

That's pretty, though I have no idea what it is supposed to represent.

It's the size of directories in a directory structure. Each ring is a different depth of nesting. Useful wherever you have a heirarchical percentages... 50% of %40 of %30... Of course, suffers from the same usability problems of pie charts. I'm not seriously suggesting we pursue this... Your Ring class just reminded me of it.

Mike

···

On Nov 14, 2008, at 9:59 AM, Michael Droettboom wrote:

--
Michael Droettboom
Science Software Branch
Operations and Engineering Division
Space Telescope Science Institute
Operated by AURA for NASA

Done. The keyword I used is *width* for the width of the ring.
Using width=None draws the whole wedge.

   - Paul

···

On Nov 14, 2008, at 12:36 PM, Paul Kienzle wrote:

Any reason not to implement this simply as an additional kwarg to
Wedge, rather than a new class -- since Ring with a r2 == 0 is
equivalent to Wedge anyway? Just thinking of having less code to
maintain...but maybe that's more confusing for end users.

Okay, I will replace Wedge on svn.