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()