diff --git a/examples/mplot3d/2dcollections3d.py b/examples/mplot3d/2dcollections3d.py index c5956bc08fb5..f4d57416355d 100644 --- a/examples/mplot3d/2dcollections3d.py +++ b/examples/mplot3d/2dcollections3d.py @@ -10,8 +10,7 @@ import numpy as np import matplotlib.pyplot as plt -fig = plt.figure() -ax = fig.gca(projection='3d') +ax = plt.figure().add_subplot(projection='3d') # Plot a sin curve using the x and y axes. x = np.linspace(0, 1, 100) diff --git a/examples/mplot3d/contour3d.py b/examples/mplot3d/contour3d.py index 8ae9deb54981..7c4f5dcbc6d5 100644 --- a/examples/mplot3d/contour3d.py +++ b/examples/mplot3d/contour3d.py @@ -11,13 +11,10 @@ import matplotlib.pyplot as plt from matplotlib import cm -fig = plt.figure() -ax = fig.gca(projection='3d') +ax = plt.figure().add_subplot(projection='3d') X, Y, Z = axes3d.get_test_data(0.05) -# Plot contour curves -cset = ax.contour(X, Y, Z, cmap=cm.coolwarm) - +cset = ax.contour(X, Y, Z, cmap=cm.coolwarm) # Plot contour curves ax.clabel(cset, fontsize=9, inline=True) plt.show() diff --git a/examples/mplot3d/contour3d_2.py b/examples/mplot3d/contour3d_2.py index 686fc4aa39f0..ed9c27f0b5ab 100644 --- a/examples/mplot3d/contour3d_2.py +++ b/examples/mplot3d/contour3d_2.py @@ -11,8 +11,7 @@ import matplotlib.pyplot as plt from matplotlib import cm -fig = plt.figure() -ax = fig.gca(projection='3d') +ax = plt.figure().add_subplot(projection='3d') X, Y, Z = axes3d.get_test_data(0.05) cset = ax.contour(X, Y, Z, extend3d=True, cmap=cm.coolwarm) diff --git a/examples/mplot3d/contour3d_3.py b/examples/mplot3d/contour3d_3.py index 33a69d61c9b2..db620e426a68 100644 --- a/examples/mplot3d/contour3d_3.py +++ b/examples/mplot3d/contour3d_3.py @@ -13,8 +13,7 @@ import matplotlib.pyplot as plt from matplotlib import cm -fig = plt.figure() -ax = fig.gca(projection='3d') +ax = plt.figure().add_subplot(projection='3d') X, Y, Z = axes3d.get_test_data(0.05) # Plot the 3D surface diff --git a/examples/mplot3d/contourf3d.py b/examples/mplot3d/contourf3d.py index 1fcfe5c634bf..7cb78e8f1b52 100644 --- a/examples/mplot3d/contourf3d.py +++ b/examples/mplot3d/contourf3d.py @@ -14,8 +14,7 @@ import matplotlib.pyplot as plt from matplotlib import cm -fig = plt.figure() -ax = fig.gca(projection='3d') +ax = plt.figure().add_subplot(projection='3d') X, Y, Z = axes3d.get_test_data(0.05) cset = ax.contourf(X, Y, Z, cmap=cm.coolwarm) diff --git a/examples/mplot3d/contourf3d_2.py b/examples/mplot3d/contourf3d_2.py index 824d3abd6db3..5ef9dc8761c7 100644 --- a/examples/mplot3d/contourf3d_2.py +++ b/examples/mplot3d/contourf3d_2.py @@ -13,8 +13,7 @@ import matplotlib.pyplot as plt from matplotlib import cm -fig = plt.figure() -ax = fig.gca(projection='3d') +ax = plt.figure().add_subplot(projection='3d') X, Y, Z = axes3d.get_test_data(0.05) # Plot the 3D surface diff --git a/examples/mplot3d/errorbar3d.py b/examples/mplot3d/errorbar3d.py index 7d8599d9cf2a..e4da658d194b 100644 --- a/examples/mplot3d/errorbar3d.py +++ b/examples/mplot3d/errorbar3d.py @@ -9,8 +9,7 @@ import matplotlib.pyplot as plt import numpy as np -fig = plt.figure() -ax = fig.gca(projection='3d') +ax = plt.figure().add_subplot(projection='3d') # setting up a parametric curve t = np.arange(0, 2*np.pi+.1, 0.01) diff --git a/examples/mplot3d/lines3d.py b/examples/mplot3d/lines3d.py index 92860ee993c5..f7578d8657b4 100644 --- a/examples/mplot3d/lines3d.py +++ b/examples/mplot3d/lines3d.py @@ -10,10 +10,7 @@ import matplotlib.pyplot as plt -plt.rcParams['legend.fontsize'] = 10 - -fig = plt.figure() -ax = fig.gca(projection='3d') +ax = plt.figure().add_subplot(projection='3d') # Prepare arrays x, y, z theta = np.linspace(-4 * np.pi, 4 * np.pi, 100) diff --git a/examples/mplot3d/lorenz_attractor.py b/examples/mplot3d/lorenz_attractor.py index 93e40fdbd4c4..778f4f849e3c 100644 --- a/examples/mplot3d/lorenz_attractor.py +++ b/examples/mplot3d/lorenz_attractor.py @@ -54,8 +54,7 @@ def lorenz(x, y, z, s=10, r=28, b=2.667): # Plot -fig = plt.figure() -ax = fig.gca(projection='3d') +ax = plt.figure().add_subplot(projection='3d') ax.plot(xs, ys, zs, lw=0.5) ax.set_xlabel("X Axis") diff --git a/examples/mplot3d/offset.py b/examples/mplot3d/offset.py index 9583c4766bd7..56a14d69fa98 100644 --- a/examples/mplot3d/offset.py +++ b/examples/mplot3d/offset.py @@ -17,8 +17,7 @@ import numpy as np -fig = plt.figure() -ax = fig.gca(projection='3d') +ax = plt.figure().add_subplot(projection='3d') X, Y = np.mgrid[0:6*np.pi:0.25, 0:4*np.pi:0.25] Z = np.sqrt(np.abs(np.cos(X) + np.cos(Y))) diff --git a/examples/mplot3d/polys3d.py b/examples/mplot3d/polys3d.py index 3ca918632acc..9a2ee1ad3155 100644 --- a/examples/mplot3d/polys3d.py +++ b/examples/mplot3d/polys3d.py @@ -24,8 +24,7 @@ def polygon_under_graph(xlist, ylist): return [(xlist[0], 0.), *zip(xlist, ylist), (xlist[-1], 0.)] -fig = plt.figure() -ax = fig.gca(projection='3d') +ax = plt.figure().add_subplot(projection='3d') # Make verts a list such that verts[i] is a list of (x, y) pairs defining # polygon i. diff --git a/examples/mplot3d/quiver3d.py b/examples/mplot3d/quiver3d.py index e0a97fa1ee62..12d60ee93e62 100644 --- a/examples/mplot3d/quiver3d.py +++ b/examples/mplot3d/quiver3d.py @@ -9,8 +9,7 @@ import matplotlib.pyplot as plt import numpy as np -fig = plt.figure() -ax = fig.gca(projection='3d') +ax = plt.figure().add_subplot(projection='3d') # Make the grid x, y, z = np.meshgrid(np.arange(-0.8, 1, 0.2), diff --git a/examples/mplot3d/surface3d_3.py b/examples/mplot3d/surface3d_3.py index ffed591ec071..2c8a4112236e 100644 --- a/examples/mplot3d/surface3d_3.py +++ b/examples/mplot3d/surface3d_3.py @@ -11,8 +11,7 @@ import numpy as np -fig = plt.figure() -ax = fig.gca(projection='3d') +ax = plt.figure().add_subplot(projection='3d') # Make data. X = np.arange(-5, 5, 0.25) diff --git a/examples/mplot3d/text3d.py b/examples/mplot3d/text3d.py index 4250125aa2c5..7f6a2858eb1f 100644 --- a/examples/mplot3d/text3d.py +++ b/examples/mplot3d/text3d.py @@ -7,20 +7,17 @@ Functionality shown: - - Using the text function with three types of 'zdir' values: None, an axis - name (ex. 'x'), or a direction tuple (ex. (1, 1, 0)). - - Using the text function with the color keyword. - - - Using the text2D function to place text on a fixed position on the ax - object. - +- Using the text function with three types of 'zdir' values: None, an axis + name (ex. 'x'), or a direction tuple (ex. (1, 1, 0)). +- Using the text function with the color keyword. +- Using the text2D function to place text on a fixed position on the ax + object. """ import matplotlib.pyplot as plt -fig = plt.figure() -ax = fig.gca(projection='3d') +ax = plt.figure().add_subplot(projection='3d') # Demo 1: zdir zdirs = (None, 'x', 'y', 'z', (1, 1, 0), (1, 1, 1)) diff --git a/examples/mplot3d/tricontour3d.py b/examples/mplot3d/tricontour3d.py index 96350db544a6..825e90d4dffa 100644 --- a/examples/mplot3d/tricontour3d.py +++ b/examples/mplot3d/tricontour3d.py @@ -35,8 +35,7 @@ y[triang.triangles].mean(axis=1)) < min_radius) -fig = plt.figure() -ax = fig.gca(projection='3d') +ax = plt.figure().add_subplot(projection='3d') ax.tricontour(triang, z, cmap=plt.cm.CMRmap) # Customize the view angle so it's easier to understand the plot. diff --git a/examples/mplot3d/tricontourf3d.py b/examples/mplot3d/tricontourf3d.py index 772ff78e063f..f579cb1f7c6f 100644 --- a/examples/mplot3d/tricontourf3d.py +++ b/examples/mplot3d/tricontourf3d.py @@ -36,8 +36,7 @@ y[triang.triangles].mean(axis=1)) < min_radius) -fig = plt.figure() -ax = fig.gca(projection='3d') +ax = plt.figure().add_subplot(projection='3d') ax.tricontourf(triang, z, cmap=plt.cm.CMRmap) # Customize the view angle so it's easier to understand the plot. diff --git a/examples/mplot3d/trisurf3d.py b/examples/mplot3d/trisurf3d.py index 1f320903310a..978b0e3abc02 100644 --- a/examples/mplot3d/trisurf3d.py +++ b/examples/mplot3d/trisurf3d.py @@ -26,8 +26,7 @@ # Compute z to make the pringle surface. z = np.sin(-x*y) -fig = plt.figure() -ax = fig.gca(projection='3d') +ax = plt.figure().add_subplot(projection='3d') ax.plot_trisurf(x, y, z, linewidth=0.2, antialiased=True) diff --git a/examples/mplot3d/voxels.py b/examples/mplot3d/voxels.py index 58fdbbe72db3..c6a35d7bcf5b 100644 --- a/examples/mplot3d/voxels.py +++ b/examples/mplot3d/voxels.py @@ -29,8 +29,7 @@ colors[cube2] = 'green' # and plot everything -fig = plt.figure() -ax = fig.gca(projection='3d') +ax = plt.figure().add_subplot(projection='3d') ax.voxels(voxels, facecolors=colors, edgecolor='k') plt.show() diff --git a/examples/mplot3d/voxels_numpy_logo.py b/examples/mplot3d/voxels_numpy_logo.py index 5c56b8de34f0..9aa72b31e290 100644 --- a/examples/mplot3d/voxels_numpy_logo.py +++ b/examples/mplot3d/voxels_numpy_logo.py @@ -5,6 +5,7 @@ Demonstrates using `.Axes3D.voxels` with uneven coordinates. """ + import matplotlib.pyplot as plt import numpy as np @@ -39,8 +40,7 @@ def explode(data): y[:, 1::2, :] += 0.95 z[:, :, 1::2] += 0.95 -fig = plt.figure() -ax = fig.gca(projection='3d') +ax = plt.figure().add_subplot(projection='3d') ax.voxels(x, y, z, filled_2, facecolors=fcolors_2, edgecolors=ecolors_2) plt.show() diff --git a/examples/mplot3d/voxels_rgb.py b/examples/mplot3d/voxels_rgb.py index e7fb7fe61c4f..a06cc10a5cc1 100644 --- a/examples/mplot3d/voxels_rgb.py +++ b/examples/mplot3d/voxels_rgb.py @@ -33,8 +33,7 @@ def midpoints(x): colors[..., 2] = bc # and plot everything -fig = plt.figure() -ax = fig.gca(projection='3d') +ax = plt.figure().add_subplot(projection='3d') ax.voxels(r, g, b, sphere, facecolors=colors, edgecolors=np.clip(2*colors - 0.5, 0, 1), # brighter diff --git a/examples/mplot3d/voxels_torus.py b/examples/mplot3d/voxels_torus.py index 11b5a0b05f62..10aa9c21d124 100644 --- a/examples/mplot3d/voxels_torus.py +++ b/examples/mplot3d/voxels_torus.py @@ -36,8 +36,7 @@ def midpoints(x): colors = matplotlib.colors.hsv_to_rgb(hsv) # and plot everything -fig = plt.figure() -ax = fig.gca(projection='3d') +ax = plt.figure().add_subplot(projection='3d') ax.voxels(x, y, z, sphere, facecolors=colors, edgecolors=np.clip(2*colors - 0.5, 0, 1), # brighter diff --git a/lib/mpl_toolkits/tests/test_mplot3d.py b/lib/mpl_toolkits/tests/test_mplot3d.py index 0b4341b1185b..b68c250496ed 100644 --- a/lib/mpl_toolkits/tests/test_mplot3d.py +++ b/lib/mpl_toolkits/tests/test_mplot3d.py @@ -112,7 +112,7 @@ def test_bar3d_lightsource(): @mpl3d_image_comparison(['contour3d.png']) def test_contour3d(): fig = plt.figure() - ax = fig.gca(projection='3d') + ax = fig.add_subplot(projection='3d') X, Y, Z = axes3d.get_test_data(0.05) ax.contour(X, Y, Z, zdir='z', offset=-100, cmap=cm.coolwarm) ax.contour(X, Y, Z, zdir='x', offset=-40, cmap=cm.coolwarm) @@ -125,7 +125,7 @@ def test_contour3d(): @mpl3d_image_comparison(['contourf3d.png']) def test_contourf3d(): fig = plt.figure() - ax = fig.gca(projection='3d') + ax = fig.add_subplot(projection='3d') X, Y, Z = axes3d.get_test_data(0.05) ax.contourf(X, Y, Z, zdir='z', offset=-100, cmap=cm.coolwarm) ax.contourf(X, Y, Z, zdir='x', offset=-40, cmap=cm.coolwarm) @@ -138,7 +138,7 @@ def test_contourf3d(): @mpl3d_image_comparison(['contourf3d_fill.png']) def test_contourf3d_fill(): fig = plt.figure() - ax = fig.gca(projection='3d') + ax = fig.add_subplot(projection='3d') X, Y = np.meshgrid(np.arange(-2, 2, 0.25), np.arange(-2, 2, 0.25)) Z = X.clip(0, 0) # This produces holes in the z=0 surface that causes rendering errors if @@ -168,7 +168,7 @@ def test_tricontour(): @mpl3d_image_comparison(['lines3d.png']) def test_lines3d(): fig = plt.figure() - ax = fig.gca(projection='3d') + ax = fig.add_subplot(projection='3d') theta = np.linspace(-4 * np.pi, 4 * np.pi, 100) z = np.linspace(-2, 2, 100) r = z ** 2 + 1 @@ -179,9 +179,9 @@ def test_lines3d(): @check_figures_equal(extensions=["png"]) def test_plot_scalar(fig_test, fig_ref): - ax1 = fig_test.gca(projection='3d') + ax1 = fig_test.add_subplot(projection='3d') ax1.plot([1], [1], "o") - ax2 = fig_ref.gca(projection='3d') + ax2 = fig_ref.add_subplot(projection='3d') ax2.plot(1, 1, "o") @@ -213,11 +213,11 @@ def f(t): def test_tight_layout_text(fig_test, fig_ref): # text is currently ignored in tight layout. So the order of text() and # tight_layout() calls should not influence the result. - ax1 = fig_test.gca(projection='3d') + ax1 = fig_test.add_subplot(projection='3d') ax1.text(.5, .5, .5, s='some string') fig_test.tight_layout() - ax2 = fig_ref.gca(projection='3d') + ax2 = fig_ref.add_subplot(projection='3d') fig_ref.tight_layout() ax2.text(.5, .5, .5, s='some string') @@ -274,7 +274,7 @@ def test_scatter3d_sorting(fig_ref, fig_test, depthshade): for a in [x, y, z, sizes, facecolors, edgecolors, linewidths] ] - ax_ref = fig_ref.gca(projection='3d') + ax_ref = fig_ref.add_subplot(projection='3d') sets = (np.unique(a) for a in [sizes, facecolors, edgecolors, linewidths]) for s, fc, ec, lw in itertools.product(*sets): subset = ( @@ -294,7 +294,7 @@ def test_scatter3d_sorting(fig_ref, fig_test, depthshade): ax_ref.scatter(x, y, subset, s=s, fc=fc, ec=ec, lw=lw, alpha=1, depthshade=depthshade) - ax_test = fig_test.gca(projection='3d') + ax_test = fig_test.add_subplot(projection='3d') ax_test.scatter(x, y, z, s=sizes, fc=facecolors, ec=edgecolors, lw=linewidths, alpha=1, depthshade=depthshade) @@ -360,7 +360,7 @@ def test_surface3d(): plt.rcParams['pcolormesh.snap'] = False fig = plt.figure() - ax = fig.gca(projection='3d') + ax = fig.add_subplot(projection='3d') X = np.arange(-5, 5, 0.25) Y = np.arange(-5, 5, 0.25) X, Y = np.meshgrid(X, Y) @@ -375,7 +375,7 @@ def test_surface3d(): @mpl3d_image_comparison(['surface3d_shaded.png']) def test_surface3d_shaded(): fig = plt.figure() - ax = fig.gca(projection='3d') + ax = fig.add_subplot(projection='3d') X = np.arange(-5, 5, 0.25) Y = np.arange(-5, 5, 0.25) X, Y = np.meshgrid(X, Y) @@ -389,7 +389,7 @@ def test_surface3d_shaded(): @mpl3d_image_comparison(['text3d.png'], remove_text=False) def test_text3d(): fig = plt.figure() - ax = fig.gca(projection='3d') + ax = fig.add_subplot(projection='3d') zdirs = (None, 'x', 'y', 'z', (1, 1, 0), (1, 1, 1)) xs = (2, 6, 4, 9, 7, 2) @@ -424,7 +424,7 @@ def test_trisurf3d(): z = np.sin(-x*y) fig = plt.figure() - ax = fig.gca(projection='3d') + ax = fig.add_subplot(projection='3d') ax.plot_trisurf(x, y, z, cmap=cm.jet, linewidth=0.2) @@ -442,7 +442,7 @@ def test_trisurf3d_shaded(): z = np.sin(-x*y) fig = plt.figure() - ax = fig.gca(projection='3d') + ax = fig.add_subplot(projection='3d') ax.plot_trisurf(x, y, z, color=[1, 0.5, 0], linewidth=0.2) @@ -511,7 +511,7 @@ def test_quiver3d_empty(fig_test, fig_ref): @mpl3d_image_comparison(['quiver3d_masked.png']) def test_quiver3d_masked(): fig = plt.figure() - ax = fig.gca(projection='3d') + ax = fig.add_subplot(projection='3d') # Using mgrid here instead of ogrid because masked_where doesn't # seem to like broadcasting very much... @@ -529,7 +529,7 @@ def test_quiver3d_masked(): @mpl3d_image_comparison(['poly3dcollection_closed.png']) def test_poly3dcollection_closed(): fig = plt.figure() - ax = fig.gca(projection='3d') + ax = fig.add_subplot(projection='3d') poly1 = np.array([[0, 0, 1], [0, 1, 1], [0, 0, 0]], float) poly2 = np.array([[0, 1, 1], [1, 1, 1], [1, 1, 0]], float) @@ -551,7 +551,7 @@ def test_poly_collection_2d_to_3d_empty(): @mpl3d_image_comparison(['poly3dcollection_alpha.png']) def test_poly3dcollection_alpha(): fig = plt.figure() - ax = fig.gca(projection='3d') + ax = fig.add_subplot(projection='3d') poly1 = np.array([[0, 0, 1], [0, 1, 1], [0, 0, 0]], float) poly2 = np.array([[0, 1, 1], [1, 1, 1], [1, 1, 0]], float) @@ -577,7 +577,7 @@ def test_add_collection3d_zs_array(): segments = np.concatenate([points[:-1], points[1:]], axis=1) fig = plt.figure() - ax = fig.gca(projection='3d') + ax = fig.add_subplot(projection='3d') norm = plt.Normalize(0, 2*np.pi) # 2D LineCollection from x & y values @@ -605,7 +605,7 @@ def test_add_collection3d_zs_scalar(): segments = np.concatenate([points[:-1], points[1:]], axis=1) fig = plt.figure() - ax = fig.gca(projection='3d') + ax = fig.add_subplot(projection='3d') norm = plt.Normalize(0, 2*np.pi) lc = LineCollection(segments, cmap='twilight', norm=norm) @@ -818,7 +818,7 @@ def test_autoscale(): @mpl3d_image_comparison(['axes3d_ortho.png'], remove_text=False) def test_axes3d_ortho(): fig = plt.figure() - ax = fig.gca(projection='3d') + ax = fig.add_subplot(projection='3d') ax.set_proj_type('ortho') @@ -1074,7 +1074,7 @@ def test_quiver3D_smoke(fig_test, fig_ref): u = v = w = np.ones_like(x) for fig, length in zip((fig_ref, fig_test), (1, 1.0)): - ax = fig.gca(projection="3d") + ax = fig.add_subplot(projection="3d") ax.quiver(x, y, z, u, v, w, length=length, pivot=pivot) @@ -1096,7 +1096,7 @@ def test_errorbar3d_errorevery(): x, y, z = np.sin(t), np.cos(3*t), np.sin(5*t) fig = plt.figure() - ax = fig.gca(projection='3d') + ax = fig.add_subplot(projection='3d') estep = 15 i = np.arange(t.size) @@ -1111,7 +1111,7 @@ def test_errorbar3d_errorevery(): def test_errorbar3d(): """Tests limits, color styling, and legend for 3d errorbars.""" fig = plt.figure() - ax = fig.gca(projection='3d') + ax = fig.add_subplot(projection='3d') d = [1, 2, 3, 4, 5] e = [.5, .5, .5, .5, .5]