-
-
Notifications
You must be signed in to change notification settings - Fork 7.9k
Check origin when saving image to PNG #7731
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
Conversation
@@ -521,6 +521,8 @@ def contains(self, mouseevent): | |||
|
|||
def write_png(self, fname): | |||
"""Write the image to png file with fname""" | |||
if self.origin == 'upper': | |||
self._A = self._A[::-1] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You should not overwrite self._A
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is better to either flip it in the call to_rgba
or flip the return im
below. Reassiging _A
like this will cause the image to alternate orientation every time you called write_png
.
Please do not backport this until after 2.0 final is out. |
@@ -521,6 +521,8 @@ def contains(self, mouseevent): | |||
|
|||
def write_png(self, fname): | |||
"""Write the image to png file with fname""" | |||
if self.origin == 'upper': | |||
self._A = self._A[::-1] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is better to either flip it in the call to_rgba
or flip the return im
below. Reassiging _A
like this will cause the image to alternate orientation every time you called write_png
.
2c44b9f
to
abcdf28
Compare
@Kojoley @tacaswell thanks. Is the test failure related to #7726? |
Yes, thanks, I thought that had been merged! |
@@ -153,7 +153,7 @@ def test_imsave_color_alpha(): | |||
data = random.rand(16, 16, 4) | |||
|
|||
buff = io.BytesIO() | |||
plt.imsave(buff, data) | |||
plt.imsave(buff, data, origin='lower') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
probably should save this with both origins and check that you get the correct output in both cases.
|
||
buff = io.BytesIO() | ||
plt.imsave(buff, data, origin='lower') | ||
for origin in ['lower', 'upper']: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@tacaswell Added test here to test both lower and upper origin settings
Current coverage is 62.11% (diff: 100%)@@ master #7731 diff @@
==========================================
Files 174 174
Lines 56028 56028
Methods 0 0
Messages 0 0
Branches 0 0
==========================================
- Hits 34805 34803 -2
- Misses 21223 21225 +2
Partials 0 0
|
@@ -521,7 +521,8 @@ def contains(self, mouseevent): | |||
|
|||
def write_png(self, fname): | |||
"""Write the image to png file with fname""" | |||
im = self.to_rgba(self._A, bytes=True, norm=True) | |||
im = self.to_rgba(self._A[::-1] if self.origin == 'upper' else self._A, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Isn't this the wrong polarity?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@tacaswell ugh, sorry. First I got mixed up on the origin
polarity, then got my git rebasing all wrong. I think it should look ok now.
1ea49c5
to
92391b5
Compare
92391b5
to
d910788
Compare
Please do not backport this until after 2.0 final. |
Backported to |
Check origin when saving image to PNG
Fixes #7656.
Added an
origin
check and flips the image when appropriate when callingAxesImage.write_png()