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

Appearance settings

Commit 47c084a

Browse filesBrowse files
committed
DOC
1 parent feda832 commit 47c084a
Copy full SHA for 47c084a

File tree

Expand file treeCollapse file tree

1 file changed

+21
-22
lines changed
Filter options
Expand file treeCollapse file tree

1 file changed

+21
-22
lines changed

‎galleries/examples/images_contours_and_fields/image_antialiasing.py

Copy file name to clipboardExpand all lines: galleries/examples/images_contours_and_fields/image_antialiasing.py
+21-22Lines changed: 21 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@
8080
# The following images are down-sampled from 450 data pixels to approximately
8181
# 125 pixels or 250 pixels (depending on your display).
8282
# The underlying image has alternating +1, -1 stripes on the left side, and
83-
# a varying wavenumber (`chirp <https://en.wikipedia.org/wiki/Chirp>`_) pattern
83+
# a varying wavelength (`chirp <https://en.wikipedia.org/wiki/Chirp>`_) pattern
8484
# in the rest of the image. If we zoom, we can see this detail without any
8585
# down-sampling:
8686

@@ -146,16 +146,16 @@
146146

147147
fig, ax = plt.subplots(figsize=(6.8, 6.8))
148148
ax.imshow(alarge, interpolation='nearest', cmap='grey')
149-
ax.set_title("upsampled by factor a 1.17, interpolation='nearest'")
149+
ax.set_title("up-sampled by factor a 1.17, interpolation='nearest'")
150150

151151
# %%
152-
# Better antialiasing algorithms can reduce this effect:
152+
# Better anti-aliasing algorithms can reduce this effect:
153153
fig, ax = plt.subplots(figsize=(6.8, 6.8))
154154
ax.imshow(alarge, interpolation='antialiased', cmap='grey')
155-
ax.set_title("upsampled by factor a 1.17, interpolation='antialiased'")
155+
ax.set_title("up-sampled by factor a 1.17, interpolation='antialiased'")
156156

157157
# %%
158-
# Apart from the default 'hanning' antialiasing, `~.Axes.imshow` supports a
158+
# Apart from the default 'hanning' anti-aliasing, `~.Axes.imshow` supports a
159159
# number of different interpolation algorithms, which may work better or
160160
# worse depending on the underlying data.
161161
fig, axs = plt.subplots(1, 2, figsize=(7, 4), layout='constrained')
@@ -164,19 +164,18 @@
164164
ax.set_title(f"interpolation='{interp}'")
165165

166166
# %%
167-
# A final example shows the desirability of performing the anti-aliasing at
168-
# the RGBA stage when using non-trivial interpolation kernels. In the following,
169-
# the data in the upper 100 rows is exactly
170-
# 0.0, and data in the inner circle is exactly 2.0. If we perform the
171-
# *interpolation_stage* in 'data' space and use an anti-aliasing filter (first
172-
# panel), then floating point imprecision makes some of the data values just a
173-
# bit less than zero or a bit more than 2.0, and they get assigned the under-
174-
# or over- colors. This can be avoided if you do not use an anti-aliasing filter
175-
# (*interpolation* set set to 'nearest'), however, that makes the part of the
176-
# data susceptible to Moiré patterns much worse (second panel). Therefore, we
177-
# recommend the default *interpolation* of 'hanning'/'antialiased', and
178-
# *interpolation_stage* of 'rgba'/'antialiased' for most down-sampling
179-
# situations (last panel).
167+
# A final example shows the desirability of performing the anti-aliasing at the
168+
# RGBA stage when using non-trivial interpolation kernels. In the following,
169+
# the data in the upper 100 rows is exactly 0.0, and data in the inner circle
170+
# is exactly 2.0. If we perform the *interpolation_stage* in 'data' space and
171+
# use an anti-aliasing filter (first panel), then floating point imprecision
172+
# makes some of the data values just a bit less than zero or a bit more than
173+
# 2.0, and they get assigned the under- or over- colors. This can be avoided if
174+
# you do not use an anti-aliasing filter (*interpolation* set set to
175+
# 'nearest'), however, that makes the part of the data susceptible to Moiré
176+
# patterns much worse (second panel). Therefore, we recommend the default
177+
# *interpolation* of 'hanning'/'antialiased', and *interpolation_stage* of
178+
# 'rgba'/'antialiased' for most down-sampling situations (last panel).
180179

181180
a = alarge + 1
182181
cmap = plt.get_cmap('RdBu_r')
@@ -199,7 +198,7 @@
199198
# Up-sampling
200199
# ===========
201200
#
202-
# If we upsample, then we can represent a data pixel by many image or screen pixels.
201+
# If we up-sample, then we can represent a data pixel by many image or screen pixels.
203202
# In the following example, we greatly over-sample the small data matrix.
204203

205204
np.random.seed(19680801+9)
@@ -239,12 +238,12 @@
239238
# aware that some vector image viewers may smooth image pixels.
240239
#
241240
# The second method is to exactly match the size of your axes to the size of
242-
# your data. in the following, the figure is exactly 2 inches by 2 inches, and
243-
# the dpi is 200, so the 400x400 data is not resampled at all. If you download
241+
# your data. In the following, the figure is exactly 2 inches by 2 inches, and
242+
# the dpi is 200, then the 400x400 data is not resampled at all. If you download
244243
# this image and zoom in an image viewer you should see the individual stripes
245244
# on the left hand side.
246245

247-
fig = plt.figure(figsize=(2, 2))
246+
fig = plt.figure(figsize=(2, 2), dpi=200)
248247
ax = fig.add_axes([0, 0, 1, 1])
249248
ax.imshow(aa[:400, :400], cmap='RdBu_r', interpolation='nearest')
250249
plt.show()

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.