overriding Collections.get_transform weirdness

Hi,

Awhile back, Jae-Joon helped me transform collection sizes from points to data values by overriding the `get_transform` method of a RegularPolyCollection (see example code below).

When I tried the code today, the collection didn't appear on the plot. Removing the get_transform method below brings the collection back, but of course, the sizes are not what I want.

Some simple testing suggests that changing the transform returned by `get_transform` changes the offsets of the collection items. In other words, the transform originally (i.e. in some older revision) modified only the scale of collection items, but now appears to modify both the scale and offset.

Is there a way to modify only the scale of collection items?

Thanks,
-Tony

BTW, I'm on svn r7950.

···

#-----------------
# The squares will not show up with the code below
# Comment out the get_transform method to see squares
# Change scale_x and scale_y to values close to 1 to see how they change both scale and offset

class SquareCollection(collections.RegularPolyCollection):
    """Return a collection of squares."""

    def __init__(self, **kwargs):
        super(SquareCollection, self).__init__(4, rotation=np.pi/4., **kwargs)

    def get_transform(self):
        """Return transform scaling circle areas to data space."""
        ax = self.axes
        pts2pixels = 72.0 / ax.figure.dpi
        scale_x = pts2pixels * ax.bbox.width / ax.viewLim.width
        scale_y = pts2pixels * ax.bbox.height / ax.viewLim.height
        return transforms.Affine2D().scale(scale_x, scale_y)

ax = plt.gca()
circle_areas = np.pi * np.ones(4)
xy = [(0, 0), (0, 1), (1, 0), (1, 1)]
squares = SquareCollection(sizes=circle_areas,
                           offsets=xy, transOffset=ax.transData,
                           facecolor='black')
ax.add_collection(squares, autolim=True)
plt.axis([-0.5, 1.5, -0.5, 1.5])
plt.show()

Which older revision (or release) worked as you expected?

Mike

Tony S Yu wrote:

···

Hi,

Awhile back, Jae-Joon helped me transform collection sizes from points to data values by overriding the `get_transform` method of a RegularPolyCollection (see example code below).

When I tried the code today, the collection didn't appear on the plot. Removing the get_transform method below brings the collection back, but of course, the sizes are not what I want.

Some simple testing suggests that changing the transform returned by `get_transform` changes the offsets of the collection items. In other words, the transform originally (i.e. in some older revision) modified only the scale of collection items, but now appears to modify both the scale and offset.

Is there a way to modify only the scale of collection items?

Thanks,
-Tony

BTW, I'm on svn r7950.

#-----------------
# The squares will not show up with the code below
# Comment out the get_transform method to see squares
# Change scale_x and scale_y to values close to 1 to see how they change both scale and offset

class SquareCollection(collections.RegularPolyCollection):
    """Return a collection of squares."""

    def __init__(self, **kwargs):
        super(SquareCollection, self).__init__(4, rotation=np.pi/4., **kwargs)

    def get_transform(self):
        """Return transform scaling circle areas to data space."""
        ax = self.axes
        pts2pixels = 72.0 / ax.figure.dpi
        scale_x = pts2pixels * ax.bbox.width / ax.viewLim.width
        scale_y = pts2pixels * ax.bbox.height / ax.viewLim.height
        return transforms.Affine2D().scale(scale_x, scale_y)

ax = plt.gca()
circle_areas = np.pi * np.ones(4)
xy = [(0, 0), (0, 1), (1, 0), (1, 1)]
squares = SquareCollection(sizes=circle_areas,
                           offsets=xy, transOffset=ax.transData,
                           facecolor='black')
ax.add_collection(squares, autolim=True)
plt.axis([-0.5, 1.5, -0.5, 1.5])
plt.show()

------------------------------------------------------------------------------
Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day trial. Simplify your report design, integration and deployment - and focus on what you do best, core application coding. Discover what's new with
Crystal Reports now. http://p.sf.net/sfu/bobj-july
_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users
  
--
Michael Droettboom
Science Software Branch
Operations and Engineering Division
Space Telescope Science Institute
Operated by AURA for NASA

Which older revision (or release) worked as you expected?

After some digging, I think this issue is caused by an error in the macosx backend (everything works fine with tkagg, qt4agg, and agg). Oddly enough, calling savefig(), instead of show(), with the macosx backend creates the correct plot, but calling savefig() after show() does not.

I'm actually not sure if my code worked for older revisions of the macosx backend (I may have had a different default backend before). The transform code doesn't work with revisions between 7950 and 7625; older versions break the macosx backend on my system (OS X 10.6.1).

-Tony

···

On Nov 11, 2009, at 1:33 PM, Michael Droettboom wrote:

Mike

Tony S Yu wrote:

Hi,

Awhile back, Jae-Joon helped me transform collection sizes from points to data values by overriding the `get_transform` method of a RegularPolyCollection (see example code below).

When I tried the code today, the collection didn't appear on the plot. Removing the get_transform method below brings the collection back, but of course, the sizes are not what I want.

Some simple testing suggests that changing the transform returned by `get_transform` changes the offsets of the collection items. In other words, the transform originally (i.e. in some older revision) modified only the scale of collection items, but now appears to modify both the scale and offset.

Is there a way to modify only the scale of collection items?

Thanks,
-Tony

BTW, I'm on svn r7950.

#-----------------
# The squares will not show up with the code below
# Comment out the get_transform method to see squares
# Change scale_x and scale_y to values close to 1 to see how they change both scale and offset

class SquareCollection(collections.RegularPolyCollection):
   """Return a collection of squares."""

   def __init__(self, **kwargs):
       super(SquareCollection, self).__init__(4, rotation=np.pi/4., **kwargs)

   def get_transform(self):
       """Return transform scaling circle areas to data space."""
       ax = self.axes
       pts2pixels = 72.0 / ax.figure.dpi
       scale_x = pts2pixels * ax.bbox.width / ax.viewLim.width
       scale_y = pts2pixels * ax.bbox.height / ax.viewLim.height
       return transforms.Affine2D().scale(scale_x, scale_y)

ax = plt.gca()
circle_areas = np.pi * np.ones(4)
xy = [(0, 0), (0, 1), (1, 0), (1, 1)]
squares = SquareCollection(sizes=circle_areas,
                          offsets=xy, transOffset=ax.transData,
                          facecolor='black')
ax.add_collection(squares, autolim=True)
plt.axis([-0.5, 1.5, -0.5, 1.5])
plt.show()

------------------------------------------------------------------------------
Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day trial. Simplify your report design, integration and deployment - and focus on what you do best, core application coding. Discover what's new with
Crystal Reports now. http://p.sf.net/sfu/bobj-july
_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users

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

Thanks for looking into this further. Can you file a bug with this script that appears differently in the PDF/PS/SVG/Agg backends vs. Mac OS X?

Cheers,
Mike

Tony S Yu wrote:

···

On Nov 11, 2009, at 1:33 PM, Michael Droettboom wrote:

Which older revision (or release) worked as you expected?

After some digging, I think this issue is caused by an error in the macosx backend (everything works fine with tkagg, qt4agg, and agg). Oddly enough, calling savefig(), instead of show(), with the macosx backend creates the correct plot, but calling savefig() after show() does not.

I'm actually not sure if my code worked for older revisions of the macosx backend (I may have had a different default backend before). The transform code doesn't work with revisions between 7950 and 7625; older versions break the macosx backend on my system (OS X 10.6.1).

-Tony

Mike

Tony S Yu wrote:

Hi,

Awhile back, Jae-Joon helped me transform collection sizes from points to data values by overriding the `get_transform` method of a RegularPolyCollection (see example code below).

When I tried the code today, the collection didn't appear on the plot. Removing the get_transform method below brings the collection back, but of course, the sizes are not what I want.

Some simple testing suggests that changing the transform returned by `get_transform` changes the offsets of the collection items. In other words, the transform originally (i.e. in some older revision) modified only the scale of collection items, but now appears to modify both the scale and offset.

Is there a way to modify only the scale of collection items?

Thanks,
-Tony

BTW, I'm on svn r7950.

#-----------------
# The squares will not show up with the code below
# Comment out the get_transform method to see squares
# Change scale_x and scale_y to values close to 1 to see how they change both scale and offset

class SquareCollection(collections.RegularPolyCollection):
   """Return a collection of squares."""

   def __init__(self, **kwargs):
       super(SquareCollection, self).__init__(4, rotation=np.pi/4., **kwargs)

   def get_transform(self):
       """Return transform scaling circle areas to data space."""
       ax = self.axes
       pts2pixels = 72.0 / ax.figure.dpi
       scale_x = pts2pixels * ax.bbox.width / ax.viewLim.width
       scale_y = pts2pixels * ax.bbox.height / ax.viewLim.height
       return transforms.Affine2D().scale(scale_x, scale_y)

ax = plt.gca()
circle_areas = np.pi * np.ones(4)
xy = [(0, 0), (0, 1), (1, 0), (1, 1)]
squares = SquareCollection(sizes=circle_areas,
                          offsets=xy, transOffset=ax.transData,
                          facecolor='black')
ax.add_collection(squares, autolim=True)
plt.axis([-0.5, 1.5, -0.5, 1.5])
plt.show()

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

Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day trial. Simplify your report design, integration and deployment - and focus on what you do best, core application coding. Discover what's new with
Crystal Reports now. http://p.sf.net/sfu/bobj-july
_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users

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

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

Thanks for looking into this further. Can you file a bug with this script that appears differently in the PDF/PS/SVG/Agg backends vs. Mac OS X?

Bug filed. Thanks for your response.

-Tony

···

On Nov 12, 2009, at 8:16 AM, Michael Droettboom wrote:

Cheers,
Mike

Tony S Yu wrote:

On Nov 11, 2009, at 1:33 PM, Michael Droettboom wrote:

Which older revision (or release) worked as you expected?

After some digging, I think this issue is caused by an error in the macosx backend (everything works fine with tkagg, qt4agg, and agg). Oddly enough, calling savefig(), instead of show(), with the macosx backend creates the correct plot, but calling savefig() after show() does not.

I'm actually not sure if my code worked for older revisions of the macosx backend (I may have had a different default backend before). The transform code doesn't work with revisions between 7950 and 7625; older versions break the macosx backend on my system (OS X 10.6.1).

-Tony