diff --git a/galleries/examples/misc/custom_projection.py b/galleries/examples/misc/custom_projection.py index e63ba8771ee1..a6e7648d62a1 100644 --- a/galleries/examples/misc/custom_projection.py +++ b/galleries/examples/misc/custom_projection.py @@ -439,7 +439,7 @@ def _get_core_transform(self, resolution): import matplotlib.pyplot as plt # Now make a simple example using the custom projection. - fig, ax = plt.subplots(subplot_kw={'projection': 'custom_hammer'}) + ax = plt.figure().add_subplot(projection="custom_hammer") ax.plot([-1, 1, 1], [-1, -1, 1], "o-") ax.grid() diff --git a/galleries/examples/mplot3d/custom_shaded_3d_surface.py b/galleries/examples/mplot3d/custom_shaded_3d_surface.py index 677bfa179a83..d4c51481b750 100644 --- a/galleries/examples/mplot3d/custom_shaded_3d_surface.py +++ b/galleries/examples/mplot3d/custom_shaded_3d_surface.py @@ -24,7 +24,7 @@ x, y, z = x[region], y[region], z[region] # Set up plot -fig, ax = plt.subplots(subplot_kw=dict(projection='3d')) +ax = plt.figure().add_subplot(projection="3d") ls = LightSource(270, 45) # To use a custom hillshading mode, override the built-in shading and pass diff --git a/galleries/examples/mplot3d/stem3d_demo.py b/galleries/examples/mplot3d/stem3d_demo.py index 6f1773c1b505..bbe363299649 100644 --- a/galleries/examples/mplot3d/stem3d_demo.py +++ b/galleries/examples/mplot3d/stem3d_demo.py @@ -15,7 +15,7 @@ y = np.sin(theta - np.pi/2) z = theta -fig, ax = plt.subplots(subplot_kw=dict(projection='3d')) +ax = plt.figure().add_subplot(projection="3d") ax.stem(x, y, z) plt.show() @@ -28,7 +28,7 @@ # configurable via keyword arguments. For more advanced control adapt the line # objects returned by `~mpl_toolkits.mplot3d.axes3d.Axes3D.stem`. -fig, ax = plt.subplots(subplot_kw=dict(projection='3d')) +ax = plt.figure().add_subplot(projection="3d") markerline, stemlines, baseline = ax.stem( x, y, z, linefmt='grey', markerfmt='D', bottom=np.pi) markerline.set_markerfacecolor('none') @@ -44,7 +44,7 @@ # For examples, by setting ``orientation='x'``, the stems are projected along # the *x*-direction, and the baseline is in the *yz*-plane. -fig, ax = plt.subplots(subplot_kw=dict(projection='3d')) +ax = plt.figure().add_subplot(projection="3d") markerline, stemlines, baseline = ax.stem(x, y, z, bottom=-1, orientation='x') ax.set(xlabel='x', ylabel='y', zlabel='z') diff --git a/galleries/examples/pie_and_polar_charts/polar_demo.py b/galleries/examples/pie_and_polar_charts/polar_demo.py index 75a7d61f6244..66844281615c 100644 --- a/galleries/examples/pie_and_polar_charts/polar_demo.py +++ b/galleries/examples/pie_and_polar_charts/polar_demo.py @@ -11,7 +11,7 @@ r = np.arange(0, 2, 0.01) theta = 2 * np.pi * r -fig, ax = plt.subplots(subplot_kw={'projection': 'polar'}) +ax = plt.figure().add_subplot(projection="polar") ax.plot(theta, r) ax.set_rmax(2) ax.set_rticks([0.5, 1, 1.5, 2]) # Less radial ticks diff --git a/galleries/examples/shapes_and_collections/ellipse_demo.py b/galleries/examples/shapes_and_collections/ellipse_demo.py index 22de6998418d..0d7e72a1100d 100644 --- a/galleries/examples/shapes_and_collections/ellipse_demo.py +++ b/galleries/examples/shapes_and_collections/ellipse_demo.py @@ -22,16 +22,15 @@ angle=np.random.rand() * 360) for i in range(NUM)] -fig, ax = plt.subplots(subplot_kw={'aspect': 'equal'}) +fig, ax = plt.subplots() +ax.set(xlim=(0, 10), ylim=(0, 10), aspect="equal") + for e in ells: ax.add_artist(e) e.set_clip_box(ax.bbox) e.set_alpha(np.random.rand()) e.set_facecolor(np.random.rand(3)) -ax.set_xlim(0, 10) -ax.set_ylim(0, 10) - plt.show() # %% @@ -45,15 +44,13 @@ angle_step = 45 # degrees angles = np.arange(0, 180, angle_step) -fig, ax = plt.subplots(subplot_kw={'aspect': 'equal'}) +fig, ax = plt.subplots() +ax.set(xlim=(-2.2, 2.2), ylim=(-2.2, 2.2), aspect="equal") for angle in angles: ellipse = Ellipse((0, 0), 4, 2, angle=angle, alpha=0.1) ax.add_artist(ellipse) -ax.set_xlim(-2.2, 2.2) -ax.set_ylim(-2.2, 2.2) - plt.show() # %% diff --git a/galleries/examples/text_labels_and_annotations/annotation_demo.py b/galleries/examples/text_labels_and_annotations/annotation_demo.py index 8b310a7a1865..186f422f50d4 100644 --- a/galleries/examples/text_labels_and_annotations/annotation_demo.py +++ b/galleries/examples/text_labels_and_annotations/annotation_demo.py @@ -110,7 +110,7 @@ # The text in the example is placed in the fractional figure coordinate system. # Text keyword arguments like horizontal and vertical alignment are respected. -fig, ax = plt.subplots(subplot_kw=dict(projection='polar'), figsize=(3, 3)) +ax = plt.figure(figsize=(3, 3)).add_subplot(projection='polar') r = np.arange(0, 1, 0.001) theta = 2*2*np.pi*r line, = ax.plot(theta, r) diff --git a/galleries/examples/widgets/lasso_selector_demo_sgskip.py b/galleries/examples/widgets/lasso_selector_demo_sgskip.py index fd2459be4f4f..628012ea4527 100644 --- a/galleries/examples/widgets/lasso_selector_demo_sgskip.py +++ b/galleries/examples/widgets/lasso_selector_demo_sgskip.py @@ -81,8 +81,8 @@ def disconnect(self): data = np.random.rand(100, 2) - subplot_kw = dict(xlim=(0, 1), ylim=(0, 1), autoscale_on=False) - fig, ax = plt.subplots(subplot_kw=subplot_kw) + fig, ax = plt.subplots() + ax.set(xlim=(0, 1), ylim=(0, 1)) pts = ax.scatter(data[:, 0], data[:, 1], s=80) selector = SelectFromCollection(ax, pts) diff --git a/galleries/plot_types/3D/scatter3d_simple.py b/galleries/plot_types/3D/scatter3d_simple.py index 27ffb6abf748..d2d5e9c063e8 100644 --- a/galleries/plot_types/3D/scatter3d_simple.py +++ b/galleries/plot_types/3D/scatter3d_simple.py @@ -19,7 +19,7 @@ zs = rng.uniform(-50, -25, n) # Plot -fig, ax = plt.subplots(subplot_kw={"projection": "3d"}) +ax = plt.figure().add_subplot(projection="3d") ax.scatter(xs, ys, zs) ax.set(xticklabels=[], diff --git a/galleries/plot_types/3D/surface3d_simple.py b/galleries/plot_types/3D/surface3d_simple.py index 04f74d5edd14..f9a856c072d4 100644 --- a/galleries/plot_types/3D/surface3d_simple.py +++ b/galleries/plot_types/3D/surface3d_simple.py @@ -20,7 +20,7 @@ Z = np.sin(R) # Plot the surface -fig, ax = plt.subplots(subplot_kw={"projection": "3d"}) +ax = plt.figure().add_subplot(projection="3d") ax.plot_surface(X, Y, Z, vmin=Z.min() * 2, cmap=cm.Blues) ax.set(xticklabels=[], diff --git a/galleries/plot_types/3D/trisurf3d_simple.py b/galleries/plot_types/3D/trisurf3d_simple.py index b32bd3ebc69a..23da644e708e 100644 --- a/galleries/plot_types/3D/trisurf3d_simple.py +++ b/galleries/plot_types/3D/trisurf3d_simple.py @@ -25,7 +25,7 @@ z = np.sin(-x*y) # Plot -fig, ax = plt.subplots(subplot_kw={'projection': '3d'}) +ax = plt.figure().add_subplot(projection="3d") ax.plot_trisurf(x, y, z, vmin=z.min() * 2, cmap=cm.Blues) ax.set(xticklabels=[], diff --git a/galleries/plot_types/3D/voxels_simple.py b/galleries/plot_types/3D/voxels_simple.py index 05ce238b0935..eb3f93bee824 100644 --- a/galleries/plot_types/3D/voxels_simple.py +++ b/galleries/plot_types/3D/voxels_simple.py @@ -21,7 +21,7 @@ voxelarray = cube1 | cube2 # Plot -fig, ax = plt.subplots(subplot_kw={"projection": "3d"}) +ax = plt.figure().add_subplot(projection="3d") ax.voxels(voxelarray, edgecolor='k') ax.set(xticklabels=[], diff --git a/galleries/plot_types/3D/wire3d_simple.py b/galleries/plot_types/3D/wire3d_simple.py index 1ab847f3ecf4..5141950a25f8 100644 --- a/galleries/plot_types/3D/wire3d_simple.py +++ b/galleries/plot_types/3D/wire3d_simple.py @@ -15,7 +15,7 @@ X, Y, Z = axes3d.get_test_data(0.05) # Plot -fig, ax = plt.subplots(subplot_kw={"projection": "3d"}) +ax = plt.figure().add_subplot(projection="3d") ax.plot_wireframe(X, Y, Z, rstride=10, cstride=10) ax.set(xticklabels=[],