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

Update image tutorial.#23889

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

Merged
timhoffm merged 1 commit intomatplotlib:mainfromanntzer:imtut
Sep 15, 2022
Merged

Update image tutorial.#23889

timhoffm merged 1 commit intomatplotlib:mainfromanntzer:imtut
Sep 15, 2022

Conversation

anntzer
Copy link
Contributor

  • Use Pillow to load the image rather than the discouraged plt.imread.
  • Remove discussion about rescaling to 0-1 as dropping the use of plt.imread also gets rid of that (not so nice) behavior. Also drop the lengthy discussion about uint8 and float32, which seems out of place here (if anything it should be in the Pillow docs). Make corresponding fixes to code to use 0-255 instead of 0-1.
  • Fix subplot management to go full pyplot (the local switch to OO-style is a bit weird).
  • Fix interpolation discussion as the default is now "nearest" (actually it's now "antialiased", but let's sweep that under the rug for this tutorial for now).

See#22790. Probably the tutorial could be further improved, but let's consider this a small step in that direction.

PR Summary

PR Checklist

Tests and Styling

  • Has pytest style unit tests (andpytest passes).
  • IsFlake 8 compliant (installflake8-docstrings and runflake8 --docstring-convention=all).

Documentation

  • New features are documented, with examples if plot related.
  • New features have an entry indoc/users/next_whats_new/ (follow instructions in README.rst there).
  • API changes documented indoc/api/next_api_changes/ (follow instructions in README.rst there).
  • Documentation is sphinx and numpydoc compliant (the docs shouldbuild without error).

Comment on lines 82 to 84
# Here, we used Pillow to open an image (with `PIL.Image.open`), and
# immediately converted the `PIL.Image.Image` object into a 8-bit
# (``dtype=uint8``) numpy array.
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
#Here, we used Pillow to open an image (with `PIL.Image.open`), and
# immediatelyconverted the `PIL.Image.Image` object intoa 8-bit
# (``dtype=uint8``) numpy array.
#We use Pillow to open an image (with `PIL.Image.open`), and
# immediatelyconvert the `PIL.Image.Image` object intoan 8-bit
# (``dtype=uint8``) numpy array.

And this should maybe be before the code instead ofand here we go

timhoffm reacted with thumbs up emoji
@@ -205,20 +199,19 @@
#
# You can specify the clim in the call to ``plot``.
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
# You can specify the clim in the call to ``plot``.
# You can specify the clim(colormap limits)in the call to ``plot``.

I think clim is colormap limits?

Comment on lines 213 to 214
ax = fig.add_subplot(1, 2, 1)
plt.subplot(1, 2, 1)
imgplot = plt.imshow(lum_img)
ax.set_title('Before')
plt.colorbar(ticks=[0.1, 0.3, 0.5, 0.7],orientation='horizontal')
ax = fig.add_subplot(1, 2, 2)
plt.title('Before')
plt.colorbar(orientation='horizontal')
plt.subplot(1, 2, 2)
imgplot = plt.imshow(lum_img)
imgplot.set_clim(0.0, 0.7)
ax.set_title('After')
plt.colorbar(ticks=[0.1, 0.3, 0.5, 0.7],orientation='horizontal')
imgplot.set_clim(0, 175)
plt.title('After')
plt.colorbar(orientation='horizontal')
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 this should stay OO since that's what we usually recommend, but with anfig, (ax1m ax2) = plt.subplots( ncols=2)

all the other examples are pyplot 'cause it's only a line of code and I think that's a fairly clear distinction?

Copy link
ContributorAuthor

Choose a reason for hiding this comment

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

I just got rid of the subplots, keeping only the second plot seems good enough.

img = Image.open('../../doc/_static/stinkbug.png')
img.thumbnail((64, 64), Image.ANTIALIAS) # resizes image in-place
imgplot = plt.imshow(img)

###############################################################################
# Here we have the default interpolation, bilinear, since we did not
# Here we have the default interpolation ("nearest"), since we did not
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
# Here wehave the default interpolation ("nearest"), since we did not
# Here weuse the default interpolation ("nearest"), since we did not

@tacaswelltacaswell added this to thev3.7.0 milestoneSep 14, 2022
@@ -205,20 +199,19 @@
#
# You can specify the clim in the call to ``plot``.
Copy link
Member

Choose a reason for hiding this comment

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

And itsimshownotplot`, we are talking about.

Then maybe:

Suggested change
# You can specify theclim in the call to ``plot``.
# You can specify thecolormap limits using ``imshow(..., clim=...)``.

Sorry, to comment on code you're not responsible for, but this is too glaringly wrong.

@@ -242,19 +235,17 @@
# We'll use the Pillow library that we used to load the image also to resize
# the image.

from PIL import Image

img = Image.open('../../doc/_static/stinkbug.png')
img.thumbnail((64, 64), Image.ANTIALIAS) # resizes image in-place
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
img.thumbnail((64,64),Image.ANTIALIAS)# resizes image in-place
img.thumbnail((64,64))# resizes image in-place

May just as well put that here instead of#23881 (which can be closed then).

Copy link
ContributorAuthor

Choose a reason for hiding this comment

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

I merged yours.

@anntzer
Copy link
ContributorAuthor

Thanks, handled all comments (got rid of the subplots, as noted re:@story645's suggestion).

- Use Pillow to load the image rather than the discouraged plt.imread.- Remove discussion about rescaling to 0-1 as dropping the use of  plt.imread also gets rid of that (not so nice) behavior.  Also drop  the lengthy discussion about uint8 and float32, which seems out of  place here (if anything it should be in the Pillow docs).  Make  corresponding fixes to code to use 0-255 instead of 0-1.- Fix subplot management to go full pyplot (the local switch to  OO-style is a bit weird).- Fix interpolation discussion as the default is now "nearest" (actually  it's now "antialiased", but let's sweep that under the rug for this  tutorial for now).
@timhoffmtimhoffm merged commit2ff4dc9 intomatplotlib:mainSep 15, 2022
@anntzeranntzer deleted the imtut branchSeptember 15, 2022 12:36
melissawm pushed a commit to melissawm/matplotlib that referenced this pull requestDec 19, 2022
- Use Pillow to load the image rather than the discouraged plt.imread.- Remove discussion about rescaling to 0-1 as dropping the use of  plt.imread also gets rid of that (not so nice) behavior.  Also drop  the lengthy discussion about uint8 and float32, which seems out of  place here (if anything it should be in the Pillow docs).  Make  corresponding fixes to code to use 0-255 instead of 0-1.- Fix subplot management to go full pyplot (the local switch to  OO-style is a bit weird).- Fix interpolation discussion as the default is now "nearest" (actually  it's now "antialiased", but let's sweep that under the rug for this  tutorial for now).
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers

@story645story645story645 left review comments

@oscargusoscargusoscargus left review comments

@timhoffmtimhoffmtimhoffm approved these changes

Assignees
No one assigned
Projects
None yet
Milestone
v3.7.0
Development

Successfully merging this pull request may close these issues.

5 participants
@anntzer@story645@timhoffm@oscargus@tacaswell

[8]ページ先頭

©2009-2025 Movatter.jp