From 4d6bba5fc6ea00fb7f5874ec3823d0a3590017ba Mon Sep 17 00:00:00 2001 From: Tim Hoffmann <2836374+timhoffm@users.noreply.github.com> Date: Thu, 24 Sep 2020 00:27:05 +0200 Subject: [PATCH] Change subplot(111, ...) to subplot(...) as 111 is the default. --- examples/animation/double_pendulum.py | 2 +- examples/animation/unchained.py | 2 +- examples/axes_grid1/simple_colorbar.py | 2 +- .../event_handling/trifinder_event_demo.py | 2 +- examples/misc/agg_buffer_to_array.py | 2 +- examples/misc/custom_projection.py | 4 +- examples/misc/customize_rc.py | 1 - examples/mplot3d/bars3d.py | 2 +- examples/mplot3d/hist3d.py | 2 +- examples/mplot3d/pathpatch3d.py | 2 +- examples/mplot3d/rotate_axes3d_sgskip.py | 2 +- examples/mplot3d/scatter3d.py | 2 +- examples/mplot3d/surface3d_2.py | 2 +- examples/mplot3d/surface3d_radial.py | 2 +- examples/mplot3d/wire3d.py | 2 +- examples/mplot3d/wire3d_animation_sgskip.py | 2 +- examples/pie_and_polar_charts/polar_bar.py | 2 +- .../pie_and_polar_charts/polar_scatter.py | 6 +- examples/pyplots/annotation_polar.py | 2 +- examples/pyplots/text_commands.py | 2 +- examples/pyplots/whats_new_98_4_legend.py | 2 +- examples/specialty_plots/skewt.py | 5 +- .../subplots_axes_and_figures/geo_demo.py | 8 +- examples/user_interfaces/canvasagg.py | 2 +- .../embedding_in_gtk3_sgskip.py | 2 +- .../user_interfaces/embedding_in_tk_sgskip.py | 2 +- .../embedding_in_wx2_sgskip.py | 2 +- .../embedding_in_wx3_sgskip.py | 2 +- .../embedding_in_wx4_sgskip.py | 2 +- .../embedding_webagg_sgskip.py | 2 +- .../user_interfaces/gtk_spreadsheet_sgskip.py | 2 +- .../user_interfaces/mathtext_wx_sgskip.py | 2 +- .../user_interfaces/mpl_with_glade3_sgskip.py | 2 +- .../user_interfaces/wxcursor_demo_sgskip.py | 2 +- examples/widgets/cursor.py | 2 +- lib/matplotlib/figure.py | 2 +- lib/matplotlib/pyplot.py | 4 +- lib/matplotlib/tests/test_arrow_patches.py | 2 +- lib/matplotlib/tests/test_axes.py | 76 +++++++++---------- lib/matplotlib/tests/test_backend_pdf.py | 8 +- lib/matplotlib/tests/test_bbox_tight.py | 2 +- lib/matplotlib/tests/test_colors.py | 4 +- .../tests/test_constrainedlayout.py | 2 +- lib/matplotlib/tests/test_dates.py | 4 +- lib/matplotlib/tests/test_image.py | 4 +- lib/matplotlib/tests/test_legend.py | 12 +-- lib/matplotlib/tests/test_lines.py | 2 +- lib/matplotlib/tests/test_patches.py | 2 +- lib/matplotlib/tests/test_patheffects.py | 4 +- lib/matplotlib/tests/test_pickle.py | 2 +- lib/matplotlib/tests/test_polar.py | 8 +- lib/matplotlib/tests/test_skew.py | 3 +- lib/matplotlib/tests/test_tightlayout.py | 4 +- lib/matplotlib/tests/test_usetex.py | 2 +- lib/matplotlib/widgets.py | 2 +- lib/mpl_toolkits/tests/test_mplot3d.py | 30 ++++---- tutorials/advanced/transforms_tutorial.py | 2 +- tutorials/intermediate/artists.py | 2 +- tutorials/intermediate/tight_layout_guide.py | 2 +- tutorials/introductory/pyplot.py | 12 +-- tutorials/text/text_intro.py | 2 +- tutorials/toolkits/axes_grid.py | 2 +- tutorials/toolkits/mplot3d.py | 2 +- 63 files changed, 142 insertions(+), 145 deletions(-) diff --git a/examples/animation/double_pendulum.py b/examples/animation/double_pendulum.py index 117322013dc8..0b2fea8a7e89 100644 --- a/examples/animation/double_pendulum.py +++ b/examples/animation/double_pendulum.py @@ -71,7 +71,7 @@ def derivs(state, t): y2 = -L2*cos(y[:, 2]) + y1 fig = plt.figure(figsize=(5, 4)) -ax = fig.add_subplot(111, autoscale_on=False, xlim=(-2, 2), ylim=(-2, 1)) +ax = fig.add_subplot(autoscale_on=False, xlim=(-2, 2), ylim=(-2, 1)) ax.set_aspect('equal') ax.grid() diff --git a/examples/animation/unchained.py b/examples/animation/unchained.py index fbcce8337ee9..522cea10b683 100644 --- a/examples/animation/unchained.py +++ b/examples/animation/unchained.py @@ -21,7 +21,7 @@ fig = plt.figure(figsize=(8, 8), facecolor='black') # Add a subplot with no frame -ax = plt.subplot(111, frameon=False) +ax = plt.subplot(frameon=False) # Generate random data data = np.random.uniform(0, 1, (64, 75)) diff --git a/examples/axes_grid1/simple_colorbar.py b/examples/axes_grid1/simple_colorbar.py index 2c561644840f..d7ca58046a53 100644 --- a/examples/axes_grid1/simple_colorbar.py +++ b/examples/axes_grid1/simple_colorbar.py @@ -8,7 +8,7 @@ from mpl_toolkits.axes_grid1 import make_axes_locatable import numpy as np -ax = plt.subplot(111) +ax = plt.subplot() im = ax.imshow(np.arange(100).reshape((10, 10))) # create an axes on the right side of ax. The width of cax will be 5% diff --git a/examples/event_handling/trifinder_event_demo.py b/examples/event_handling/trifinder_event_demo.py index 9c4a05058fb3..039365af8200 100644 --- a/examples/event_handling/trifinder_event_demo.py +++ b/examples/event_handling/trifinder_event_demo.py @@ -52,7 +52,7 @@ def on_mouse_move(event): trifinder = triang.get_trifinder() # Setup plot and callbacks. -plt.subplot(111, aspect='equal') +plt.subplot(aspect='equal') plt.triplot(triang, 'bo-') polygon = Polygon([[0, 0], [0, 0]], facecolor='y') # dummy data for (xs, ys) update_polygon(-1) diff --git a/examples/misc/agg_buffer_to_array.py b/examples/misc/agg_buffer_to_array.py index 93c80f13b907..1202702367ae 100644 --- a/examples/misc/agg_buffer_to_array.py +++ b/examples/misc/agg_buffer_to_array.py @@ -25,6 +25,6 @@ # now display the array X as an Axes in a new figure fig2 = plt.figure() -ax2 = fig2.add_subplot(111, frameon=False) +ax2 = fig2.add_subplot(frameon=False) ax2.imshow(X) plt.show() diff --git a/examples/misc/custom_projection.py b/examples/misc/custom_projection.py index 14069bb7bf3c..7f7078539da5 100644 --- a/examples/misc/custom_projection.py +++ b/examples/misc/custom_projection.py @@ -370,7 +370,7 @@ class HammerAxes(GeoAxes): # The projection must specify a name. This will be used by the # user to select the projection, - # i.e. ``subplot(111, projection='custom_hammer')``. + # i.e. ``subplot(projection='custom_hammer')``. name = 'custom_hammer' class HammerTransform(Transform): @@ -441,7 +441,7 @@ def _get_core_transform(self, resolution): if __name__ == '__main__': import matplotlib.pyplot as plt # Now make a simple example using the custom projection. - plt.subplot(111, projection="custom_hammer") + plt.subplot(projection="custom_hammer") p = plt.plot([-1, 1, 1], [-1, -1, 1], "o-") plt.grid(True) diff --git a/examples/misc/customize_rc.py b/examples/misc/customize_rc.py index dc406bc63928..d4149c46dd44 100644 --- a/examples/misc/customize_rc.py +++ b/examples/misc/customize_rc.py @@ -26,7 +26,6 @@ def set_pub(): Then as you are working interactively, you just need to do:: >>> set_pub() - >>> subplot(111) >>> plot([1, 2, 3]) >>> savefig('myfig') >>> rcdefaults() # restore the defaults diff --git a/examples/mplot3d/bars3d.py b/examples/mplot3d/bars3d.py index 7ce1740db49c..e4678b351bb4 100644 --- a/examples/mplot3d/bars3d.py +++ b/examples/mplot3d/bars3d.py @@ -15,7 +15,7 @@ fig = plt.figure() -ax = fig.add_subplot(111, projection='3d') +ax = fig.add_subplot(projection='3d') colors = ['r', 'g', 'b', 'y'] yticks = [3, 2, 1, 0] diff --git a/examples/mplot3d/hist3d.py b/examples/mplot3d/hist3d.py index 0ec003d61fdd..6577a010c14a 100644 --- a/examples/mplot3d/hist3d.py +++ b/examples/mplot3d/hist3d.py @@ -14,7 +14,7 @@ fig = plt.figure() -ax = fig.add_subplot(111, projection='3d') +ax = fig.add_subplot(projection='3d') x, y = np.random.rand(2, 100) * 4 hist, xedges, yedges = np.histogram2d(x, y, bins=4, range=[[0, 4], [0, 4]]) diff --git a/examples/mplot3d/pathpatch3d.py b/examples/mplot3d/pathpatch3d.py index d632d3969b03..e300158108a5 100644 --- a/examples/mplot3d/pathpatch3d.py +++ b/examples/mplot3d/pathpatch3d.py @@ -41,7 +41,7 @@ def text3d(ax, xyz, s, zdir="z", size=None, angle=0, usetex=False, **kwargs): fig = plt.figure() -ax = fig.add_subplot(111, projection='3d') +ax = fig.add_subplot(projection='3d') # Draw a circle on the x=0 'wall' p = Circle((5, 5), 3) diff --git a/examples/mplot3d/rotate_axes3d_sgskip.py b/examples/mplot3d/rotate_axes3d_sgskip.py index add73fba99b9..be8adf3c29a0 100644 --- a/examples/mplot3d/rotate_axes3d_sgskip.py +++ b/examples/mplot3d/rotate_axes3d_sgskip.py @@ -15,7 +15,7 @@ import matplotlib.pyplot as plt fig = plt.figure() -ax = fig.add_subplot(111, projection='3d') +ax = fig.add_subplot(projection='3d') # load some test data for demonstration and plot a wireframe X, Y, Z = axes3d.get_test_data(0.1) diff --git a/examples/mplot3d/scatter3d.py b/examples/mplot3d/scatter3d.py index e977dfe43adb..6db0ac9222bc 100644 --- a/examples/mplot3d/scatter3d.py +++ b/examples/mplot3d/scatter3d.py @@ -21,7 +21,7 @@ def randrange(n, vmin, vmax): return (vmax - vmin)*np.random.rand(n) + vmin fig = plt.figure() -ax = fig.add_subplot(111, projection='3d') +ax = fig.add_subplot(projection='3d') n = 100 diff --git a/examples/mplot3d/surface3d_2.py b/examples/mplot3d/surface3d_2.py index 8254ab4b8cfc..d5cfca1905a3 100644 --- a/examples/mplot3d/surface3d_2.py +++ b/examples/mplot3d/surface3d_2.py @@ -11,7 +11,7 @@ fig = plt.figure() -ax = fig.add_subplot(111, projection='3d') +ax = fig.add_subplot(projection='3d') # Make data u = np.linspace(0, 2 * np.pi, 100) diff --git a/examples/mplot3d/surface3d_radial.py b/examples/mplot3d/surface3d_radial.py index 617bcba3557b..c298ddc48864 100644 --- a/examples/mplot3d/surface3d_radial.py +++ b/examples/mplot3d/surface3d_radial.py @@ -15,7 +15,7 @@ fig = plt.figure() -ax = fig.add_subplot(111, projection='3d') +ax = fig.add_subplot(projection='3d') # Create the mesh in polar coordinates and compute corresponding Z. r = np.linspace(0, 1.25, 50) diff --git a/examples/mplot3d/wire3d.py b/examples/mplot3d/wire3d.py index d8e33327663e..7fc0274309ff 100644 --- a/examples/mplot3d/wire3d.py +++ b/examples/mplot3d/wire3d.py @@ -11,7 +11,7 @@ fig = plt.figure() -ax = fig.add_subplot(111, projection='3d') +ax = fig.add_subplot(projection='3d') # Grab some test data. X, Y, Z = axes3d.get_test_data(0.05) diff --git a/examples/mplot3d/wire3d_animation_sgskip.py b/examples/mplot3d/wire3d_animation_sgskip.py index 9e63c8d2b7b3..bc4cccf20a2c 100644 --- a/examples/mplot3d/wire3d_animation_sgskip.py +++ b/examples/mplot3d/wire3d_animation_sgskip.py @@ -23,7 +23,7 @@ def generate(X, Y, phi): fig = plt.figure() -ax = fig.add_subplot(111, projection='3d') +ax = fig.add_subplot(projection='3d') # Make the X, Y meshgrid. xs = np.linspace(-1, 1, 50) diff --git a/examples/pie_and_polar_charts/polar_bar.py b/examples/pie_and_polar_charts/polar_bar.py index 2d9a8dee3252..a833342b532c 100644 --- a/examples/pie_and_polar_charts/polar_bar.py +++ b/examples/pie_and_polar_charts/polar_bar.py @@ -19,7 +19,7 @@ width = np.pi / 4 * np.random.rand(N) colors = plt.cm.viridis(radii / 10.) -ax = plt.subplot(111, projection='polar') +ax = plt.subplot(projection='polar') ax.bar(theta, radii, width=width, bottom=0.0, color=colors, alpha=0.5) plt.show() diff --git a/examples/pie_and_polar_charts/polar_scatter.py b/examples/pie_and_polar_charts/polar_scatter.py index 350369ed3557..5a806ef3d9e5 100644 --- a/examples/pie_and_polar_charts/polar_scatter.py +++ b/examples/pie_and_polar_charts/polar_scatter.py @@ -21,7 +21,7 @@ colors = theta fig = plt.figure() -ax = fig.add_subplot(111, projection='polar') +ax = fig.add_subplot(projection='polar') c = ax.scatter(theta, r, c=colors, s=area, cmap='hsv', alpha=0.75) ############################################################################### @@ -33,7 +33,7 @@ # rotate the plot. fig = plt.figure() -ax = fig.add_subplot(111, polar=True) +ax = fig.add_subplot(polar=True) c = ax.scatter(theta, r, c=colors, s=area, cmap='hsv', alpha=0.75) ax.set_rorigin(-2.5) @@ -47,7 +47,7 @@ # theta start and end limits, producing a sector instead of a full circle. fig = plt.figure() -ax = fig.add_subplot(111, polar=True) +ax = fig.add_subplot(polar=True) c = ax.scatter(theta, r, c=colors, s=area, cmap='hsv', alpha=0.75) ax.set_thetamin(45) diff --git a/examples/pyplots/annotation_polar.py b/examples/pyplots/annotation_polar.py index 534bb54a7760..f09b78f20b2e 100644 --- a/examples/pyplots/annotation_polar.py +++ b/examples/pyplots/annotation_polar.py @@ -12,7 +12,7 @@ import matplotlib.pyplot as plt fig = plt.figure() -ax = fig.add_subplot(111, polar=True) +ax = fig.add_subplot(polar=True) r = np.arange(0, 1, 0.001) theta = 2 * 2*np.pi * r line, = ax.plot(theta, r, color='#ee8d18', lw=3) diff --git a/examples/pyplots/text_commands.py b/examples/pyplots/text_commands.py index 931f549f417e..e144baea1988 100644 --- a/examples/pyplots/text_commands.py +++ b/examples/pyplots/text_commands.py @@ -11,7 +11,7 @@ fig = plt.figure() fig.suptitle('bold figure suptitle', fontsize=14, fontweight='bold') -ax = fig.add_subplot(111) +ax = fig.add_subplot() fig.subplots_adjust(top=0.85) ax.set_title('axes title') diff --git a/examples/pyplots/whats_new_98_4_legend.py b/examples/pyplots/whats_new_98_4_legend.py index 6995fe281ac7..01c773c2c0d4 100644 --- a/examples/pyplots/whats_new_98_4_legend.py +++ b/examples/pyplots/whats_new_98_4_legend.py @@ -9,7 +9,7 @@ import numpy as np -ax = plt.subplot(111) +ax = plt.subplot() t1 = np.arange(0.0, 1.0, 0.01) for n in [1, 2, 3, 4]: plt.plot(t1, t1**n, label=f"n={n}") diff --git a/examples/specialty_plots/skewt.py b/examples/specialty_plots/skewt.py index 852adeac01ae..50167ffb203c 100644 --- a/examples/specialty_plots/skewt.py +++ b/examples/specialty_plots/skewt.py @@ -79,8 +79,7 @@ def _adjust_location(self): # spines and axes instances as appropriate. class SkewXAxes(Axes): # The projection must specify a name. This will be used be the - # user to select the projection, i.e. ``subplot(111, - # projection='skewx')``. + # user to select the projection, i.e. ``subplot(projection='skewx')``. name = 'skewx' def _init_axis(self): @@ -236,7 +235,7 @@ def upper_xlim(self): # Create a new figure. The dimensions here give a good aspect ratio fig = plt.figure(figsize=(6.5875, 6.2125)) - ax = fig.add_subplot(111, projection='skewx') + ax = fig.add_subplot(projection='skewx') plt.grid(True) diff --git a/examples/subplots_axes_and_figures/geo_demo.py b/examples/subplots_axes_and_figures/geo_demo.py index afedcf760e19..562f9d710438 100644 --- a/examples/subplots_axes_and_figures/geo_demo.py +++ b/examples/subplots_axes_and_figures/geo_demo.py @@ -14,28 +14,28 @@ ############################################################################### plt.figure() -plt.subplot(111, projection="aitoff") +plt.subplot(projection="aitoff") plt.title("Aitoff") plt.grid(True) ############################################################################### plt.figure() -plt.subplot(111, projection="hammer") +plt.subplot(projection="hammer") plt.title("Hammer") plt.grid(True) ############################################################################### plt.figure() -plt.subplot(111, projection="lambert") +plt.subplot(projection="lambert") plt.title("Lambert") plt.grid(True) ############################################################################### plt.figure() -plt.subplot(111, projection="mollweide") +plt.subplot(projection="mollweide") plt.title("Mollweide") plt.grid(True) diff --git a/examples/user_interfaces/canvasagg.py b/examples/user_interfaces/canvasagg.py index 9d4f8185d74f..38785b94f65d 100644 --- a/examples/user_interfaces/canvasagg.py +++ b/examples/user_interfaces/canvasagg.py @@ -30,7 +30,7 @@ canvas = FigureCanvasAgg(fig) # Do some plotting. -ax = fig.add_subplot(111) +ax = fig.add_subplot() ax.plot([1, 2, 3]) # Option 1: Save the figure to a file; can also be a file-like object (BytesIO, diff --git a/examples/user_interfaces/embedding_in_gtk3_sgskip.py b/examples/user_interfaces/embedding_in_gtk3_sgskip.py index 510f475a76d5..f5872304964d 100644 --- a/examples/user_interfaces/embedding_in_gtk3_sgskip.py +++ b/examples/user_interfaces/embedding_in_gtk3_sgskip.py @@ -22,7 +22,7 @@ win.set_title("Embedding in GTK") fig = Figure(figsize=(5, 4), dpi=100) -ax = fig.add_subplot(111) +ax = fig.add_subplot() t = np.arange(0.0, 3.0, 0.01) s = np.sin(2*np.pi*t) ax.plot(t, s) diff --git a/examples/user_interfaces/embedding_in_tk_sgskip.py b/examples/user_interfaces/embedding_in_tk_sgskip.py index 6a6cc1605f01..e7342f3dcbf3 100644 --- a/examples/user_interfaces/embedding_in_tk_sgskip.py +++ b/examples/user_interfaces/embedding_in_tk_sgskip.py @@ -21,7 +21,7 @@ fig = Figure(figsize=(5, 4), dpi=100) t = np.arange(0, 3, .01) -fig.add_subplot(111).plot(t, 2 * np.sin(2 * np.pi * t)) +fig.add_subplot().plot(t, 2 * np.sin(2 * np.pi * t)) canvas = FigureCanvasTkAgg(fig, master=root) # A tk.DrawingArea. canvas.draw() diff --git a/examples/user_interfaces/embedding_in_wx2_sgskip.py b/examples/user_interfaces/embedding_in_wx2_sgskip.py index 7c29b32b9063..19580517e9e1 100644 --- a/examples/user_interfaces/embedding_in_wx2_sgskip.py +++ b/examples/user_interfaces/embedding_in_wx2_sgskip.py @@ -23,7 +23,7 @@ def __init__(self): super().__init__(None, -1, 'CanvasFrame', size=(550, 350)) self.figure = Figure() - self.axes = self.figure.add_subplot(111) + self.axes = self.figure.add_subplot() t = np.arange(0.0, 3.0, 0.01) s = np.sin(2 * np.pi * t) diff --git a/examples/user_interfaces/embedding_in_wx3_sgskip.py b/examples/user_interfaces/embedding_in_wx3_sgskip.py index c25c9be7aba2..ec596aba0478 100644 --- a/examples/user_interfaces/embedding_in_wx3_sgskip.py +++ b/examples/user_interfaces/embedding_in_wx3_sgskip.py @@ -54,7 +54,7 @@ def __init__(self, parent): self.Fit() def init_plot_data(self): - ax = self.fig.add_subplot(111) + ax = self.fig.add_subplot() x = np.arange(120.0) * 2 * np.pi / 60.0 y = np.arange(100.0) * 2 * np.pi / 50.0 diff --git a/examples/user_interfaces/embedding_in_wx4_sgskip.py b/examples/user_interfaces/embedding_in_wx4_sgskip.py index 153ca22a0fb4..69922046c49f 100644 --- a/examples/user_interfaces/embedding_in_wx4_sgskip.py +++ b/examples/user_interfaces/embedding_in_wx4_sgskip.py @@ -44,7 +44,7 @@ def __init__(self): super().__init__(None, -1, 'CanvasFrame', size=(550, 350)) self.figure = Figure(figsize=(5, 4), dpi=100) - self.axes = self.figure.add_subplot(111) + self.axes = self.figure.add_subplot() t = np.arange(0.0, 3.0, 0.01) s = np.sin(2 * np.pi * t) diff --git a/examples/user_interfaces/embedding_webagg_sgskip.py b/examples/user_interfaces/embedding_webagg_sgskip.py index d4c0e7e9e6f2..d3a313c6b9ef 100644 --- a/examples/user_interfaces/embedding_webagg_sgskip.py +++ b/examples/user_interfaces/embedding_webagg_sgskip.py @@ -39,7 +39,7 @@ def create_figure(): Creates a simple example figure. """ fig = Figure() - ax = fig.add_subplot(111) + ax = fig.add_subplot() t = np.arange(0.0, 3.0, 0.01) s = np.sin(2 * np.pi * t) ax.plot(t, s) diff --git a/examples/user_interfaces/gtk_spreadsheet_sgskip.py b/examples/user_interfaces/gtk_spreadsheet_sgskip.py index bbeb2b2c7e99..1f0f6e702240 100644 --- a/examples/user_interfaces/gtk_spreadsheet_sgskip.py +++ b/examples/user_interfaces/gtk_spreadsheet_sgskip.py @@ -52,7 +52,7 @@ def __init__(self): self.canvas = FigureCanvas(fig) # a Gtk.DrawingArea vbox.pack_start(self.canvas, True, True, 0) - ax = fig.add_subplot(111) + ax = fig.add_subplot() self.line, = ax.plot(self.data[0, :], 'go') # plot the first row self.treeview.connect('row-activated', self.plot_row) diff --git a/examples/user_interfaces/mathtext_wx_sgskip.py b/examples/user_interfaces/mathtext_wx_sgskip.py index eebf57c2925d..ce305557b6fb 100644 --- a/examples/user_interfaces/mathtext_wx_sgskip.py +++ b/examples/user_interfaces/mathtext_wx_sgskip.py @@ -43,7 +43,7 @@ def __init__(self, parent, title): super().__init__(parent, -1, title, size=(550, 350)) self.figure = Figure() - self.axes = self.figure.add_subplot(111) + self.axes = self.figure.add_subplot() self.canvas = FigureCanvas(self, -1, self.figure) diff --git a/examples/user_interfaces/mpl_with_glade3_sgskip.py b/examples/user_interfaces/mpl_with_glade3_sgskip.py index d437e82df46b..2464c5e04c41 100644 --- a/examples/user_interfaces/mpl_with_glade3_sgskip.py +++ b/examples/user_interfaces/mpl_with_glade3_sgskip.py @@ -32,7 +32,7 @@ def main(): # Start of Matplotlib specific code figure = Figure(figsize=(8, 6), dpi=71) - axis = figure.add_subplot(111) + axis = figure.add_subplot() t = np.arange(0.0, 3.0, 0.01) s = np.sin(2*np.pi*t) axis.plot(t, s) diff --git a/examples/user_interfaces/wxcursor_demo_sgskip.py b/examples/user_interfaces/wxcursor_demo_sgskip.py index 3c8418db298c..e0e318f85679 100644 --- a/examples/user_interfaces/wxcursor_demo_sgskip.py +++ b/examples/user_interfaces/wxcursor_demo_sgskip.py @@ -19,7 +19,7 @@ def __init__(self, ): super().__init__(None, -1, 'CanvasFrame', size=(550, 350)) self.figure = Figure() - self.axes = self.figure.add_subplot(111) + self.axes = self.figure.add_subplot() t = np.arange(0.0, 3.0, 0.01) s = np.sin(2*np.pi*t) diff --git a/examples/widgets/cursor.py b/examples/widgets/cursor.py index 6fa20ca21177..76e7a8d7f40c 100644 --- a/examples/widgets/cursor.py +++ b/examples/widgets/cursor.py @@ -13,7 +13,7 @@ np.random.seed(19680801) fig = plt.figure(figsize=(8, 6)) -ax = fig.add_subplot(111, facecolor='#FFFFCC') +ax = fig.add_subplot(facecolor='#FFFFCC') x, y = 4*(np.random.rand(2, 100) - .5) ax.plot(x, y, 'o') diff --git a/lib/matplotlib/figure.py b/lib/matplotlib/figure.py index 4565a5661f6b..b9c523c8e72e 100644 --- a/lib/matplotlib/figure.py +++ b/lib/matplotlib/figure.py @@ -1368,7 +1368,7 @@ def add_subplot(self, *args, **kwargs): if not args: args = (1, 1, 1) # Normalize correct ijk values to (i, j, k) here so that - # add_subplot(111) == add_subplot(1, 1, 1). Invalid values will + # add_subplot(211) == add_subplot(2, 1, 1). Invalid values will # trigger errors later (via SubplotSpec._from_subplot_args). if (len(args) == 1 and isinstance(args[0], Integral) and 100 <= args[0] <= 999): diff --git a/lib/matplotlib/pyplot.py b/lib/matplotlib/pyplot.py index c5c047471aa8..a8bca37cb3f5 100644 --- a/lib/matplotlib/pyplot.py +++ b/lib/matplotlib/pyplot.py @@ -965,7 +965,7 @@ def axes(arg=None, **kwargs): The exact behavior of this function depends on the type: - *None*: A new full window axes is added using - ``subplot(111, **kwargs)``. + ``subplot(**kwargs)``. - 4-tuple of floats *rect* = ``[left, bottom, width, height]``. A new axes is added with dimensions *rect* in normalized (0, 1) units using `~.Figure.add_axes` on the current figure. @@ -1037,7 +1037,7 @@ def axes(arg=None, **kwargs): """ if arg is None: - return subplot(111, **kwargs) + return subplot(**kwargs) else: return gcf().add_axes(arg, **kwargs) diff --git a/lib/matplotlib/tests/test_arrow_patches.py b/lib/matplotlib/tests/test_arrow_patches.py index cca505ab908b..472c928ae5e1 100644 --- a/lib/matplotlib/tests/test_arrow_patches.py +++ b/lib/matplotlib/tests/test_arrow_patches.py @@ -57,7 +57,7 @@ def __prepare_fancyarrow_dpi_cor_test(): NB: this function *is not* a test in itself! """ fig2 = plt.figure("fancyarrow_dpi_cor_test", figsize=(4, 3), dpi=50) - ax = fig2.add_subplot(111) + ax = fig2.add_subplot() ax.set_xlim([0, 1]) ax.set_ylim([0, 1]) ax.add_patch(mpatches.FancyArrowPatch(posA=(0.3, 0.4), posB=(0.8, 0.6), diff --git a/lib/matplotlib/tests/test_axes.py b/lib/matplotlib/tests/test_axes.py index f9f447f37813..d30c97932e89 100644 --- a/lib/matplotlib/tests/test_axes.py +++ b/lib/matplotlib/tests/test_axes.py @@ -526,7 +526,7 @@ def test_basic_annotate(): # Offset Points fig = plt.figure() - ax = fig.add_subplot(111, autoscale_on=False, xlim=(-1, 5), ylim=(-3, 5)) + ax = fig.add_subplot(autoscale_on=False, xlim=(-1, 5), ylim=(-3, 5)) line, = ax.plot(t, s, lw=3, color='purple') ax.annotate('local max', xy=(3, 1), xycoords='data', @@ -863,7 +863,7 @@ def test_imshow(): # Reuse testcase from above for a labeled data test data = {"r": r} fig = plt.figure() - ax = fig.add_subplot(111) + ax = fig.add_subplot() ax.imshow("r", data=data) @@ -1336,7 +1336,7 @@ def test_markevery(): # check marker only plot fig = plt.figure() - ax = fig.add_subplot(111) + ax = fig.add_subplot() ax.plot(x, y, 'o', label='default') ax.plot(x, y, 'd', markevery=None, label='mark all') ax.plot(x, y, 's', markevery=10, label='mark every 10') @@ -1351,7 +1351,7 @@ def test_markevery_line(): # check line/marker combos fig = plt.figure() - ax = fig.add_subplot(111) + ax = fig.add_subplot() ax.plot(x, y, '-o', label='default') ax.plot(x, y, '-d', markevery=None, label='mark all') ax.plot(x, y, '-s', markevery=10, label='mark every 10') @@ -1466,7 +1466,7 @@ def test_markevery_polar(): def test_marker_edges(): x = np.linspace(0, 1, 10) fig = plt.figure() - ax = fig.add_subplot(111) + ax = fig.add_subplot() ax.plot(x, np.sin(x), 'y.', ms=30.0, mew=0, mec='r') ax.plot(x+0.1, np.sin(x), 'y.', ms=30.0, mew=1, mec='r') ax.plot(x+0.2, np.sin(x), 'y.', ms=30.0, mew=2, mec='b') @@ -1481,7 +1481,7 @@ def test_bar_tick_label_single(): # Reuse testcase from above for a labeled data test data = {"a": 0, "b": 1} fig = plt.figure() - ax = fig.add_subplot(111) + ax = fig.add_subplot() ax = plt.gca() ax.bar("a", "b", align='edge', tick_label='0', data=data) @@ -1684,7 +1684,7 @@ def test_hist_log(): data0 = np.linspace(0, 1, 200)**3 data = np.concatenate([1 - data0, 1 + data0]) fig = plt.figure() - ax = fig.add_subplot(111) + ax = fig.add_subplot() ax.hist(data, fill=False, log=True) @@ -1976,7 +1976,7 @@ def contour_dat(): def test_contour_hatching(): x, y, z = contour_dat() fig = plt.figure() - ax = fig.add_subplot(111) + ax = fig.add_subplot() ax.contourf(x, y, z, 7, hatches=['/', '\\', '//', '-'], cmap=plt.get_cmap('gray'), extend='both', alpha=0.5) @@ -1990,7 +1990,7 @@ def test_contour_colorbar(): x, y, z = contour_dat() fig = plt.figure() - ax = fig.add_subplot(111) + ax = fig.add_subplot() cs = ax.contourf(x, y, z, levels=np.arange(-1.8, 1.801, 0.2), cmap=plt.get_cmap('RdBu'), vmin=-0.6, @@ -2018,13 +2018,13 @@ def test_hist2d(): x = np.random.randn(100)*2+5 y = np.random.randn(100)-2 fig = plt.figure() - ax = fig.add_subplot(111) + ax = fig.add_subplot() ax.hist2d(x, y, bins=10, rasterized=True) # Reuse testcase from above for a labeled data test data = {"x": x, "y": y} fig = plt.figure() - ax = fig.add_subplot(111) + ax = fig.add_subplot() ax.hist2d("x", "y", bins=10, data=data, rasterized=True) @@ -2039,7 +2039,7 @@ def test_hist2d_transpose(): x = np.array([5]*100) y = np.random.randn(100)-2 fig = plt.figure() - ax = fig.add_subplot(111) + ax = fig.add_subplot() ax.hist2d(x, y, bins=10, rasterized=True) @@ -2881,7 +2881,7 @@ def test_boxplot_with_CIarray(): x = np.linspace(-7, 7, 140) x = np.hstack([-25, x, 25]) fig = plt.figure() - ax = fig.add_subplot(111) + ax = fig.add_subplot() CIs = np.array([[-1.5, 3.], [-1., 3.5]]) # show a boxplot with Matplotlib medians and confidence intervals, and @@ -3418,13 +3418,13 @@ def test_hist_stacked_stepfilled(): d1 = np.linspace(1, 3, 20) d2 = np.linspace(0, 10, 50) fig = plt.figure() - ax = fig.add_subplot(111) + ax = fig.add_subplot() ax.hist((d1, d2), histtype="stepfilled", stacked=True) # Reuse testcase from above for a labeled data test data = {"x": (d1, d2)} fig = plt.figure() - ax = fig.add_subplot(111) + ax = fig.add_subplot() ax.hist("x", histtype="stepfilled", stacked=True, data=data) @@ -3434,7 +3434,7 @@ def test_hist_offset(): d1 = np.linspace(0, 10, 50) d2 = np.linspace(1, 3, 20) fig = plt.figure() - ax = fig.add_subplot(111) + ax = fig.add_subplot() ax.hist(d1, bottom=5) ax.hist(d2, bottom=15) @@ -3444,7 +3444,7 @@ def test_hist_step(): # make some data d1 = np.linspace(1, 3, 20) fig = plt.figure() - ax = fig.add_subplot(111) + ax = fig.add_subplot() ax.hist(d1, histtype="step") ax.set_ylim(0, 10) ax.set_xlim(-1, 5) @@ -3456,7 +3456,7 @@ def test_hist_step_horiz(): d1 = np.linspace(0, 10, 50) d2 = np.linspace(1, 3, 20) fig = plt.figure() - ax = fig.add_subplot(111) + ax = fig.add_subplot() ax.hist((d1, d2), histtype="step", orientation="horizontal") @@ -3468,7 +3468,7 @@ def test_hist_stacked_weighted(): w1 = np.linspace(0.01, 3.5, 50) w2 = np.linspace(0.05, 2., 20) fig = plt.figure() - ax = fig.add_subplot(111) + ax = fig.add_subplot() ax.hist((d1, d2), weights=(w1, w2), histtype="stepfilled", stacked=True) @@ -3528,7 +3528,7 @@ def test_hist_stacked_stepfilled_alpha(): d1 = np.linspace(1, 3, 20) d2 = np.linspace(0, 10, 50) fig = plt.figure() - ax = fig.add_subplot(111) + ax = fig.add_subplot() ax.hist((d1, d2), histtype="stepfilled", stacked=True, alpha=0.5) @@ -3538,7 +3538,7 @@ def test_hist_stacked_step(): d1 = np.linspace(1, 3, 20) d2 = np.linspace(0, 10, 50) fig = plt.figure() - ax = fig.add_subplot(111) + ax = fig.add_subplot() ax.hist((d1, d2), histtype="step", stacked=True) @@ -3556,7 +3556,7 @@ def test_hist_step_bottom(): # make some data d1 = np.linspace(1, 3, 20) fig = plt.figure() - ax = fig.add_subplot(111) + ax = fig.add_subplot() ax.hist(d1, bottom=np.arange(10), histtype="stepfilled") @@ -3703,7 +3703,7 @@ def test_hist_stacked_bar(): (0.28302699607823545, 0.0, 1.0), (0.6849123462299822, 0.0, 1.0)] labels = ['green', 'orange', ' yellow', 'magenta', 'black'] fig = plt.figure() - ax = fig.add_subplot(111) + ax = fig.add_subplot() ax.hist(d, bins=10, histtype='barstacked', align='mid', color=colors, label=labels) ax.legend(loc='upper right', bbox_to_anchor=(1.0, 1.0), ncol=1) @@ -3717,7 +3717,7 @@ def test_hist_barstacked_bottom_unchanged(): def test_hist_emptydata(): fig = plt.figure() - ax = fig.add_subplot(111) + ax = fig.add_subplot() ax.hist([[], range(10), range(10)], histtype="step") @@ -3742,7 +3742,7 @@ def test_transparent_markers(): data = np.random.random(50) fig = plt.figure() - ax = fig.add_subplot(111) + ax = fig.add_subplot() ax.plot(data, 'D', mfc='none', markersize=100) @@ -3768,7 +3768,7 @@ def test_mollweide_grid(): # test that both horizontal and vertical gridlines appear on the Mollweide # projection fig = plt.figure() - ax = fig.add_subplot(111, projection='mollweide') + ax = fig.add_subplot(projection='mollweide') ax.grid() @@ -3776,7 +3776,7 @@ def test_mollweide_forward_inverse_closure(): # test that the round-trip Mollweide forward->inverse transformation is an # approximate identity fig = plt.figure() - ax = fig.add_subplot(111, projection='mollweide') + ax = fig.add_subplot(projection='mollweide') # set up 1-degree grid in longitude, latitude lon = np.linspace(-np.pi, np.pi, 360) @@ -3798,7 +3798,7 @@ def test_mollweide_inverse_forward_closure(): # test that the round-trip Mollweide inverse->forward transformation is an # approximate identity fig = plt.figure() - ax = fig.add_subplot(111, projection='mollweide') + ax = fig.add_subplot(projection='mollweide') # set up grid in x, y x = np.linspace(0, 1, 500) @@ -3821,7 +3821,7 @@ def test_alpha(): data = np.random.random(50) fig = plt.figure() - ax = fig.add_subplot(111) + ax = fig.add_subplot() # alpha=.5 markers, solid line ax.plot(data, '-D', color=[1, 0, 0], mfc=[1, 0, 0, .5], @@ -3873,7 +3873,7 @@ def test_eventplot(): linelengths = linelengths1 + linelengths2 fig = plt.figure() - axobj = fig.add_subplot(111) + axobj = fig.add_subplot() colls = axobj.eventplot(data, colors=colors, lineoffsets=lineoffsets, linelengths=linelengths) @@ -3883,7 +3883,7 @@ def test_eventplot(): # Reuse testcase from above for a labeled data test data = {"pos": data, "c": colors, "lo": lineoffsets, "ll": linelengths} fig = plt.figure() - axobj = fig.add_subplot(111) + axobj = fig.add_subplot() colls = axobj.eventplot("pos", colors="c", lineoffsets="lo", linelengths="ll", data=data) num_collections = len(colls) @@ -3903,7 +3903,7 @@ def test_eventplot_defaults(): data = data1 + data2 fig = plt.figure() - axobj = fig.add_subplot(111) + axobj = fig.add_subplot() axobj.eventplot(data) @@ -3947,7 +3947,7 @@ def test_eventplot_problem_kwargs(recwarn): data = [data1, data2] fig = plt.figure() - axobj = fig.add_subplot(111) + axobj = fig.add_subplot() axobj.eventplot(data, colors=['r', 'b'], @@ -3985,7 +3985,7 @@ def test_eventplot_orientation(data, orientation): @image_comparison(['marker_styles.png'], remove_text=True) def test_marker_styles(): fig = plt.figure() - ax = fig.add_subplot(111) + ax = fig.add_subplot() for y, marker in enumerate(sorted(matplotlib.markers.MarkerStyle.markers, key=lambda x: str(type(x))+str(x))): ax.plot((y % 2)*5 + np.arange(10)*10, np.ones(10)*10*y, linestyle='', @@ -4008,7 +4008,7 @@ def test_vertex_markers(): marker_as_tuple = ((-1, -1), (1, -1), (1, 1), (-1, 1)) marker_as_list = [(-1, -1), (1, -1), (1, 1), (-1, 1)] fig = plt.figure() - ax = fig.add_subplot(111) + ax = fig.add_subplot() ax.plot(data, linestyle='', marker=marker_as_tuple, mfc='k') ax.plot(data[::-1], linestyle='', marker=marker_as_list, mfc='b') ax.set_xlim([-1, 10]) @@ -4492,7 +4492,7 @@ def make_patch_spines_invisible(ax): fig = plt.figure(figsize=(4, 3)) fig.subplots_adjust(right=0.75) - host = fig.add_subplot(111) + host = fig.add_subplot() par1 = host.twinx() par2 = host.twinx() @@ -4678,7 +4678,7 @@ def test_relim_visible_only(): y2 = (-10., 30.) fig = matplotlib.figure.Figure() - ax = fig.add_subplot(111) + ax = fig.add_subplot() ax.plot(x1, y1) assert ax.get_xlim() == x1 assert ax.get_ylim() == y1 @@ -5940,7 +5940,7 @@ def test_invalid_axis_limits(): @pytest.mark.parametrize('xscale', ['symlog', 'log']) @pytest.mark.parametrize('yscale', ['symlog', 'log']) def test_minorticks_on(xscale, yscale): - ax = plt.subplot(111) + ax = plt.subplot() ax.plot([1, 2, 3, 4]) ax.set_xscale(xscale) ax.set_yscale(yscale) diff --git a/lib/matplotlib/tests/test_backend_pdf.py b/lib/matplotlib/tests/test_backend_pdf.py index ca5a89ad251f..30c6969fcc42 100644 --- a/lib/matplotlib/tests/test_backend_pdf.py +++ b/lib/matplotlib/tests/test_backend_pdf.py @@ -44,7 +44,7 @@ def test_type42(): rcParams['pdf.fonttype'] = 42 fig = plt.figure() - ax = fig.add_subplot(111) + ax = fig.add_subplot() ax.plot([1, 2, 3]) fig.savefig(io.BytesIO()) @@ -53,7 +53,7 @@ def test_multipage_pagecount(): with PdfPages(io.BytesIO()) as pdf: assert pdf.get_pagecount() == 0 fig = plt.figure() - ax = fig.add_subplot(111) + ax = fig.add_subplot() ax.plot([1, 2, 3]) fig.savefig(pdf, format="pdf") assert pdf.get_pagecount() == 1 @@ -66,7 +66,7 @@ def test_multipage_properfinalize(): with PdfPages(pdfio) as pdf: for i in range(10): fig = plt.figure() - ax = fig.add_subplot(111) + ax = fig.add_subplot() ax.set_title('This is a long title') fig.savefig(pdf, format="pdf") pdfio.seek(0) @@ -88,7 +88,7 @@ def test_multipage_keep_empty(): assert not os.path.exists(filename) # test pdf files with content, they should never be deleted fig = plt.figure() - ax = fig.add_subplot(111) + ax = fig.add_subplot() ax.plot([1, 2, 3]) # test that a non-empty pdf is left behind with keep_empty=True (default) with NamedTemporaryFile(delete=False) as tmp: diff --git a/lib/matplotlib/tests/test_bbox_tight.py b/lib/matplotlib/tests/test_bbox_tight.py index dd7731a6b2ff..dfe1ac7da8bc 100644 --- a/lib/matplotlib/tests/test_bbox_tight.py +++ b/lib/matplotlib/tests/test_bbox_tight.py @@ -87,7 +87,7 @@ def test_bbox_inches_tight_clipping(): def test_bbox_inches_tight_raster(): """Test rasterization with tight_layout""" fig = plt.figure() - ax = fig.add_subplot(111) + ax = fig.add_subplot() ax.plot([1.0, 2.0], rasterized=True) diff --git a/lib/matplotlib/tests/test_colors.py b/lib/matplotlib/tests/test_colors.py index d180fb28afa5..97790de87617 100644 --- a/lib/matplotlib/tests/test_colors.py +++ b/lib/matplotlib/tests/test_colors.py @@ -573,7 +573,7 @@ def test_SymLogNorm_colorbar(): """ norm = mcolors.SymLogNorm(0.1, vmin=-1, vmax=1, linscale=1, base=np.e) fig = plt.figure() - mcolorbar.ColorbarBase(fig.add_subplot(111), norm=norm) + mcolorbar.ColorbarBase(fig.add_subplot(), norm=norm) plt.close(fig) @@ -583,7 +583,7 @@ def test_SymLogNorm_single_zero(): """ fig = plt.figure() norm = mcolors.SymLogNorm(1e-5, vmin=-1, vmax=1, base=np.e) - cbar = mcolorbar.ColorbarBase(fig.add_subplot(111), norm=norm) + cbar = mcolorbar.ColorbarBase(fig.add_subplot(), norm=norm) ticks = cbar.get_ticks() assert sum(ticks == 0) == 1 plt.close(fig) diff --git a/lib/matplotlib/tests/test_constrainedlayout.py b/lib/matplotlib/tests/test_constrainedlayout.py index 4d68b2ed6c43..ab59725c1b82 100644 --- a/lib/matplotlib/tests/test_constrainedlayout.py +++ b/lib/matplotlib/tests/test_constrainedlayout.py @@ -36,7 +36,7 @@ def example_pcolor(ax, fontsize=12): def test_constrained_layout1(): """Test constrained_layout for a single subplot""" fig = plt.figure(constrained_layout=True) - ax = fig.add_subplot(111) + ax = fig.add_subplot() example_plot(ax, fontsize=24) diff --git a/lib/matplotlib/tests/test_dates.py b/lib/matplotlib/tests/test_dates.py index 577af4c972b8..2204be5bf80e 100644 --- a/lib/matplotlib/tests/test_dates.py +++ b/lib/matplotlib/tests/test_dates.py @@ -181,7 +181,7 @@ def test_RRuleLocator(): tf = datetime.datetime(6000, 1, 1) fig = plt.figure() - ax = plt.subplot(111) + ax = plt.subplot() ax.set_autoscale_on(True) ax.plot([t0, tf], [0.0, 1.0], marker='o') @@ -214,7 +214,7 @@ def test_DateFormatter(): tf = datetime.datetime(2001, 1, 1, 0, 0, 1) fig = plt.figure() - ax = plt.subplot(111) + ax = plt.subplot() ax.set_autoscale_on(True) ax.plot([t0, tf], [0.0, 1.0], marker='o') diff --git a/lib/matplotlib/tests/test_image.py b/lib/matplotlib/tests/test_image.py index 77d25b89a625..8c2214038ac3 100644 --- a/lib/matplotlib/tests/test_image.py +++ b/lib/matplotlib/tests/test_image.py @@ -1090,10 +1090,10 @@ def test_image_array_alpha(fig_test, fig_ref): alpha = zz / zz.max() cmap = plt.get_cmap('viridis') - ax = fig_test.add_subplot(111) + ax = fig_test.add_subplot() ax.imshow(zz, alpha=alpha, cmap=cmap, interpolation='nearest') - ax = fig_ref.add_subplot(111) + ax = fig_ref.add_subplot() rgba = cmap(colors.Normalize()(zz)) rgba[..., -1] = alpha ax.imshow(rgba, interpolation='nearest') diff --git a/lib/matplotlib/tests/test_legend.py b/lib/matplotlib/tests/test_legend.py index 6ffe0e7a2535..ac778fcb913a 100644 --- a/lib/matplotlib/tests/test_legend.py +++ b/lib/matplotlib/tests/test_legend.py @@ -37,7 +37,7 @@ def test_legend_ordereddict(): def test_legend_auto1(): """Test automatic legend placement""" fig = plt.figure() - ax = fig.add_subplot(111) + ax = fig.add_subplot() x = np.arange(100) ax.plot(x, 50 - x, 'o', label='y=1') ax.plot(x, x - 50, 'o', label='y=-1') @@ -48,7 +48,7 @@ def test_legend_auto1(): def test_legend_auto2(): """Test automatic legend placement""" fig = plt.figure() - ax = fig.add_subplot(111) + ax = fig.add_subplot() x = np.arange(100) b1 = ax.bar(x, x, align='edge', color='m') b2 = ax.bar(x, x[::-1], align='edge', color='g') @@ -59,7 +59,7 @@ def test_legend_auto2(): def test_legend_auto3(): """Test automatic legend placement""" fig = plt.figure() - ax = fig.add_subplot(111) + ax = fig.add_subplot() x = [0.9, 0.1, 0.1, 0.9, 0.9, 0.5] y = [0.95, 0.95, 0.05, 0.05, 0.5, 0.5] ax.plot(x, y, 'o-', label='line') @@ -83,7 +83,7 @@ def test_various_labels(): def test_labels_first(): # test labels to left of markers fig = plt.figure() - ax = fig.add_subplot(111) + ax = fig.add_subplot() ax.plot(np.arange(10), '-o', label=1) ax.plot(np.ones(10)*5, ':x', label="x") ax.plot(np.arange(20, 10, -1), 'd', label="diamond") @@ -94,7 +94,7 @@ def test_labels_first(): def test_multiple_keys(): # test legend entries with multiple keys fig = plt.figure() - ax = fig.add_subplot(111) + ax = fig.add_subplot() p1, = ax.plot([1, 2, 3], '-o') p2, = ax.plot([2, 3, 4], '-x') p3, = ax.plot([3, 4, 5], '-d') @@ -391,7 +391,7 @@ def test_legend_stackplot(): """Test legend for PolyCollection using stackplot.""" # related to #1341, #1943, and PR #3303 fig = plt.figure() - ax = fig.add_subplot(111) + ax = fig.add_subplot() x = np.linspace(0, 10, 10) y1 = 1.0 * x y2 = 2.0 * x + 1 diff --git a/lib/matplotlib/tests/test_lines.py b/lib/matplotlib/tests/test_lines.py index 0fe5b58a0de4..42e81ca30282 100644 --- a/lib/matplotlib/tests/test_lines.py +++ b/lib/matplotlib/tests/test_lines.py @@ -47,7 +47,7 @@ def test_invisible_Line_rendering(): # Create a plot figure: fig = plt.figure() - ax = plt.subplot(111) + ax = plt.subplot() # Create a "big" Line instance: l = mlines.Line2D(x, y) diff --git a/lib/matplotlib/tests/test_patches.py b/lib/matplotlib/tests/test_patches.py index baff5dabccaa..1feafa775c94 100644 --- a/lib/matplotlib/tests/test_patches.py +++ b/lib/matplotlib/tests/test_patches.py @@ -88,7 +88,7 @@ def test_negative_rect(): def test_clip_to_bbox(): fig = plt.figure() - ax = fig.add_subplot(111) + ax = fig.add_subplot() ax.set_xlim([-18, 20]) ax.set_ylim([-150, 100]) diff --git a/lib/matplotlib/tests/test_patheffects.py b/lib/matplotlib/tests/test_patheffects.py index 2592796b33af..34462fa0d179 100644 --- a/lib/matplotlib/tests/test_patheffects.py +++ b/lib/matplotlib/tests/test_patheffects.py @@ -9,7 +9,7 @@ @image_comparison(['patheffect1'], remove_text=True) def test_patheffect1(): - ax1 = plt.subplot(111) + ax1 = plt.subplot() ax1.imshow([[1, 2], [2, 3]]) txt = ax1.annotate("test", (1., 1.), (0., 0), arrowprops=dict(arrowstyle="->", @@ -28,7 +28,7 @@ def test_patheffect1(): @image_comparison(['patheffect2'], remove_text=True, style='mpl20') def test_patheffect2(): - ax2 = plt.subplot(111) + ax2 = plt.subplot() arr = np.arange(25).reshape((5, 5)) ax2.imshow(arr, interpolation='nearest') cntr = ax2.contour(arr, colors="k") diff --git a/lib/matplotlib/tests/test_pickle.py b/lib/matplotlib/tests/test_pickle.py index e3bd7eeee185..5c169cb23303 100644 --- a/lib/matplotlib/tests/test_pickle.py +++ b/lib/matplotlib/tests/test_pickle.py @@ -138,7 +138,7 @@ def test_image(): def test_polar(): - plt.subplot(111, polar=True) + plt.subplot(polar=True) fig = plt.gcf() pf = pickle.dumps(fig) pickle.loads(pf) diff --git a/lib/matplotlib/tests/test_polar.py b/lib/matplotlib/tests/test_polar.py index da9a77c82502..9f50c6890400 100644 --- a/lib/matplotlib/tests/test_polar.py +++ b/lib/matplotlib/tests/test_polar.py @@ -25,7 +25,7 @@ def test_polar_annotations(): theta = 2.0 * 2.0 * np.pi * r fig = plt.figure() - ax = fig.add_subplot(111, polar=True) + ax = fig.add_subplot(polar=True) line, = ax.plot(theta, r, color='#ee8d18', lw=3) line, = ax.plot((0, 0), (0, 1), color="#0000ff", lw=1) @@ -52,7 +52,7 @@ def test_polar_coord_annotations(): el = mpl.patches.Ellipse((0, 0), 10, 20, facecolor='r', alpha=0.5) fig = plt.figure() - ax = fig.add_subplot(111, aspect='equal') + ax = fig.add_subplot(aspect='equal') ax.add_artist(el) el.set_clip_box(ax.bbox) @@ -217,7 +217,7 @@ def test_polar_theta_position(): @image_comparison(['polar_rlabel_position'], style='default') def test_polar_rlabel_position(): fig = plt.figure() - ax = fig.add_subplot(111, projection='polar') + ax = fig.add_subplot(projection='polar') ax.set_rlabel_position(315) ax.tick_params(rotation='auto') @@ -299,7 +299,7 @@ def test_polar_not_datalim_adjustable(): def test_polar_gridlines(): fig = plt.figure() - ax = fig.add_subplot(111, polar=True) + ax = fig.add_subplot(polar=True) # make all major grid lines lighter, only x grid lines set in 2.1.0 ax.grid(alpha=0.2) # hide y tick labels, no effect in 2.1.0 diff --git a/lib/matplotlib/tests/test_skew.py b/lib/matplotlib/tests/test_skew.py index 3b05b8c44fb5..7ac1c049f8cd 100644 --- a/lib/matplotlib/tests/test_skew.py +++ b/lib/matplotlib/tests/test_skew.py @@ -69,8 +69,7 @@ def _adjust_location(self): # spines and axes instances as appropriate. class SkewXAxes(Axes): # The projection must specify a name. This will be used be the - # user to select the projection, i.e. ``subplot(111, - # projection='skewx')``. + # user to select the projection, i.e. ``subplot(projection='skewx')``. name = 'skewx' def _init_axis(self): diff --git a/lib/matplotlib/tests/test_tightlayout.py b/lib/matplotlib/tests/test_tightlayout.py index cc928005c15b..96c478de5768 100644 --- a/lib/matplotlib/tests/test_tightlayout.py +++ b/lib/matplotlib/tests/test_tightlayout.py @@ -68,7 +68,7 @@ def test_tight_layout4(): @image_comparison(['tight_layout5']) def test_tight_layout5(): """Test tight_layout for image.""" - ax = plt.subplot(111) + ax = plt.subplot() arr = np.arange(100).reshape((10, 10)) ax.imshow(arr, interpolation="none") plt.tight_layout() @@ -135,7 +135,7 @@ def test_tight_layout8(): """Test automatic use of tight_layout.""" fig = plt.figure() fig.set_tight_layout({'pad': .1}) - ax = fig.add_subplot(111) + ax = fig.add_subplot() example_plot(ax, fontsize=24) diff --git a/lib/matplotlib/tests/test_usetex.py b/lib/matplotlib/tests/test_usetex.py index 5e4d1ff7edba..b57fbe887188 100644 --- a/lib/matplotlib/tests/test_usetex.py +++ b/lib/matplotlib/tests/test_usetex.py @@ -17,7 +17,7 @@ def test_usetex(): mpl.rcParams['text.usetex'] = True fig = plt.figure() - ax = fig.add_subplot(111) + ax = fig.add_subplot() kwargs = {"verticalalignment": "baseline", "size": 24, "bbox": dict(pad=0, edgecolor="k", facecolor="none")} ax.text(0.2, 0.7, diff --git a/lib/matplotlib/widgets.py b/lib/matplotlib/widgets.py index 4371701e13db..6f0d4c40e305 100644 --- a/lib/matplotlib/widgets.py +++ b/lib/matplotlib/widgets.py @@ -2386,7 +2386,7 @@ class LassoSelector(_SelectorWidget): Example usage:: - ax = subplot(111) + ax = plt.subplot() ax.plot(x, y) def onselect(verts): diff --git a/lib/mpl_toolkits/tests/test_mplot3d.py b/lib/mpl_toolkits/tests/test_mplot3d.py index 27919e011701..68276d37fbbc 100644 --- a/lib/mpl_toolkits/tests/test_mplot3d.py +++ b/lib/mpl_toolkits/tests/test_mplot3d.py @@ -20,7 +20,7 @@ def test_aspect_equal_error(): fig = plt.figure() - ax = fig.add_subplot(111, projection='3d') + ax = fig.add_subplot(projection='3d') with pytest.raises(NotImplementedError): ax.set_aspect('equal') @@ -28,7 +28,7 @@ def test_aspect_equal_error(): @mpl3d_image_comparison(['bar3d.png']) def test_bar3d(): fig = plt.figure() - ax = fig.add_subplot(111, projection='3d') + ax = fig.add_subplot(projection='3d') for c, z in zip(['r', 'g', 'b', 'y'], [30, 20, 10, 0]): xs = np.arange(20) ys = np.arange(20) @@ -39,7 +39,7 @@ def test_bar3d(): def test_bar3d_colors(): fig = plt.figure() - ax = fig.add_subplot(111, projection='3d') + ax = fig.add_subplot(projection='3d') for c in ['red', 'green', 'blue', 'yellow']: xs = np.arange(len(c)) ys = np.zeros_like(xs) @@ -72,7 +72,7 @@ def test_bar3d_shaded(): @mpl3d_image_comparison(['bar3d_notshaded.png']) def test_bar3d_notshaded(): fig = plt.figure() - ax = fig.add_subplot(111, projection='3d') + ax = fig.add_subplot(projection='3d') x = np.arange(4) y = np.arange(5) x2d, y2d = np.meshgrid(x, y) @@ -225,7 +225,7 @@ def test_tight_layout_text(fig_test, fig_ref): @mpl3d_image_comparison(['scatter3d.png']) def test_scatter3d(): fig = plt.figure() - ax = fig.add_subplot(111, projection='3d') + ax = fig.add_subplot(projection='3d') ax.scatter(np.arange(10), np.arange(10), np.arange(10), c='r', marker='o') x = y = z = np.arange(10, 20) @@ -236,7 +236,7 @@ def test_scatter3d(): @mpl3d_image_comparison(['scatter3d_color.png']) def test_scatter3d_color(): fig = plt.figure() - ax = fig.add_subplot(111, projection='3d') + ax = fig.add_subplot(projection='3d') # Check that 'none' color works; these two should overlay to produce the # same as setting just `color`. @@ -353,7 +353,7 @@ def test_marker_draw_order_view_rotated(fig_test, fig_ref): @mpl3d_image_comparison(['plot_3d_from_2d.png'], tol=0.01) def test_plot_3d_from_2d(): fig = plt.figure() - ax = fig.add_subplot(111, projection='3d') + ax = fig.add_subplot(projection='3d') xs = np.arange(0, 5) ys = np.arange(5, 10) ax.plot(xs, ys, zs=0, zdir='x') @@ -480,7 +480,7 @@ def test_trisurf3d_shaded(): @mpl3d_image_comparison(['wireframe3d.png']) def test_wireframe3d(): fig = plt.figure() - ax = fig.add_subplot(111, projection='3d') + ax = fig.add_subplot(projection='3d') X, Y, Z = axes3d.get_test_data(0.05) ax.plot_wireframe(X, Y, Z, rcount=13, ccount=13) @@ -488,7 +488,7 @@ def test_wireframe3d(): @mpl3d_image_comparison(['wireframe3dzerocstride.png']) def test_wireframe3dzerocstride(): fig = plt.figure() - ax = fig.add_subplot(111, projection='3d') + ax = fig.add_subplot(projection='3d') X, Y, Z = axes3d.get_test_data(0.05) ax.plot_wireframe(X, Y, Z, rcount=13, ccount=0) @@ -496,14 +496,14 @@ def test_wireframe3dzerocstride(): @mpl3d_image_comparison(['wireframe3dzerorstride.png']) def test_wireframe3dzerorstride(): fig = plt.figure() - ax = fig.add_subplot(111, projection='3d') + ax = fig.add_subplot(projection='3d') X, Y, Z = axes3d.get_test_data(0.05) ax.plot_wireframe(X, Y, Z, rstride=0, cstride=10) def test_wireframe3dzerostrideraises(): fig = plt.figure() - ax = fig.add_subplot(111, projection='3d') + ax = fig.add_subplot(projection='3d') X, Y, Z = axes3d.get_test_data(0.05) with pytest.raises(ValueError): ax.plot_wireframe(X, Y, Z, rstride=0, cstride=0) @@ -511,7 +511,7 @@ def test_wireframe3dzerostrideraises(): def test_mixedsamplesraises(): fig = plt.figure() - ax = fig.add_subplot(111, projection='3d') + ax = fig.add_subplot(projection='3d') X, Y, Z = axes3d.get_test_data(0.05) with pytest.raises(ValueError): ax.plot_wireframe(X, Y, Z, rstride=10, ccount=50) @@ -865,7 +865,7 @@ def test_axes3d_ortho(): def test_invalid_axes_limits(setter, side, value): limit = {side: value} fig = plt.figure() - obj = fig.add_subplot(111, projection='3d') + obj = fig.add_subplot(projection='3d') with pytest.raises(ValueError): getattr(obj, setter)(**limit) @@ -996,7 +996,7 @@ def test_line3d_set_get_data_3d(): x, y, z = [0, 1], [2, 3], [4, 5] x2, y2, z2 = [6, 7], [8, 9], [10, 11] fig = plt.figure() - ax = fig.add_subplot(111, projection='3d') + ax = fig.add_subplot(projection='3d') lines = ax.plot(x, y, z) line = lines[0] np.testing.assert_array_equal((x, y, z), line.get_data_3d()) @@ -1159,7 +1159,7 @@ def test_equal_box_aspect(): from itertools import product, combinations fig = plt.figure() - ax = fig.add_subplot(111, projection="3d") + ax = fig.add_subplot(projection="3d") # Make data u = np.linspace(0, 2 * np.pi, 100) diff --git a/tutorials/advanced/transforms_tutorial.py b/tutorials/advanced/transforms_tutorial.py index 47ae908e2d5c..09bedc428814 100644 --- a/tutorials/advanced/transforms_tutorial.py +++ b/tutorials/advanced/transforms_tutorial.py @@ -492,7 +492,7 @@ # # .. sourcecode:: ipython # -# In [80]: ax = subplot(111) +# In [80]: ax = plt.subplot() # # In [81]: ax.set_xlim(0, 10) # Out[81]: (0, 10) diff --git a/tutorials/intermediate/artists.py b/tutorials/intermediate/artists.py index 3cd33dac168f..6733ed55a796 100644 --- a/tutorials/intermediate/artists.py +++ b/tutorials/intermediate/artists.py @@ -383,7 +383,7 @@ class in the matplotlib API, and the one you will be working with most # :class:`~matplotlib.patches.Circle` for polar coordinates; this patch # determines the shape, background and border of the plotting region:: # -# ax = fig.add_subplot(111) +# ax = fig.add_subplot() # rect = ax.patch # a Rectangle instance # rect.set_facecolor('green') # diff --git a/tutorials/intermediate/tight_layout_guide.py b/tutorials/intermediate/tight_layout_guide.py index c8234fa881c7..5ea7da4fce60 100644 --- a/tutorials/intermediate/tight_layout_guide.py +++ b/tutorials/intermediate/tight_layout_guide.py @@ -143,7 +143,7 @@ def example_plot(ax, fontsize=12): plt.close('all') fig = plt.figure(figsize=(5, 4)) -ax = plt.subplot(111) +ax = plt.subplot() im = ax.imshow(arr, interpolation="none") plt.tight_layout() diff --git a/tutorials/introductory/pyplot.py b/tutorials/introductory/pyplot.py index d9880e83ea8f..33a902db7b53 100644 --- a/tutorials/introductory/pyplot.py +++ b/tutorials/introductory/pyplot.py @@ -258,10 +258,10 @@ def f(t): plt.show() ############################################################################### -# The `~.pyplot.figure` call here is optional because -# ``figure(1)`` will be created by default, just as a ``subplot(111)`` -# will be created by default if you don't manually specify any axes. The -# `~.pyplot.subplot` call specifies ``numrows, +# The `~.pyplot.figure` call here is optional because a figure will be created +# if none exists, just as an axes will be created (equivalent to an explicit +# ``subplot()`` call) if none exists. +# The `~.pyplot.subplot` call specifies ``numrows, # numcols, plot_number`` where ``plot_number`` ranges from 1 to # ``numrows*numcols``. The commas in the ``subplot`` call are # optional if ``numrows*numcols<10``. So ``subplot(211)`` is identical @@ -291,7 +291,7 @@ def f(t): # # # plt.figure(2) # a second figure -# plt.plot([4, 5, 6]) # creates a subplot(111) by default +# plt.plot([4, 5, 6]) # creates a subplot() by default # # plt.figure(1) # figure 1 current; subplot(212) still current # plt.subplot(211) # make subplot(211) in figure1 current @@ -380,7 +380,7 @@ def f(t): # the argument ``xy`` and the location of the text ``xytext``. Both of # these arguments are ``(x, y)`` tuples. -ax = plt.subplot(111) +ax = plt.subplot() t = np.arange(0.0, 5.0, 0.01) s = np.cos(2*np.pi*t) diff --git a/tutorials/text/text_intro.py b/tutorials/text/text_intro.py index 507e86cf141a..10432971e151 100644 --- a/tutorials/text/text_intro.py +++ b/tutorials/text/text_intro.py @@ -69,7 +69,7 @@ import matplotlib.pyplot as plt fig = plt.figure() -ax = fig.add_subplot(111) +ax = fig.add_subplot() fig.subplots_adjust(top=0.85) # Set titles for the figure and the subplot respectively diff --git a/tutorials/toolkits/axes_grid.py b/tutorials/toolkits/axes_grid.py index e78a38313838..e55555a4aab3 100644 --- a/tutorials/toolkits/axes_grid.py +++ b/tutorials/toolkits/axes_grid.py @@ -128,7 +128,7 @@ The :doc:`/gallery/lines_bars_and_markers/scatter_hist` example can be rewritten using `~.axes_grid1.axes_divider.make_axes_locatable`:: - axScatter = subplot(111) + axScatter = plt.subplot() axScatter.scatter(x, y) axScatter.set_aspect(1.) diff --git a/tutorials/toolkits/mplot3d.py b/tutorials/toolkits/mplot3d.py index 56f0edaf5a8b..d5ab4f2b10b6 100644 --- a/tutorials/toolkits/mplot3d.py +++ b/tutorials/toolkits/mplot3d.py @@ -19,7 +19,7 @@ import matplotlib.pyplot as plt fig = plt.figure() - ax = fig.add_subplot(111, projection='3d') + ax = fig.add_subplot(projection='3d') .. versionchanged:: 1.0.0 Prior to Matplotlib 1.0.0, `.Axes3D` needed to be directly instantiated with