8000 Ensure image scale factors are scalars by ngoldbaum · Pull Request #10289 · matplotlib/matplotlib · GitHub
[go: up one dir, main page]

Skip to content

Ensure image scale factors are scalars #10289

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

Merged
merged 1 commit into from
Jan 23, 2018
Merged
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
6 changes: 4 additions & 2 deletions lib/matplotlib/image.py
Original file line number Diff line number Diff line change
Expand Up @@ -394,8 +394,10 @@ def _make_image(self, A, in_bbox, out_bbox, clip_bbox, magnification=1.0,
A_scaled = np.empty(A.shape, dtype=scaled_dtype)
A_scaled[:] = A
A_scaled -= a_min
a_min = a_min.astype(scaled_dtype)
a_max = a_max.astype(scaled_dtype)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It took me a bit to understand why this was necessary (because ytarray inherits nparray). Can you add a comment that makes it clear why this extra call is needed? Otherwise looks fine to me!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've added the comment

# a_min and a_max might be ndarray subclasses so use
# asscalar to ensure they are scalars to avoid errors
a_min = np.asscalar(a_min.astype(scaled_dtype))
a_max = np.asscalar(a_max.astype(scaled_dtype))

if a_min != a_max:
A_scaled /= ((a_max - a_min) / 0.8)
Expand Down
0