-
-
Notifications
You must be signed in to change notification settings - Fork 7.9k
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 our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Update image tutorial. #23889
Conversation
tutorials/introductory/images.py
Outdated
# 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. |
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.
# 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. | |
# We use Pillow to open an image (with `PIL.Image.open`), and | |
# immediately convert the `PIL.Image.Image` object into an 8-bit | |
# (``dtype=uint8``) numpy array. |
And this should maybe be before the code instead of and here we go
tutorials/introductory/images.py
Outdated
@@ -205,20 +199,19 @@ | |||
# | |||
# You can specify the clim in the call to ``plot``. |
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 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?
tutorials/introductory/images.py
Outdated
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') |
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.
I think this should stay OO since that's what we usually recommend, but with an fig, (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?
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.
I just got rid of the subplots, keeping only the second plot seems good enough.
tutorials/introductory/images.py
Outdated
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 |
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.
# Here we have the default interpolation ("nearest"), since we did not | |
# Here we use the default interpolation ("nearest"), since we did not |
tutorials/introductory/images.py
Outdated
@@ -205,20 +199,19 @@ | |||
# | |||
# You can specify the clim in the call to ``plot``. |
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.
And its
imshownot
plot`, we are talking about.
Then maybe:
# You can specify the clim in the call to ``plot``. | |
# You can specify the colormap 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 |
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.
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).
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.
I merged yours.
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).
- 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
pytest
passes).flake8-docstrings
and runflake8 --docstring-convention=all
).Documentation
doc/users/next_whats_new/
(follow instructions in README.rst there).doc/api/next_api_changes/
(follow instructions in README.rst there).