diff --git a/examples/specialty_plots/leftventricle_bulleye.py b/examples/specialty_plots/leftventricle_bulleye.py index 834d158f1ac0..1d98f5e8bfa0 100644 --- a/examples/specialty_plots/leftventricle_bulleye.py +++ b/examples/specialty_plots/leftventricle_bulleye.py @@ -79,7 +79,7 @@ def bullseye_plot(ax, data, seg_bold=None, cmap=None, norm=None): theta0 = theta[i * 128:i * 128 + 128] + np.deg2rad(60) theta0 = np.repeat(theta0[:, np.newaxis], 2, axis=1) z = np.ones((128, 2)) * data[i] - ax.pcolormesh(theta0, r0, z, cmap=cmap, norm=norm) + ax.pcolormesh(theta0, r0, z, cmap=cmap, norm=norm, shading='auto') if i + 1 in seg_bold: ax.plot(theta0, r0, '-k', lw=linewidth + 2) ax.plot(theta0[0], [r[2], r[3]], '-k', lw=linewidth + 1) @@ -93,7 +93,7 @@ def bullseye_plot(ax, data, seg_bold=None, cmap=None, norm=None): theta0 = theta[i * 128:i * 128 + 128] + np.deg2rad(60) theta0 = np.repeat(theta0[:, np.newaxis], 2, axis=1) z = np.ones((128, 2)) * data[i + 6] - ax.pcolormesh(theta0, r0, z, cmap=cmap, norm=norm) + ax.pcolormesh(theta0, r0, z, cmap=cmap, norm=norm, shading='auto') if i + 7 in seg_bold: ax.plot(theta0, r0, '-k', lw=linewidth + 2) ax.plot(theta0[0], [r[1], r[2]], '-k', lw=linewidth + 1) @@ -107,7 +107,7 @@ def bullseye_plot(ax, data, seg_bold=None, cmap=None, norm=None): theta0 = theta[i * 192:i * 192 + 192] + np.deg2rad(45) theta0 = np.repeat(theta0[:, np.newaxis], 2, axis=1) z = np.ones((192, 2)) * data[i + 12] - ax.pcolormesh(theta0, r0, z, cmap=cmap, norm=norm) + ax.pcolormesh(theta0, r0, z, cmap=cmap, norm=norm, shading='auto') if i + 13 in seg_bold: ax.plot(theta0, r0, '-k', lw=linewidth + 2) ax.plot(theta0[0], [r[0], r[1]], '-k', lw=linewidth + 1) @@ -119,7 +119,7 @@ def bullseye_plot(ax, data, seg_bold=None, cmap=None, norm=None): r0 = np.repeat(r0[:, np.newaxis], theta.size, axis=1).T theta0 = np.repeat(theta[:, np.newaxis], 2, axis=1) z = np.ones((theta.size, 2)) * data[16] - ax.pcolormesh(theta0, r0, z, cmap=cmap, norm=norm) + ax.pcolormesh(theta0, r0, z, cmap=cmap, norm=norm, shading='auto') if 17 in seg_bold: ax.plot(theta0, r0, '-k', lw=linewidth + 2) diff --git a/examples/subplots_axes_and_figures/axes_margins.py b/examples/subplots_axes_and_figures/axes_margins.py index fb8eba65fa89..41347f715d4d 100644 --- a/examples/subplots_axes_and_figures/axes_margins.py +++ b/examples/subplots_axes_and_figures/axes_margins.py @@ -62,7 +62,7 @@ def f(t): ax2.use_sticky_edges = False for ax, status in zip((ax1, ax2), ('Is', 'Is Not')): - cells = ax.pcolor(x, y, x+y, cmap='inferno') # sticky + cells = ax.pcolor(x, y, x+y, cmap='inferno', shading='auto') # sticky ax.add_patch( plt.Polygon(poly_coords, color='forestgreen', alpha=0.5) ) # not sticky diff --git a/examples/userdemo/colormap_normalizations_bounds.py b/examples/userdemo/colormap_normalizations_bounds.py deleted file mode 100644 index d37113b9dd37..000000000000 --- a/examples/userdemo/colormap_normalizations_bounds.py +++ /dev/null @@ -1,44 +0,0 @@ -""" -============================== -Colormap Normalizations Bounds -============================== - -Demonstration of using norm to map colormaps onto data in non-linear ways. -""" - -import numpy as np -import matplotlib.pyplot as plt -import matplotlib.colors as colors - -N = 100 -X, Y = np.mgrid[-3:3:complex(0, N), -2:2:complex(0, N)] -Z1 = np.exp(-X**2 - Y**2) -Z2 = np.exp(-(X - 1)**2 - (Y - 1)**2) -Z = (Z1 - Z2) * 2 - -''' -BoundaryNorm: For this one you provide the boundaries for your colors, -and the Norm puts the first color in between the first pair, the -second color between the second pair, etc. -''' - -fig, ax = plt.subplots(3, 1, figsize=(8, 8)) -ax = ax.flatten() -# even bounds gives a contour-like effect -bounds = np.linspace(-1, 1, 10) -norm = colors.BoundaryNorm(boundaries=bounds, ncolors=256) -pcm = ax[0].pcolormesh(X, Y, Z, - norm=norm, - cmap='RdBu_r') -fig.colorbar(pcm, ax=ax[0], extend='both', orientation='vertical') - -# uneven bounds changes the colormapping: -bounds = np.array([-0.25, -0.125, 0, 0.5, 1]) -norm = colors.BoundaryNorm(boundaries=bounds, ncolors=256) -pcm = ax[1].pcolormesh(X, Y, Z, norm=norm, cmap='RdBu_r') -fig.colorbar(pcm, ax=ax[1], extend='both', orientation='vertical') - -pcm = ax[2].pcolormesh(X, Y, Z, cmap='RdBu_r', vmin=-np.max(Z)) -fig.colorbar(pcm, ax=ax[2], extend='both', orientation='vertical') - -plt.show() diff --git a/examples/userdemo/colormap_normalizations_custom.py b/examples/userdemo/colormap_normalizations_custom.py deleted file mode 100644 index 2eb042f1f4c5..000000000000 --- a/examples/userdemo/colormap_normalizations_custom.py +++ /dev/null @@ -1,50 +0,0 @@ -""" -============================== -Colormap Normalizations Custom -============================== - -Demonstration of using norm to map colormaps onto data in non-linear ways. -""" - -import numpy as np -import matplotlib.pyplot as plt -import matplotlib.colors as colors - -N = 100 -''' -Custom Norm: An example with a customized normalization. This one -uses the example above, and normalizes the negative data differently -from the positive. -''' -X, Y = np.mgrid[-3:3:complex(0, N), -2:2:complex(0, N)] -Z1 = np.exp(-X**2 - Y**2) -Z2 = np.exp(-(X - 1)**2 - (Y - 1)**2) -Z = (Z1 - Z2) * 2 - - -# Example of making your own norm. Also see matplotlib.colors. -# From Joe Kington: This one gives two different linear ramps: -class MidpointNormalize(colors.Normalize): - def __init__(self, vmin=None, vmax=None, midpoint=None, clip=False): - self.midpoint = midpoint - colors.Normalize.__init__(self, vmin, vmax, clip) - - def __call__(self, value, clip=None): - # I'm ignoring masked values and all kinds of edge cases to make a - # simple example... - x, y = [self.vmin, self.midpoint, self.vmax], [0, 0.5, 1] - return np.ma.masked_array(np.interp(value, x, y)) - - -##### -fig, ax = plt.subplots(2, 1) - -pcm = ax[0].pcolormesh(X, Y, Z, - norm=MidpointNormalize(midpoint=0.), - cmap='RdBu_r') -fig.colorbar(pcm, ax=ax[0], extend='both') - -pcm = ax[1].pcolormesh(X, Y, Z, cmap='RdBu_r', vmin=-np.max(Z)) -fig.colorbar(pcm, ax=ax[1], extend='both') - -plt.show() diff --git a/examples/userdemo/colormap_normalizations_diverging.py b/examples/userdemo/colormap_normalizations_diverging.py deleted file mode 100644 index 65bad21dbfda..000000000000 --- a/examples/userdemo/colormap_normalizations_diverging.py +++ /dev/null @@ -1,44 +0,0 @@ -""" -=================================== -TwoSlopeNorm colormap normalization -=================================== - -Sometimes we want to have a different colormap on either side of a -conceptual center point, and we want those two colormaps to have -different linear scales. An example is a topographic map where the land -and ocean have a center at zero, but land typically has a greater -elevation range than the water has depth range, and they are often -represented by a different colormap. -""" - -import numpy as np -import matplotlib.pyplot as plt -import matplotlib.cbook as cbook -import matplotlib.colors as colors - -filename = cbook.get_sample_data('topobathy.npz', asfileobj=False) -with np.load(filename) as dem: - topo = dem['topo'] - longitude = dem['longitude'] - latitude = dem['latitude'] - -fig, ax = plt.subplots(constrained_layout=True) -# make a colormap that has land and ocean clearly delineated and of the -# same length (256 + 256) -colors_undersea = plt.cm.terrain(np.linspace(0, 0.17, 256)) -colors_land = plt.cm.terrain(np.linspace(0.25, 1, 256)) -all_colors = np.vstack((colors_undersea, colors_land)) -terrain_map = colors.LinearSegmentedColormap.from_list( - 'terrain_map', all_colors) - -# make the norm: Note the center is offset so that the land has more -# dynamic range: -divnorm = colors.TwoSlopeNorm(vmin=-500, vcenter=0, vmax=4000) - -pcm = ax.pcolormesh( - longitude, latitude, topo, rasterized=True, norm=divnorm, cmap=terrain_map) -ax.set_xlabel('Lon $[^o E]$') -ax.set_ylabel('Lat $[^o N]$') -ax.set_aspect(1 / np.cos(np.deg2rad(49))) -fig.colorbar(pcm, shrink=0.6, extend='both', label='Elevation [m]') -plt.show() diff --git a/examples/userdemo/colormap_normalizations_lognorm.py b/examples/userdemo/colormap_normalizations_lognorm.py deleted file mode 100644 index 5b2f7c3668af..000000000000 --- a/examples/userdemo/colormap_normalizations_lognorm.py +++ /dev/null @@ -1,35 +0,0 @@ -""" -=============================== -Colormap Normalizations Lognorm -=============================== - -Demonstration of using norm to map colormaps onto data in non-linear ways. -""" - -import numpy as np -import matplotlib.pyplot as plt -import matplotlib.colors as colors - -''' -Lognorm: Instead of pcolor log10(Z1) you can have colorbars that have -the exponential labels using a norm. -''' -N = 100 -X, Y = np.mgrid[-3:3:complex(0, N), -2:2:complex(0, N)] - -# A low hump with a spike coming out of the top right. Needs to have -# z/colour axis on a log scale so we see both hump and spike. linear -# scale only shows the spike. -Z = np.exp(-X**2 - Y**2) - -fig, ax = plt.subplots(2, 1) - -pcm = ax[0].pcolor(X, Y, Z, - norm=colors.LogNorm(vmin=Z.min(), vmax=Z.max()), - cmap='PuBu_r') -fig.colorbar(pcm, ax=ax[0], extend='max') - -pcm = ax[1].pcolor(X, Y, Z, cmap='PuBu_r') -fig.colorbar(pcm, ax=ax[1], extend='max') - -plt.show() diff --git a/examples/userdemo/colormap_normalizations_power.py b/examples/userdemo/colormap_normalizations_power.py deleted file mode 100644 index 6ea9a01ceca2..000000000000 --- a/examples/userdemo/colormap_normalizations_power.py +++ /dev/null @@ -1,32 +0,0 @@ -""" -============================= -Colormap Normalizations Power -============================= - -Demonstration of using norm to map colormaps onto data in non-linear ways. -""" - -import numpy as np -import matplotlib.pyplot as plt -import matplotlib.colors as colors - -N = 100 -X, Y = np.mgrid[-3:3:complex(0, N), -2:2:complex(0, N)] - -''' -PowerNorm: Here a power-law trend in X partially obscures a rectified -sine wave in Y. We can remove the power law using a PowerNorm. -''' -X, Y = np.mgrid[0:3:complex(0, N), 0:2:complex(0, N)] -Z1 = (1 + np.sin(Y * 10.)) * X**2 - -fig, ax = plt.subplots(2, 1) - -pcm = ax[0].pcolormesh(X, Y, Z1, norm=colors.PowerNorm(gamma=1./2.), - cmap='PuBu_r') -fig.colorbar(pcm, ax=ax[0], extend='max') - -pcm = ax[1].pcolormesh(X, Y, Z1, cmap='PuBu_r') -fig.colorbar(pcm, ax=ax[1], extend='max') - -plt.show() diff --git a/tutorials/colors/colormapnorms.py b/tutorials/colors/colormapnorms.py index db35807799f0..549cc781b9fa 100644 --- a/tutorials/colors/colormapnorms.py +++ b/tutorials/colors/colormapnorms.py @@ -62,10 +62,10 @@ pcm = ax[0].pcolor(X, Y, Z, norm=colors.LogNorm(vmin=Z.min(), vmax=Z.max()), - cmap='PuBu_r') + cmap='PuBu_r', shading='auto') fig.colorbar(pcm, ax=ax[0], extend='max') -pcm = ax[1].pcolor(X, Y, Z, cmap='PuBu_r') +pcm = ax[1].pcolor(X, Y, Z, cmap='PuBu_r', shading='auto') fig.colorbar(pcm, ax=ax[1], extend='max') plt.show() @@ -99,10 +99,10 @@ pcm = ax[0].pcolormesh(X, Y, Z, norm=colors.SymLogNorm(linthresh=0.03, linscale=0.03, vmin=-1.0, vmax=1.0, base=10), - cmap='RdBu_r') + cmap='RdBu_r', shading='auto') fig.colorbar(pcm, ax=ax[0], extend='both') -pcm = ax[1].pcolormesh(X, Y, Z, cmap='RdBu_r', vmin=-np.max(Z)) +pcm = ax[1].pcolormesh(X, Y, Z, cmap='RdBu_r', vmin=-np.max(Z), shading='auto') fig.colorbar(pcm, ax=ax[1], extend='both') plt.show() @@ -131,10 +131,10 @@ fig, ax = plt.subplots(2, 1) pcm = ax[0].pcolormesh(X, Y, Z1, norm=colors.PowerNorm(gamma=0.5), - cmap='PuBu_r') + cmap='PuBu_r', shading='auto') fig.colorbar(pcm, ax=ax[0], extend='max') -pcm = ax[1].pcolormesh(X, Y, Z1, cmap='PuBu_r') +pcm = ax[1].pcolormesh(X, Y, Z1, cmap='PuBu_r', shading='auto') fig.colorbar(pcm, ax=ax[1], extend='max') plt.show() @@ -171,18 +171,16 @@ # even bounds gives a contour-like effect bounds = np.linspace(-1, 1, 10) norm = colors.BoundaryNorm(boundaries=bounds, ncolors=256) -pcm = ax[0].pcolormesh(X, Y, Z, - norm=norm, - cmap='RdBu_r') +pcm = ax[0].pcolormesh(X, Y, Z, norm=norm, cmap='RdBu_r', shading='auto') fig.colorbar(pcm, ax=ax[0], extend='both', orientation='vertical') # uneven bounds changes the colormapping: bounds = np.array([-0.25, -0.125, 0, 0.5, 1]) norm = colors.BoundaryNorm(boundaries=bounds, ncolors=256) -pcm = ax[1].pcolormesh(X, Y, Z, norm=norm, cmap='RdBu_r') +pcm = ax[1].pcolormesh(X, Y, Z, norm=norm, cmap='RdBu_r', shading='auto') fig.colorbar(pcm, ax=ax[1], extend='both', orientation='vertical') -pcm = ax[2].pcolormesh(X, Y, Z, cmap='RdBu_r', vmin=-np.max(Z)) +pcm = ax[2].pcolormesh(X, Y, Z, cmap='RdBu_r', vmin=-np.max(Z), shading='auto') fig.colorbar(pcm, ax=ax[2], extend='both', orientation='vertical') plt.show() @@ -217,8 +215,8 @@ # dynamic range: divnorm = colors.TwoSlopeNorm(vmin=-500., vcenter=0, vmax=4000) -pcm = ax.pcolormesh( - longitude, latitude, topo, rasterized=True, norm=divnorm, cmap=terrain_map) +pcm = ax.pcolormesh(longitude, latitude, topo, rasterized=True, norm=divnorm, + cmap=terrain_map, shading='auto') # Simple geographic plot, set aspect ratio beecause distance between lines of # longitude depends on latitude. ax.set_aspect(1 / np.cos(np.deg2rad(49))) @@ -248,8 +246,8 @@ def __call__(self, value, clip=None): fig, ax = plt.subplots() midnorm = MidpointNormalize(vmin=-500., vcenter=0, vmax=4000) -pcm = ax.pcolormesh( - longitude, latitude, topo, rasterized=True, norm=midnorm, cmap=terrain_map) +pcm = ax.pcolormesh(longitude, latitude, topo, rasterized=True, norm=midnorm, + cmap=terrain_map, shading='auto') ax.set_aspect(1 / np.cos(np.deg2rad(49))) fig.colorbar(pcm, shrink=0.6, extend='both') plt.show()