Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Fixed imsave() saving incorrect color map#29203

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Closed
gpxxlt wants to merge6 commits intomatplotlib:mainfromgpxxlt:main

Conversation

gpxxlt
Copy link
Contributor

@gpxxltgpxxlt commentedNov 28, 2024
edited by timhoffm
Loading

PR summary

Goal

This pull request is made to address issue#29183. Itcloses#29183.

Implementation

This pull request added anif branch within the functionimsave() in the pathlib/matplotlib/image.py. It is added to handle the case addressed in issue#29183 where inputarr is a vanilla python list.

Testing

One test case is added tolib/matplotlib/tests/test_image.py so there is a round trip fromimread() toimsave(). Test input is designed to be a vanilla python list so that the newly added branch is covered in test suite.

PR checklist

Copy link

@github-actionsgithub-actionsbot left a comment

Choose a reason for hiding this comment

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

Thank you for opening your first PR into Matplotlib!

If you have not heard from us in a week or so, please leave a new comment below and that should bring it to our attention. Most of our reviewers are volunteers and sometimes things fall through the cracks.

You can also join uson gitter for real-time discussion.

For details on testing, writing docs, and our review process, please seethe developer guide

We strive to be a welcoming and open project. Please follow ourCode of Conduct.

@story645
Copy link
Member

Hi, thanks for tackling this! Can you change the title and content to something that describes what this PR is doing? That may help attract reviewers.

@gpxxltgpxxlt changed the titleFixed issue #29183Fixed imsave() saving incorrect color mapNov 29, 2024
@gpxxlt
Copy link
ContributorAuthor

Thank you@story645 for your advice. I am currently editing this pull request and waiting for the newest check to complete.

@gpxxltgpxxlt marked this pull request as ready for reviewNovember 29, 2024 04:00
@@ -28,6 +28,8 @@
Affine2D, BboxBase, Bbox, BboxTransform, BboxTransformTo,
IdentityTransform, TransformedBbox)

import matplotlib.image as mimage
Copy link
Member

Choose a reason for hiding this comment

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

This is a very confusing import in this file... this file ISmatplotlib.image

You should be able to remove themimage. below, asAxesImage is defined in this file and therefore exists in the namespace already.

Copy link
ContributorAuthor

Choose a reason for hiding this comment

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

Hi@ksunden, thank you for pointing out this confusing line. I have made small adjustments in the most recent update. Please let me know if it looks good. Thank you for your time!

@gpxxltgpxxlt requested a review fromksundenDecember 6, 2024 20:30
Comment on lines 1588 to 1600
# This specifically handled list-of-list-of-list
# Produced an image instance using the data from arr and do scaling
if (isinstance(arr, list)):
fig = Figure()
ax = fig.add_axes([0, 0, 1, 1],
aspect='auto',
frameon=False,
xticks=[],
yticks=[])
im = AxesImage(ax, cmap=cmap)
im.set_data(arr)
im._scale_norm(None, vmin, vmax)
arr = im.get_array()
Copy link
Member

Choose a reason for hiding this comment

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

I'm confused: Why do we explicitly scale if the data are lists and not if they are arrays? Shouldn't they be handled equally wrt to scaling whether it's[[1, 2]], [3, 4]] ornp.array([[1, 2]], [3, 4]])? Also, are we sure that this plays well with the following if/else block? Overall, from#29183 (comment) I would have expected nut much more thanarr = np.asarray(arr, dtype=np.uint8) in an appropriate place.

Additionally, noteif separate scaling is needed, it should look more like the scaling in the else block below and not create a whole figure.

Copy link
Member

Choose a reason for hiding this comment

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

I think we can get away with only doingarr = np.asarray(arr) here and dropping theisinstance check in the next line.

@QuLogic
Copy link
Member

Please correct your Git config; it is using the username of your computer at the temporary DNS name of your computer for the email address. Neitherguyuepeng@air-model-g.wifi.local.cmu.edu norguyuepeng@MacBook-Air-Model-G.local seem to be valid emails.

Comment on lines +1587 to +1590

if (isinstance(arr, list)):
arr = np.asarray(arr, dtype=np.uint8)

Copy link
Member

Choose a reason for hiding this comment

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

Let's move the format coersion above the origin handling. While the reversal ([::-1]) also works for lists, it's more efficient and easier to understand if we ensure that we have the array already there.

Alsoarr = np.asanyarray(array) should be enough.

  • asanyarray() instead ofasarray() Passing through array subclasses should be ok - we currently do that as well.
  • let's not do dtype conversion in this PR - we currently also don't do this for arrays. The user is responsible for passing reasonable types. Any change to that would be a separate topic.

tacaswell reacted with thumbs up emoji
@@ -5869,6 +5869,7 @@ def imshow(self, X, cmap=None, norm=None, *, aspect=None,
`~matplotlib.pyplot.imshow` expects RGB images adopting the straight
(unassociated) alpha representation.
"""

Copy link
Member

Choose a reason for hiding this comment

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

Suggested change

@@ -1093,6 +1094,7 @@ def set_data(self, x, y, A):
"""
Set the grid for the pixel centers, and the pixel values.


Copy link
Member

Choose a reason for hiding this comment

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

Suggested change

@tacaswelltacaswell added this to thev3.11.0 milestoneDec 18, 2024
@timhoffm
Copy link
Member

@gpxxlt Do you plan to continue with this?

@QuLogic
Copy link
Member

This was replaced by#29931.

NGWi reacted with thumbs up emoji

@github-project-automationgithub-project-automationbot moved this fromNeeds review toWaiting for author inFirst Time ContributorsApr 22, 2025
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers

@tacaswelltacaswelltacaswell left review comments

@timhoffmtimhoffmtimhoffm left review comments

@github-actionsgithub-actions[bot]github-actions[bot] left review comments

@ksundenksundenAwaiting requested review from ksunden

Assignees
No one assigned
Projects
Status: Waiting for author
Milestone
v3.11.0
Development

Successfully merging this pull request may close these issues.

[Bug]: I give an RGB image to imsave but I don't have the right color map!
7 participants
@gpxxlt@story645@QuLogic@timhoffm@tacaswell@ksunden@rcomer

[8]ページ先頭

©2009-2025 Movatter.jp