-
-
Notifications
You must be signed in to change notification settings - Fork 7.9k
Quadmesh.set_array validates dimensions #20215
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -2024,14 +2024,15 @@ def __init__(self, *args, **kwargs): | |||||||||||||||||||||||
kwargs.setdefault("pickradius", 0) | ||||||||||||||||||||||||
# end of signature deprecation code | ||||||||||||||||||||||||
|
||||||||||||||||||||||||
super().__init__(**kwargs) | ||||||||||||||||||||||||
_api.check_shape((None, None, 2), coordinates=coords) | ||||||||||||||||||||||||
self._coordinates = coords | ||||||||||||||||||||||||
self._antialiased = antialiased | ||||||||||||||||||||||||
self._shading = shading | ||||||||||||||||||||||||
|
||||||||||||||||||||||||
self._bbox = transforms.Bbox.unit() | ||||||||||||||||||||||||
self._bbox.update_from_data_xy(self._coordinates.reshape(-1, 2)) | ||||||||||||||||||||||||
# super init delayed after own init because array kwarg requires | ||||||||||||||||||||||||
# self._coordinates and self._shading | ||||||||||||||||||||||||
super().__init__(**kwargs) | ||||||||||||||||||||||||
jeffreypaul15 marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||||||||||||||||
|
||||||||||||||||||||||||
# Only needed during signature deprecation | ||||||||||||||||||||||||
__init__.__signature__ = inspect.signature( | ||||||||||||||||||||||||
|
@@ -2047,6 +2048,53 @@ def set_paths(self): | |||||||||||||||||||||||
self._paths = self._convert_mesh_to_paths(self._coordinates) | ||||||||||||||||||||||||
self.stale = True | ||||||||||||||||||||||||
|
||||||||||||||||||||||||
def set_array(self, A): | ||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is public API, so it needs a docstring. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ah, will do. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not really sure how to structure this docstring, please make any changes if required There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Well, it would have inherited a docstring from matplotlib/lib/matplotlib/cm.py Lines 363 to 373 in 63261cc
Though some of that needs to be overridden anyway, so it's good to write one here. |
||||||||||||||||||||||||
""" | ||||||||||||||||||||||||
Set the data values. | ||||||||||||||||||||||||
|
||||||||||||||||||||||||
Parameters | ||||||||||||||||||||||||
---------- | ||||||||||||||||||||||||
A : (M, N) array-like or M*N array-like | ||||||||||||||||||||||||
If the values are provided as a 2D grid, the shape must match the | ||||||||||||||||||||||||
coordinates grid. If the values are 1D, they are reshaped to 2D. | ||||||||||||||||||||||||
M, N follow from the coordinates grid, where the coordinates grid | ||||||||||||||||||||||||
shape is (M, N) for 'gouraud' *shading* and (M+1, N+1) for 'flat' | ||||||||||||||||||||||||
shading. | ||||||||||||||||||||||||
""" | ||||||||||||||||||||||||
height, width = self._coordinates.shape[0:-1] | ||||||||||||||||||||||||
misshapen_data = False | ||||||||||||||||||||||||
faulty_data = False | ||||||||||||||||||||||||
|
||||||||||||||||||||||||
if self._shading == 'flat': | ||||||||||||||||||||||||
h, w = height-1, width-1 | ||||||||||||||||||||||||
else: | ||||||||||||||||||||||||
h, w = height, width | ||||||||||||||||||||||||
|
||||||||||||||||||||||||
if A is not None: | ||||||||||||||||||||||||
shape = np.shape(A) | ||||||||||||||||||||||||
if len(shape) == 1: | ||||||||||||||||||||||||
if shape[0] != (h*w): | ||||||||||||||||||||||||
faulty_data = True | ||||||||||||||||||||||||
elif shape != (h, w): | ||||||||||||||||||||||||
if np.prod(shape) == (h * w): | ||||||||||||||||||||||||
misshapen_data = True | ||||||||||||||||||||||||
else: | ||||||||||||||||||||||||
faulty_data = True | ||||||||||||||||||||||||
|
||||||||||||||||||||||||
if misshapen_data: | ||||||||||||||||||||||||
_api.warn_deprecated( | ||||||||||||||||||||||||
"3.5", message=f"For X ({width}) and Y ({height}) " | ||||||||||||||||||||||||
f"with {self._shading} shading, the expected shape of " | ||||||||||||||||||||||||
f"A is ({h}, {w}). Passing A ({A.shape}) is deprecated " | ||||||||||||||||||||||||
"since %(since)s and will become an error %(removal)s.") | ||||||||||||||||||||||||
|
||||||||||||||||||||||||
if faulty_data: | ||||||||||||||||||||||||
raise TypeError( | ||||||||||||||||||||||||
f"Dimensions of A {A.shape} are incompatible with " | ||||||||||||||||||||||||
f"X ({width}) and/or Y ({height})") | ||||||||||||||||||||||||
|
||||||||||||||||||||||||
return super().set_array(A) | ||||||||||||||||||||||||
|
||||||||||||||||||||||||
def get_datalim(self, transData): | ||||||||||||||||||||||||
return (self.get_transform() - transData).transform_bbox(self._bbox) | ||||||||||||||||||||||||
|
||||||||||||||||||||||||
|
Uh oh!
There was an error while loading. Please reload this page.