From 8774ce4dc6cf5f4b2d245b3eb930168f18455616 Mon Sep 17 00:00:00 2001 From: Steffen Rehberg Date: Mon, 29 Nov 2021 15:09:16 +0100 Subject: [PATCH 1/4] Minor fixes in Basic Usage tutorial MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - fix typos and PEP8 (line 338) - apply terminology and unify capitalization acc. to https://matplotlib.org/stable/devel/style_guide.html#terminology - replace -- by en dash (–), as smartquotes is set to False in conf.py - explicitly apply ConciseDateFormatter so that it's clear why the date axis is formatted the way it is(examples\ticks\date_concise_formatter.py registers the ConciseDateConverter and when the documentation is being built, this example is processed before the tutorials and hence the registered converter is still in effect) - remove redundant redefinition of x at line 246 and move definition of xdata at line 208 to where it is used --- tutorials/introductory/usage.py | 132 ++++++++++++++++---------------- 1 file changed, 67 insertions(+), 65 deletions(-) diff --git a/tutorials/introductory/usage.py b/tutorials/introductory/usage.py index 5f9f386a01ff..a819a79ea632 100644 --- a/tutorials/introductory/usage.py +++ b/tutorials/introductory/usage.py @@ -21,8 +21,8 @@ # widgets, etc.), each of which can contain one or more `~.axes.Axes`, an # area where points can be specified in terms of x-y coordinates (or theta-r # in a polar plot, x-y-z in a 3D plot, etc). The simplest way of -# creating a figure with an axes is using `.pyplot.subplots`. We can then use -# `.Axes.plot` to draw some data on the axes: +# creating a Figure with an Axes is using `.pyplot.subplots`. We can then use +# `.Axes.plot` to draw some data on the Axes: fig, ax = plt.subplots() # Create a figure containing a single axes. ax.plot([1, 2, 3, 4], [1, 4, 2, 3]); # Plot some data on the axes. @@ -33,33 +33,33 @@ # Parts of a Figure # ================= # -# Here are the components of a Matplotlib figure. +# Here are the components of a Matplotlib Figure. # # .. image:: ../../_static/anatomy.png # # :class:`~matplotlib.figure.Figure` # ---------------------------------- # -# The **whole** figure. The figure keeps +# The **whole** figure. The Figure keeps # track of all the child :class:`~matplotlib.axes.Axes`, a group of -# 'special' artists (titles, figure legends, colorbars, etc), and +# 'special' Artists (titles, figure legends, colorbars, etc), and # even nested subfigures. # -# The easiest way to create a new figure is with pyplot:: +# The easiest way to create a new Figure is with pyplot:: # # fig = plt.figure() # an empty figure with no Axes # fig, ax = plt.subplots() # a figure with a single Axes # fig, axs = plt.subplots(2, 2) # a figure with a 2x2 grid of Axes # -# It is often convenient to create the axes together with the figure, but you -# can also manually add axes later on. Note that many +# It is often convenient to create the Axes together with the Figure, but you +# can also manually add Axes later on. Note that many # :doc:`Matplotlib backends ` support zooming and # panning on figure windows. # # :class:`~matplotlib.axes.Axes` # ------------------------------ # -# An Axes is an artist attached to a figure that contains a region for +# An Axes is an Artist attached to a Figure that contains a region for # plotting data, and usually includes two (or three in the case of 3D) # :class:`~matplotlib.axis.Axis` objects (be aware of the difference # between **Axes** and **Axis**) that provide ticks and tick labels to @@ -70,7 +70,7 @@ # :meth:`~matplotlib.axes.Axes.set_ylabel`). # # The :class:`~.axes.Axes` class and its member functions are the primary -# entry point to working with the OO interface, and have most of the +# entry point to working with the OOP interface, and have most of the # plotting methods defined on them (e.g. ``ax.plot()``, shown above, uses # the `~.Axes.plot` method) # @@ -78,7 +78,7 @@ # ------------------------------ # # These objects set the scale and limits and generate ticks (the marks -# on the axis) and ticklabels (strings labeling the ticks). The location +# on the Axis) and ticklabels (strings labeling the ticks). The location # of the ticks is determined by a `~matplotlib.ticker.Locator` object and the # ticklabel strings are formatted by a `~matplotlib.ticker.Formatter`. The # combination of the correct `.Locator` and `.Formatter` gives very fine @@ -87,11 +87,11 @@ # :class:`~matplotlib.artist.Artist` # ---------------------------------- # -# Basically, everything visible on the figure is an artist (even +# Basically, everything visible on the Figure is an Artist (even # `.Figure`, `Axes <.axes.Axes>`, and `~.axis.Axis` objects). This includes # `.Text` objects, `.Line2D` objects, :mod:`.collections` objects, `.Patch` -# objects, etc... When the figure is rendered, all of the -# artists are drawn to the **canvas**. Most Artists are tied to an Axes; such +# objects, etc. When the Figure is rendered, all of the +# Artists are drawn to the **canvas**. Most Artists are tied to an Axes; such # an Artist cannot be shared by multiple Axes, or moved from one to another. # # .. _input_types: @@ -109,7 +109,7 @@ # b = np.matrix([[1, 2], [3, 4]]) # b_asarray = np.asarray(b) # -# Most methods will also parse an addressible object like a *dict*, a +# Most methods will also parse an addressable object like a *dict*, a # `numpy.recarray`, or a `pandas.DataFrame`. Matplotlib allows you provide # the ``data`` keyword argument and generate plots passing the strings # corresponding to the *x* and *y* variables. @@ -131,21 +131,22 @@ # Coding styles # ============= # -# The object-oriented and the pyplot interfaces -# --------------------------------------------- +# The explicit and the implicit approach of programming +# ----------------------------------------------------- # # As noted above, there are essentially two ways to use Matplotlib: # -# - Explicitly create figures and axes, and call methods on them (the -# "object-oriented (OO) style"). -# - Rely on pyplot to automatically create and manage the figures and axes, and -# use pyplot functions for plotting. +# - Explicitly create Figures and Axes, and call methods on them (the explicit +# or "object oriented programming (OOP) style"). +# - Rely on pyplot to automatically create and manage the Figures and Axes, and +# use pyplot functions for plotting (the implicit style). # -# So one can use the OO-style +# So one can use the explicit style x = np.linspace(0, 2, 100) # Sample data. -# Note that even in the OO-style, we use `.pyplot.figure` to create the figure. +# Note that even in the explicit style, we use `.pyplot.figure` to create the +# Figure. fig, ax = plt.subplots(figsize=(5, 2.7), constrained_layout=True) ax.plot(x, x, label='linear') # Plot some data on the axes. ax.plot(x, x**2, label='quadratic') # Plot more data on the axes... @@ -156,7 +157,7 @@ ax.legend(); # Add a legend. ############################################################################### -# or the pyplot-style: +# or the implicit style: x = np.linspace(0, 2, 100) # Sample data. @@ -175,11 +176,11 @@ # figure creation. See the corresponding section in the gallery for more info: # :ref:`user_interfaces`.) # -# Matplotlib's documentation and examples use both the OO and the pyplot -# styles. In general, we suggest using the OO style, particularly for -# complicated plots, and functions and scripts that are intended to be reused -# as part of a larger project. However, the pyplot style can be very -# conveneient for quick interactive work. +# Matplotlib's documentation and examples use both the explicit and the +# implicit styles. In general, we suggest using the explicit style, +# particularly for complicated plots, and functions and scripts that are +# intended to be reused as part of a larger project. However, the implicit +# style can be very convenient for quick interactive work. # # .. note:: # @@ -205,14 +206,13 @@ def my_plotter(ax, data1, data2, param_dict): # which you would then use twice to populate two subplots: data1, data2, data3, data4 = np.random.randn(4, 100) # make 4 random data sets -xdata = np.arange(len(data1)) # make an ordinal for this fig, (ax1, ax2) = plt.subplots(1, 2, figsize=(5, 2.7)) my_plotter(ax1, data1, data2, {'marker': 'x'}) my_plotter(ax2, data3, data4, {'marker': 'o'}); ############################################################################### # Note that if you want to install these as a python package, or any other -# customizations you could use use one of the many templates on the web; +# customizations you could use one of the many templates on the web; # Matplotlib has one at `mpl-cookiecutter # `_ # @@ -221,9 +221,9 @@ def my_plotter(ax, data1, data2, param_dict): # =============== # # Most plotting methods have styling options for the Artists, accessible either -# when a plotting method is called, or from a "setter" on the artist. In the -# plot below we manaully set the *color*, *linewidth*, and *linestyle* of the -# artists created by `~.Axes.plot`, and we set the linestyle of the second line +# when a plotting method is called, or from a "setter" on the Artist. In the +# plot below we manually set the *color*, *linewidth*, and *linestyle* of the +# Artists created by `~.Axes.plot`, and we set the linestyle of the second line # after the fact with `~.Line2D.set_linestyle`. fig, ax = plt.subplots(figsize=(5, 2.7)) @@ -237,13 +237,12 @@ def my_plotter(ax, data1, data2, param_dict): # ------ # # Matplotlib has a very flexible array of colors that are accepted for most -# artists; see the :doc:`colors tutorial ` for a +# Artists; see the :doc:`colors tutorial ` for a # list of specifications. Some Artists will take multiple colors. i.e. for # a `~.Axes.scatter` plot, the edge of the markers can be different colors # from the interior: fig, ax = plt.subplots(figsize=(5, 2.7)) -x = np.arange(len(data1)) ax.scatter(data1, data2, s=50, facecolor='C0', edgecolor='k'); ############################################################################### @@ -251,7 +250,7 @@ def my_plotter(ax, data1, data2, param_dict): # --------------------------------------- # # Line widths are typically in typographic points (1 pt = 1/72 inch) and -# available for artists that have stroked lines. Similarly, stroked lines +# available for Artists that have stroked lines. Similarly, stroked lines # can have a linestyle. See the :doc:`linestyles example # `. # @@ -318,21 +317,21 @@ def my_plotter(ax, data1, data2, param_dict): # where the ``r`` preceding the title string signifies that the string is a # *raw* string and not to treat backslashes as python escapes. # Matplotlib has a built-in TeX expression parser and -# layout engine, and ships its own math fonts -- for details see +# layout engine, and ships its own math fonts – for details see # :doc:`/tutorials/text/mathtext`. You can also use LaTeX directly to format # your text and incorporate the output directly into your display figures or -# saved postscript -- see :doc:`/tutorials/text/usetex`. +# saved postscript – see :doc:`/tutorials/text/usetex`. # # Annotations # ----------- # -# We can also annotate points on a plot, odten by connecting an arrow pointing +# We can also annotate points on a plot, often by connecting an arrow pointing # to *xy*, to a piece of text at *xytext*: fig, ax = plt.subplots(figsize=(5, 2.7)) t = np.arange(0.0, 5.0, 0.01) -s = np.cos(2*np.pi*t) +s = np.cos(2 * np.pi * t) line, = ax.plot(t, s, lw=2) ax.annotate('local max', xy=(2, 1), xytext=(3, 1.5), @@ -366,9 +365,9 @@ def my_plotter(ax, data1, data2, param_dict): # Axis scales and ticks # ===================== # -# Each Axes has two (or three) `~.axis.Axis` objects represnting the x- and -# y-axis. These control the *scale* of the axis, the tick *Locators* and the -# tick *Formatters*. +# Each Axes has two (or three) `~.axis.Axis` objects representing the x- and +# y-axis. These control the *scale* of the Axis, the tick *locators* and the +# tick *formatters*. # # Scales # ------ @@ -381,6 +380,7 @@ def my_plotter(ax, data1, data2, param_dict): # manually: fig, axs = plt.subplots(1, 2, figsize=(5, 2.7), constrained_layout=True) +xdata = np.arange(len(data1)) # make an ordinal for this data = 10**data1 axs[0].plot(xdata, data) @@ -390,14 +390,15 @@ def my_plotter(ax, data1, data2, param_dict): ############################################################################## # The scale sets the mapping from data values to spacing along the Axis. This # happens in both directions, and gets combined into a *transform*, which -# is the way that Matplotlib maps from data co-ordinates to Axes, Figure, or -# screen co-ordinates. See :doc:`/tutorials/advanced/transforms_tutorial`. +# is the way that Matplotlib maps from data coordinates to Axes, Figure, or +# screen coordinates. See :doc:`/tutorials/advanced/transforms_tutorial`. # # Tick locators and formatters # ---------------------------- # # Each Axis has a tick *locator* and *formatter* that choose where along the -# axes to put tick marks. A simple interface to this is `~.Axes.set_xticks`: +# Axis objects to put tick marks. A simple interface to this is +# `~.Axes.set_xticks`: fig, axs = plt.subplots(2, 1, constrained_layout=True) axs[0].plot(xdata, data1) @@ -422,11 +423,13 @@ def my_plotter(ax, data1, data2, param_dict): # well as floating point numbers. These get special locators and formatters # as appropriate. For dates: -fig, ax = plt.subplots(figsize=(5, 3.7), constrained_layout=True) +fig, ax = plt.subplots(figsize=(5, 2.7), constrained_layout=True) dates = np.arange(np.datetime64('2021-11-15'), np.datetime64('2021-12-25'), np.timedelta64(1, 'h')) data = np.cumsum(np.random.randn(len(dates))) -ax.plot(dates, data); +ax.plot(dates, data) +cdf = mpl.dates.ConciseDateFormatter(ax.xaxis.get_major_locator()) +ax.xaxis.set_major_formatter(cdf); ############################################################################## # For more information see the date examples @@ -436,7 +439,7 @@ def my_plotter(ax, data1, data2, param_dict): # :doc:`/gallery/lines_bars_and_markers/categorical_variables`). fig, ax = plt.subplots(figsize=(5, 2.7), constrained_layout=True) -categories = ['turnips', 'rutabega', 'cucumber', 'pumpkins'] +categories = ['turnips', 'rutabaga', 'cucumber', 'pumpkins'] ax.bar(categories, np.random.rand(len(categories))); @@ -499,36 +502,35 @@ def my_plotter(ax, data1, data2, param_dict): # Adding a `~.Figure.colorbar` gives a key to relate the color back to the # underlying data. Colorbars are figure-level Artists, and are attached to # a ScalarMappable (where they get their information about the norm and -# colormap) and usually steal space from a parent axes. Placement of +# colormap) and usually steal space from a parent Axes. Placement of # colorbars can be complex: see # :doc:`/gallery/subplots_axes_and_figures/colorbar_placement` for # details. You can also change the appearance of colorbars with the # *extend* keyword to add arrows to the ends, and *shrink* and *aspect* to -# control the size. Finally, the colorbar will have default Locators -# and Formatters appropriate to the Norm. These can be changed as for -# other axis objects. +# control the size. Finally, the colorbar will have default locators +# and formatters appropriate to the norm. These can be changed as for +# other Axis objects. # # -# Working with multiple figures and axes +# Working with multiple Figures and Axes # ====================================== # -# You can open multiple figures with multiple calls to +# You can open multiple Figures with multiple calls to # ``fig = plt.figure()`` or ``fig2, ax = plt.subplots()``. By keeping the -# object references you can add artists to either figure. +# object references you can add Artists to either Figure. # -# Multiple axes can be added a number of ways, but the most basic is +# Multiple Axes can be added a number of ways, but the most basic is # ``plt.subplots()`` as used above. One can achieve more complex layouts, -# with axes spanning columns or rows, using `~.pyplot.subplot_mosaic`. +# with Axes objects spanning columns or rows, using `~.pyplot.subplot_mosaic`. fig, axd = plt.subplot_mosaic([['upleft', 'right'], ['lowleft', 'right']], constrained_layout=True) axd['upleft'].set_title('upleft') axd['lowleft'].set_title('lowleft') -axd['right'].set_title('right') -plt.show() +axd['right'].set_title('right'); ############################################################################### -# Matplotlib has quite sophisticated tools for arranging axes: See +# Matplotlib has quite sophisticated tools for arranging Axes: See # :doc:`/tutorials/intermediate/arranging_axes` and # :doc:`/tutorials/provisional/mosaic`. # @@ -536,6 +538,6 @@ def my_plotter(ax, data1, data2, param_dict): # More reading # ============ # -# - For more plot types see :doc:`Plot types ` and the -# :doc:`API reference `, in particlar the -# :doc:`Axes API `. +# For more plot types see :doc:`Plot types ` and the +# :doc:`API reference `, in particlar the +# :doc:`Axes API `. From 0750e2040f55a0004239f28d39c635e764ec8332 Mon Sep 17 00:00:00 2001 From: Steffen Rehberg Date: Mon, 29 Nov 2021 15:42:22 +0100 Subject: [PATCH 2/4] Basic Usage tutorial: add additional axes section Secondary and twin axes are rather important (although not necessarily very basic) so they should be shortly mentioned with links to the API docs and some more detailed examples. --- tutorials/introductory/usage.py | 31 ++++++++++++++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) diff --git a/tutorials/introductory/usage.py b/tutorials/introductory/usage.py index a819a79ea632..6169ac15d5a0 100644 --- a/tutorials/introductory/usage.py +++ b/tutorials/introductory/usage.py @@ -367,7 +367,8 @@ def my_plotter(ax, data1, data2, param_dict): # # Each Axes has two (or three) `~.axis.Axis` objects representing the x- and # y-axis. These control the *scale* of the Axis, the tick *locators* and the -# tick *formatters*. +# tick *formatters*. Additional Axes can be attached to display further Axis +# objects. # # Scales # ------ @@ -449,6 +450,34 @@ def my_plotter(ax, data1, data2, param_dict): # numbers or dates. If you pass 1000 strings, Matplotlib will think you # meant 1000 categories and will add 1000 ticks to your plot! # +# +# Additional Axis objects +# ------------------------ +# +# Plotting data of different magnitude in one chart may require +# an additional y-axis. Such an Axis can be created by using +# `~.Axes.twinx` to add a new Axes with an invisible x-axis and a y-axis +# positioned at the right (analogously for `~.Axes.twiny`). See +# :doc:`/gallery/subplots_axes_and_figures/two_scales` for another example. +# +# Similarly, you can add a `~.Axes.secondary_xaxis` or +# `~.Axes.secondary_yaxis` having a different scale than the main Axis to +# represent the data in different scales or units. See +# :doc:`/gallery/subplots_axes_and_figures/secondary_axis` for further +# examples. + +fig, (ax1, ax3) = plt.subplots(1, 2, figsize=(8, 2.7), constrained_layout=True) +l1, = ax1.plot(t, s) +ax2 = ax1.twinx() +l2, = ax2.plot(t, range(len(t)), 'C1') +ax2.legend([l1, l2], ['Sine (left)', 'Straight (right)']) + +ax3.plot(t, s) +ax3.set_xlabel('Angle [°]') +ax4 = ax3.secondary_xaxis('top', functions=(np.rad2deg, np.deg2rad)) +ax4.set_xlabel('Angle [rad]') + +############################################################################## # Color mapped data # ================= # From 0caa41ac6a9f9ee7649a9f7e491c1bafb52abbb2 Mon Sep 17 00:00:00 2001 From: Steffen Rehberg Date: Tue, 30 Nov 2021 15:02:36 +0100 Subject: [PATCH 3/4] Change constrained_layout=True to layout='constrained' as the former is discouraged, see https://matplotlib.org/3.5.0/api/figure_api.html#matplotlib.figure.Figure --- tutorials/introductory/usage.py | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/tutorials/introductory/usage.py b/tutorials/introductory/usage.py index 6169ac15d5a0..21a41172c851 100644 --- a/tutorials/introductory/usage.py +++ b/tutorials/introductory/usage.py @@ -120,7 +120,7 @@ data['b'] = data['a'] + 10 * np.random.randn(50) data['d'] = np.abs(data['d']) * 100 -fig, ax = plt.subplots(figsize=(5, 2.7), constrained_layout=True) +fig, ax = plt.subplots(figsize=(5, 2.7), layout='constrained') ax.scatter('a', 'b', c='c', s='d', data=data) ax.set_xlabel('entry a') ax.set_ylabel('entry b'); @@ -147,7 +147,7 @@ # Note that even in the explicit style, we use `.pyplot.figure` to create the # Figure. -fig, ax = plt.subplots(figsize=(5, 2.7), constrained_layout=True) +fig, ax = plt.subplots(figsize=(5, 2.7), layout='constrained') ax.plot(x, x, label='linear') # Plot some data on the axes. ax.plot(x, x**2, label='quadratic') # Plot more data on the axes... ax.plot(x, x**3, label='cubic') # ... and some more. @@ -161,7 +161,7 @@ x = np.linspace(0, 2, 100) # Sample data. -plt.figure(figsize=(5, 2.7), constrained_layout=True) +plt.figure(figsize=(5, 2.7), layout='constrained') plt.plot(x, x, label='linear') # Plot some data on the (implicit) axes. plt.plot(x, x**2, label='quadratic') # etc. plt.plot(x, x**3, label='cubic') @@ -284,7 +284,7 @@ def my_plotter(ax, data1, data2, param_dict): mu, sigma = 115, 15 x = mu + sigma * np.random.randn(10000) -fig, ax = plt.subplots(figsize=(5, 2.7), constrained_layout=True) +fig, ax = plt.subplots(figsize=(5, 2.7), layout='constrained') # the histogram of the data n, bins, patches = ax.hist(x, 50, density=1, facecolor='C0', alpha=0.75) @@ -380,7 +380,7 @@ def my_plotter(ax, data1, data2, param_dict): # :doc:`/gallery/scales/scales` for other examples). Here we set the scale # manually: -fig, axs = plt.subplots(1, 2, figsize=(5, 2.7), constrained_layout=True) +fig, axs = plt.subplots(1, 2, figsize=(5, 2.7), layout='constrained') xdata = np.arange(len(data1)) # make an ordinal for this data = 10**data1 axs[0].plot(xdata, data) @@ -401,7 +401,7 @@ def my_plotter(ax, data1, data2, param_dict): # Axis objects to put tick marks. A simple interface to this is # `~.Axes.set_xticks`: -fig, axs = plt.subplots(2, 1, constrained_layout=True) +fig, axs = plt.subplots(2, 1, layout='constrained') axs[0].plot(xdata, data1) axs[0].set_title('Automatic ticks') @@ -424,7 +424,7 @@ def my_plotter(ax, data1, data2, param_dict): # well as floating point numbers. These get special locators and formatters # as appropriate. For dates: -fig, ax = plt.subplots(figsize=(5, 2.7), constrained_layout=True) +fig, ax = plt.subplots(figsize=(5, 2.7), layout='constrained') dates = np.arange(np.datetime64('2021-11-15'), np.datetime64('2021-12-25'), np.timedelta64(1, 'h')) data = np.cumsum(np.random.randn(len(dates))) @@ -439,7 +439,7 @@ def my_plotter(ax, data1, data2, param_dict): # For strings, we get categorical plotting (see: # :doc:`/gallery/lines_bars_and_markers/categorical_variables`). -fig, ax = plt.subplots(figsize=(5, 2.7), constrained_layout=True) +fig, ax = plt.subplots(figsize=(5, 2.7), layout='constrained') categories = ['turnips', 'rutabaga', 'cucumber', 'pumpkins'] ax.bar(categories, np.random.rand(len(categories))); @@ -466,7 +466,7 @@ def my_plotter(ax, data1, data2, param_dict): # :doc:`/gallery/subplots_axes_and_figures/secondary_axis` for further # examples. -fig, (ax1, ax3) = plt.subplots(1, 2, figsize=(8, 2.7), constrained_layout=True) +fig, (ax1, ax3) = plt.subplots(1, 2, figsize=(8, 2.7), layout='constrained') l1, = ax1.plot(t, s) ax2 = ax1.twinx() l2, = ax2.plot(t, range(len(t)), 'C1') @@ -487,7 +487,7 @@ def my_plotter(ax, data1, data2, param_dict): X, Y = np.meshgrid(np.linspace(-3, 3, 128), np.linspace(-3, 3, 128)) Z = (1 - X/2 + X**5 + Y**3) * np.exp(-X**2 - Y**2) -fig, axs = plt.subplots(2, 2, constrained_layout=True) +fig, axs = plt.subplots(2, 2, layout='constrained') pc = axs[0, 0].pcolormesh(X, Y, Z, vmin=-1, vmax=1, cmap='RdBu_r') fig.colorbar(pc, ax=axs[0, 0]) axs[0, 0].set_title('pcolormesh()') @@ -553,7 +553,7 @@ def my_plotter(ax, data1, data2, param_dict): # with Axes objects spanning columns or rows, using `~.pyplot.subplot_mosaic`. fig, axd = plt.subplot_mosaic([['upleft', 'right'], - ['lowleft', 'right']], constrained_layout=True) + ['lowleft', 'right']], layout='constrained') axd['upleft'].set_title('upleft') axd['lowleft'].set_title('lowleft') axd['right'].set_title('right'); From 5dfbb7d6acaeba136fe1ed427d1fddc2bd4653e7 Mon Sep 17 00:00:00 2001 From: Steffen Rehberg Date: Wed, 1 Dec 2021 13:24:21 +0100 Subject: [PATCH 4/4] Basic usage tutorial: Revert terminology and spelling changes regarding implicit/explicit and pyplot/object oriented style --- tutorials/introductory/usage.py | 27 +++++++++++++-------------- 1 file changed, 13 insertions(+), 14 deletions(-) diff --git a/tutorials/introductory/usage.py b/tutorials/introductory/usage.py index 21a41172c851..e578d9b7d44d 100644 --- a/tutorials/introductory/usage.py +++ b/tutorials/introductory/usage.py @@ -131,22 +131,21 @@ # Coding styles # ============= # -# The explicit and the implicit approach of programming -# ----------------------------------------------------- +# The object-oriented and the pyplot interfaces +# --------------------------------------------- # # As noted above, there are essentially two ways to use Matplotlib: # -# - Explicitly create Figures and Axes, and call methods on them (the explicit -# or "object oriented programming (OOP) style"). +# - Explicitly create Figures and Axes, and call methods on them (the +# "object-oriented (OO) style"). # - Rely on pyplot to automatically create and manage the Figures and Axes, and -# use pyplot functions for plotting (the implicit style). +# use pyplot functions for plotting. # -# So one can use the explicit style +# So one can use the OO-style x = np.linspace(0, 2, 100) # Sample data. -# Note that even in the explicit style, we use `.pyplot.figure` to create the -# Figure. +# Note that even in the OO-style, we use `.pyplot.figure` to create the Figure. fig, ax = plt.subplots(figsize=(5, 2.7), layout='constrained') ax.plot(x, x, label='linear') # Plot some data on the axes. ax.plot(x, x**2, label='quadratic') # Plot more data on the axes... @@ -157,7 +156,7 @@ ax.legend(); # Add a legend. ############################################################################### -# or the implicit style: +# or the pyplot-style: x = np.linspace(0, 2, 100) # Sample data. @@ -176,11 +175,11 @@ # figure creation. See the corresponding section in the gallery for more info: # :ref:`user_interfaces`.) # -# Matplotlib's documentation and examples use both the explicit and the -# implicit styles. In general, we suggest using the explicit style, -# particularly for complicated plots, and functions and scripts that are -# intended to be reused as part of a larger project. However, the implicit -# style can be very convenient for quick interactive work. +# Matplotlib's documentation and examples use both the OO and the pyplot +# styles. In general, we suggest using the OO style, particularly for +# complicated plots, and functions and scripts that are intended to be reused +# as part of a larger project. However, the pyplot style can be very convenient +# for quick interactive work. # # .. note:: #