Skip to content

[WIP] Quad mesh extent #3095 #4017

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 35 additions & 4 deletions lib/matplotlib/collections.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,6 @@ class Collection(artist.Artist, cm.ScalarMappable):
_transOffset = transforms.IdentityTransform()
_transforms = []



def __init__(self,
edgecolors=None,
facecolors=None,
Expand Down Expand Up @@ -1501,7 +1499,7 @@ def _set_transforms(self):
self._transforms[:, 1, 0] = widths * sin_angle
self._transforms[:, 1, 1] = heights * cos_angle
self._transforms[:, 2, 2] = 1.0

_affine = transforms.Affine2D
if self._units == 'xy':
m = ax.transData.get_affine().get_matrix().copy()
Expand Down Expand Up @@ -1689,7 +1687,8 @@ def __init__(self, meshWidth, meshHeight, coordinates,

self._bbox = transforms.Bbox.unit()
self._bbox.update_from_data_xy(coordinates.reshape(
((meshWidth + 1) * (meshHeight + 1), 2)))
((meshWidth + 1) * (meshHeight + 1), 2)),
ignore=True)

# By converting to floats now, we can avoid that on every draw.
self._coordinates = self._coordinates.reshape(
Expand All @@ -1705,6 +1704,38 @@ def set_paths(self):
self._paths = self.convert_mesh_to_paths(
self._meshWidth, self._meshHeight, self._coordinates)

def get_window_extent(self, renderer):
# get a dummy bounding box
bbox = transforms.Bbox([[0, 0], [0, 0]])
# get the data and offset transforms
trans_data_to_xy = self.get_transform().transform
transOffset = self.get_offset_transform().transform
# convert the transforms to data-units
offsets = transOffset(self._offsets)

# deal with masked arrays
coordinates = self._coordinates
if ma.isMaskedArray(coordinates):
c = coordinates.data
else:
c = coordinates
# slice sets to pick out the corners of each patch
# bottom-left, top-left, top-right, bottom-right
slice_sets = ((slice(0, -1), slice(0, -1)),
(slice(0, -1), slice(1, None)),
(slice(1, None), slice(1, None)),
(slice(1, None), slice(0, -1))
)
# first time ignore the existing bounds
ignore = True
for x_slc, y_slc in slice_sets:
bbox.update_from_data_xy(
trans_data_to_xy(c[x_slc, y_slc].reshape(-1, 2) + offsets),
ignore=ignore)
# but on subsequent loops don't shrink the bounding box
ignore = False
return bbox

@staticmethod
def convert_mesh_to_paths(meshWidth, meshHeight, coordinates):
"""
Expand Down