Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit cdb81b6

Browse files
authored
Merge pull request #15642 from anntzer/uninterpolate
Remove interpolation="nearest" from most examples.
2 parents ab932d1 + c6e185d commit cdb81b6

19 files changed

+45
-64
lines changed

examples/axes_grid1/demo_axes_divider.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ def get_demo_image():
2121
def demo_simple_image(ax):
2222
Z, extent = get_demo_image()
2323

24-
im = ax.imshow(Z, extent=extent, interpolation="nearest")
24+
im = ax.imshow(Z, extent=extent)
2525
cb = plt.colorbar(im)
2626
plt.setp(cb.ax.get_yticklabels(), visible=False)
2727

@@ -60,7 +60,7 @@ def demo_locatable_axes_hard(fig):
6060

6161
Z, extent = get_demo_image()
6262

63-
im = ax.imshow(Z, extent=extent, interpolation="nearest")
63+
im = ax.imshow(Z, extent=extent)
6464
plt.colorbar(im, cax=ax_cb)
6565
plt.setp(ax_cb.get_yticklabels(), visible=False)
6666

@@ -75,7 +75,7 @@ def demo_locatable_axes_easy(ax):
7575
fig.add_axes(ax_cb)
7676

7777
Z, extent = get_demo_image()
78-
im = ax.imshow(Z, extent=extent, interpolation="nearest")
78+
im = ax.imshow(Z, extent=extent)
7979

8080
plt.colorbar(im, cax=ax_cb)
8181
ax_cb.yaxis.tick_right()
@@ -92,8 +92,8 @@ def demo_images_side_by_side(ax):
9292
fig1 = ax.get_figure()
9393
fig1.add_axes(ax2)
9494

95-
ax.imshow(Z, extent=extent, interpolation="nearest")
96-
ax2.imshow(Z, extent=extent, interpolation="nearest")
95+
ax.imshow(Z, extent=extent)
96+
ax2.imshow(Z, extent=extent)
9797
ax2.yaxis.set_tick_params(labelleft=False)
9898

9999

examples/axes_grid1/demo_axes_grid.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ def demo_simple_grid(fig):
3434
)
3535
Z, extent = get_demo_image()
3636
for ax in grid:
37-
ax.imshow(Z, extent=extent, interpolation="nearest")
37+
ax.imshow(Z, extent=extent)
3838
# This only affects axes in first column and second row as share_all=False.
3939
grid.axes_llc.set_xticks([-2, 0, 2])
4040
grid.axes_llc.set_yticks([-2, 0, 2])
@@ -55,7 +55,7 @@ def demo_grid_with_single_cbar(fig):
5555

5656
Z, extent = get_demo_image()
5757
for ax in grid:
58-
im = ax.imshow(Z, extent=extent, interpolation="nearest")
58+
im = ax.imshow(Z, extent=extent)
5959
grid.cbar_axes[0].colorbar(im)
6060

6161
for cax in grid.cbar_axes:
@@ -82,7 +82,7 @@ def demo_grid_with_each_cbar(fig):
8282
)
8383
Z, extent = get_demo_image()
8484
for ax, cax in zip(grid, grid.cbar_axes):
85-
im = ax.imshow(Z, extent=extent, interpolation="nearest")
85+
im = ax.imshow(Z, extent=extent)
8686
cax.colorbar(im)
8787
cax.toggle_label(False)
8888

@@ -110,8 +110,7 @@ def demo_grid_with_each_cbar_labelled(fig):
110110
# Use a different colorbar range every time
111111
limits = ((0, 1), (-2, 2), (-1.7, 1.4), (-1.5, 1))
112112
for ax, cax, vlim in zip(grid, grid.cbar_axes, limits):
113-
im = ax.imshow(Z, extent=extent, interpolation="nearest",
114-
vmin=vlim[0], vmax=vlim[1])
113+
im = ax.imshow(Z, extent=extent, vmin=vlim[0], vmax=vlim[1])
115114
cb = cax.colorbar(im)
116115
cb.set_ticks((vlim[0], vlim[1]))
117116

examples/axes_grid1/demo_axes_grid2.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,7 @@ def add_inner_title(ax, title, loc, **kwargs):
5858
)
5959

6060
for i, (ax, z) in enumerate(zip(grid, ZS)):
61-
im = ax.imshow(
62-
z, origin="lower", extent=extent, interpolation="nearest")
61+
im = ax.imshow(z, origin="lower", extent=extent)
6362
cb = ax.cax.colorbar(im)
6463
# Changing the colorbar ticks
6564
if i in [1, 2]:
@@ -100,9 +99,7 @@ def add_inner_title(ax, title, loc, **kwargs):
10099
norm = matplotlib.colors.Normalize(vmax=vmax, vmin=vmin)
101100

102101
for ax, z in zip(grid2, ZS):
103-
im = ax.imshow(z, norm=norm,
104-
origin="lower", extent=extent,
105-
interpolation="nearest")
102+
im = ax.imshow(z, norm=norm, origin="lower", extent=extent)
106103

107104
# With cbar_mode="single", cax attribute of all axes are identical.
108105
ax.cax.colorbar(im)

examples/axes_grid1/demo_axes_hbox_divider.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,8 @@ def make_heights_equal(fig, rect, ax1, ax2, pad):
3434
arr2 = np.arange(20).reshape((5, 4))
3535

3636
fig, (ax1, ax2) = plt.subplots(1, 2)
37-
ax1.imshow(arr1, interpolation="nearest")
38-
ax2.imshow(arr2, interpolation="nearest")
37+
ax1.imshow(arr1)
38+
ax2.imshow(arr2)
3939

4040
rect = 111 # subplot param for combined axes
4141
make_heights_equal(fig, rect, ax1, ax2, pad=0.5) # pad in inches

examples/axes_grid1/demo_axes_rgb.py

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -52,23 +52,18 @@ def demo_rgb():
5252

5353
r, g, b = get_rgb()
5454
im_r, im_g, im_b, im_rgb = make_cube(r, g, b)
55-
kwargs = dict(origin="lower", interpolation="nearest")
56-
ax.imshow(im_rgb, **kwargs)
57-
ax_r.imshow(im_r, **kwargs)
58-
ax_g.imshow(im_g, **kwargs)
59-
ax_b.imshow(im_b, **kwargs)
55+
ax.imshow(im_rgb)
56+
ax_r.imshow(im_r)
57+
ax_g.imshow(im_g)
58+
ax_b.imshow(im_b)
6059

6160

6261
def demo_rgb2():
6362
fig = plt.figure()
6463
ax = RGBAxes(fig, [0.1, 0.1, 0.8, 0.8], pad=0.0)
6564

6665
r, g, b = get_rgb()
67-
kwargs = dict(origin="lower", interpolation="nearest")
68-
ax.imshow_rgb(r, g, b, **kwargs)
69-
70-
ax.RGB.set_xlim(0., 9.5)
71-
ax.RGB.set_ylim(0.9, 10.6)
66+
ax.imshow_rgb(r, g, b)
7267

7368
for ax1 in [ax.RGB, ax.R, ax.G, ax.B]:
7469
ax1.tick_params(axis='both', direction='in')

examples/axes_grid1/demo_colorbar_of_inset_axes.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,7 @@ def get_demo_image():
2828

2929

3030
axins = zoomed_inset_axes(ax, zoom=2, loc='upper left')
31-
im = axins.imshow(Z, extent=extent, interpolation="nearest",
32-
origin="lower")
31+
im = axins.imshow(Z, extent=extent, origin="lower")
3332

3433
plt.xticks(visible=False)
3534
plt.yticks(visible=False)

examples/axes_grid1/demo_edge_colorbar.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,14 @@
66
This example shows how to use one common colorbar for each row or column
77
of an image grid.
88
"""
9+
910
import matplotlib.pyplot as plt
1011
from mpl_toolkits.axes_grid1 import AxesGrid
1112

1213

14+
plt.rcParams["mpl_toolkits.legacy_colorbar"] = False
15+
16+
1317
def get_demo_image():
1418
import numpy as np
1519
from matplotlib.cbook import get_sample_data
@@ -38,8 +42,7 @@ def demo_bottom_cbar(fig):
3842
Z, extent = get_demo_image()
3943
cmaps = [plt.get_cmap("autumn"), plt.get_cmap("summer")]
4044
for i in range(4):
41-
im = grid[i].imshow(Z, extent=extent, interpolation="nearest",
42-
cmap=cmaps[i//2])
45+
im = grid[i].imshow(Z, extent=extent, cmap=cmaps[i//2])
4346
if i % 2:
4447
grid.cbar_axes[i//2].colorbar(im)
4548

@@ -69,8 +72,7 @@ def demo_right_cbar(fig):
6972
Z, extent = get_demo_image()
7073
cmaps = [plt.get_cmap("spring"), plt.get_cmap("winter")]
7174
for i in range(4):
72-
im = grid[i].imshow(Z, extent=extent, interpolation="nearest",
73-
cmap=cmaps[i//2])
75+
im = grid[i].imshow(Z, extent=extent, cmap=cmaps[i//2])
7476
if i % 2:
7577
grid.cbar_axes[i//2].colorbar(im)
7678

examples/axes_grid1/inset_locator_demo2.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -61,13 +61,11 @@ def add_sizebar(ax, size):
6161
Z2[30:30 + ny, 30:30 + nx] = Z
6262

6363
# extent = [-3, 4, -4, 3]
64-
ax2.imshow(Z2, extent=extent, interpolation="nearest",
65-
origin="lower")
64+
ax2.imshow(Z2, extent=extent, origin="lower")
6665

6766

6867
axins2 = zoomed_inset_axes(ax2, 6, loc=1) # zoom = 6
69-
axins2.imshow(Z2, extent=extent, interpolation="nearest",
70-
origin="lower")
68+
axins2.imshow(Z2, extent=extent, origin="lower")
7169

7270
# sub region of the original image
7371
x1, x2, y1, y2 = -1.5, -0.9, -2.5, -1.9

examples/axes_grid1/simple_axesgrid2.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ def get_demo_image():
3434
im3 = Z[:, 10:]
3535
vmin, vmax = Z.min(), Z.max()
3636
for ax, im in zip(grid, [im1, im2, im3]):
37-
ax.imshow(im, origin="lower", vmin=vmin, vmax=vmax,
38-
interpolation="nearest")
37+
ax.imshow(im, origin="lower", vmin=vmin, vmax=vmax)
3938

4039
plt.show()

examples/axes_grid1/simple_rgb.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,7 @@ def get_rgb():
3535
ax = RGBAxes(fig, [0.1, 0.1, 0.8, 0.8])
3636

3737
r, g, b = get_rgb()
38-
kwargs = dict(origin="lower", interpolation="nearest")
39-
ax.imshow_rgb(r, g, b, **kwargs)
38+
ax.imshow_rgb(r, g, b, origin="lower")
4039

4140
ax.RGB.set_xlim(0., 9.5)
4241
ax.RGB.set_ylim(0.9, 10.6)

examples/axisartist/demo_curvelinear_grid2.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,7 @@ def inv_tr(x, y):
5757
fig.add_subplot(ax1)
5858

5959
ax1.imshow(np.arange(25).reshape(5, 5),
60-
vmax=50, cmap=plt.cm.gray_r,
61-
interpolation="nearest",
62-
origin="lower")
60+
vmax=50, cmap=plt.cm.gray_r, origin="lower")
6361

6462

6563
if __name__ == "__main__":

examples/color/custom_cmap.py

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -92,10 +92,9 @@
9292
fig.subplots_adjust(left=0.02, bottom=0.06, right=0.95, top=0.94, wspace=0.05)
9393
for n_bin, ax in zip(n_bins, axs.ravel()):
9494
# Create the colormap
95-
cm = LinearSegmentedColormap.from_list(
96-
cmap_name, colors, N=n_bin)
95+
cm = LinearSegmentedColormap.from_list(cmap_name, colors, N=n_bin)
9796
# Fewer bins will result in "coarser" colomap interpolation
98-
im = ax.imshow(Z, interpolation='nearest', origin='lower', cmap=cm)
97+
im = ax.imshow(Z, origin='lower', cmap=cm)
9998
ax.set_title("N bins: %s" % n_bin)
10099
fig.colorbar(im, ax=ax)
101100

@@ -188,11 +187,11 @@
188187

189188
# Make 4 subplots:
190189

191-
im1 = axs[0, 0].imshow(Z, interpolation='nearest', cmap=blue_red1)
190+
im1 = axs[0, 0].imshow(Z, cmap=blue_red1)
192191
fig.colorbar(im1, ax=axs[0, 0])
193192

194193
cmap = plt.get_cmap('BlueRed2')
195-
im2 = axs[1, 0].imshow(Z, interpolation='nearest', cmap=cmap)
194+
im2 = axs[1, 0].imshow(Z, cmap=cmap)
196195
fig.colorbar(im2, ax=axs[1, 0])
197196

198197
# Now we will set the third cmap as the default. One would
@@ -201,7 +200,7 @@
201200

202201
plt.rcParams['image.cmap'] = 'BlueRed3'
203202

204-
im3 = axs[0, 1].imshow(Z, interpolation='nearest')
203+
im3 = axs[0, 1].imshow(Z)
205204
fig.colorbar(im3, ax=axs[0, 1])
206205
axs[0, 1].set_title("Alpha = 1")
207206

@@ -215,7 +214,7 @@
215214
# Draw a line with low zorder so it will be behind the image.
216215
axs[1, 1].plot([0, 10 * np.pi], [0, 20 * np.pi], color='c', lw=20, zorder=-1)
217216

218-
im4 = axs[1, 1].imshow(Z, interpolation='nearest')
217+
im4 = axs[1, 1].imshow(Z)
219218
fig.colorbar(im4, ax=axs[1, 1])
220219

221220
# Here it is: changing the colormap for the current image and its

examples/images_contours_and_fields/image_zcoord.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
X = 10*np.random.rand(5, 3)
2020

2121
fig, ax = plt.subplots()
22-
ax.imshow(X, interpolation='nearest')
22+
ax.imshow(X)
2323

2424
numrows, numcols = X.shape
2525

examples/images_contours_and_fields/plot_streamplot.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,7 @@
6565
ax4.streamplot(X, Y, U, V, color='r')
6666
ax4.set_title('Streamplot with Masking')
6767

68-
ax4.imshow(~mask, extent=(-w, w, -w, w), alpha=0.5,
69-
interpolation='nearest', cmap='gray', aspect='auto')
68+
ax4.imshow(~mask, extent=(-w, w, -w, w), alpha=0.5, cmap='gray', aspect='auto')
7069
ax4.set_aspect('equal')
7170

7271
plt.tight_layout()

examples/pyplots/whats_new_99_axes_grid.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,7 @@ def get_rgb():
4242
ax = RGBAxes(fig, [0.1, 0.1, 0.8, 0.8])
4343

4444
r, g, b = get_rgb()
45-
kwargs = dict(origin="lower", interpolation="nearest")
46-
ax.imshow_rgb(r, g, b, **kwargs)
45+
ax.imshow_rgb(r, g, b, origin="lower")
4746

4847
ax.RGB.set_xlim(0., 9.5)
4948
ax.RGB.set_ylim(0.9, 10.6)

examples/subplots_axes_and_figures/zoom_inset_axes.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,11 @@ def get_demo_image():
2727
ny, nx = Z.shape
2828
Z2[30:30 + ny, 30:30 + nx] = Z
2929

30-
ax.imshow(Z2, extent=extent, interpolation="nearest",
31-
origin="lower")
30+
ax.imshow(Z2, extent=extent, origin="lower")
3231

3332
# inset axes....
3433
axins = ax.inset_axes([0.5, 0.5, 0.47, 0.47])
35-
axins.imshow(Z2, extent=extent, interpolation="nearest",
36-
origin="lower")
34+
axins.imshow(Z2, extent=extent, origin="lower")
3735
# sub region of the original image
3836
x1, x2, y1, y2 = -1.5, -0.9, -2.5, -1.9
3937
axins.set_xlim(x1, x2)

examples/ticks_and_spines/colorbar_tick_labelling_demo.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020

2121
data = np.clip(randn(250, 250), -1, 1)
2222

23-
cax = ax.imshow(data, interpolation='nearest', cmap=cm.coolwarm)
23+
cax = ax.imshow(data, cmap=cm.coolwarm)
2424
ax.set_title('Gaussian noise with vertical colorbar')
2525

2626
# Add colorbar, make sure to specify tick locations to match desired ticklabels
@@ -34,7 +34,7 @@
3434

3535
data = np.clip(randn(250, 250), -1, 1)
3636

37-
cax = ax.imshow(data, interpolation='nearest', cmap=cm.afmhot)
37+
cax = ax.imshow(data, cmap=cm.afmhot)
3838
ax.set_title('Gaussian noise with horizontal colorbar')
3939

4040
cbar = fig.colorbar(cax, ticks=[-1, 0, 1], orientation='horizontal')

examples/ticks_and_spines/spines_dropped.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
fig, ax = plt.subplots()
1515

1616
image = np.random.uniform(size=(10, 10))
17-
ax.imshow(image, cmap=plt.cm.gray, interpolation='nearest')
17+
ax.imshow(image, cmap=plt.cm.gray)
1818
ax.set_title('dropped spines')
1919

2020
# Move left and bottom spines outward by 10 points

examples/user_interfaces/embedding_in_wx3_sgskip.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ def init_plot_data(self):
6363
y = np.arange(100.0) * 2 * np.pi / 50.0
6464
self.x, self.y = np.meshgrid(x, y)
6565
z = np.sin(self.x) + np.cos(self.y)
66-
self.im = a.imshow(z, cmap=cm.RdBu) # , interpolation='nearest')
66+
self.im = a.imshow(z, cmap=cm.RdBu)
6767

6868
zmax = np.max(z) - ERR_TOL
6969
ymax_i, xmax_i = np.nonzero(z >= zmax)

0 commit comments

Comments
 (0)