From 6cde20074263d3a8a45442d6ae6a3cc21f672ea0 Mon Sep 17 00:00:00 2001 From: Tim Hoffmann <2836374+timhoffm@users.noreply.github.com> Date: Tue, 19 May 2026 11:57:25 +0200 Subject: [PATCH] DOC: Remove pyplot text example Motivation: This is part of the general approach to consolidate examples. Why we don't need the pyplot text example: - We don't have to explicitly discuss mathtext for the case of pyplot - Title and axkis labels are better described already in the basic plot example - `plt.text()` is not so common as to justify a specific pyplot example. As with most other functions it's sufficient to have examples for the Axes interface (which for text are in the section "Text, labels and annoations") --- galleries/examples/pyplots/pyplot_simple.py | 28 ++++++++++---- galleries/examples/pyplots/pyplot_text.py | 41 --------------------- 2 files changed, 20 insertions(+), 49 deletions(-) delete mode 100644 galleries/examples/pyplots/pyplot_text.py diff --git a/galleries/examples/pyplots/pyplot_simple.py b/galleries/examples/pyplots/pyplot_simple.py index 48a862c7fee3..8da1e346c296 100644 --- a/galleries/examples/pyplots/pyplot_simple.py +++ b/galleries/examples/pyplots/pyplot_simple.py @@ -1,20 +1,30 @@ """ -=========== -Simple plot -=========== +========== +Basic plot +========== -A simple plot where a list of numbers are plotted against their index, -resulting in a straight line. Use a format string (here, 'o-r') to set the -markers (circles), linestyle (solid line) and color (red). +A basic plot using the :ref:`pyplot_interface`. + +- `~.pyplot.plot` plots the data y versus x as lines and/or markers. +- `~.pyplot.title`, `~.pyplot.xlabel` and `~.pyplot.ylabel` set the title, + x-axis label and y-axis label. +- `~.pyplot.show` displays the plot. .. redirect-from:: /gallery/pyplots/fig_axes_labels_simple .. redirect-from:: /gallery/pyplots/pyplot_formatstr +.. redirect-from:: /gallery/pyplots/pyplot_text """ import matplotlib.pyplot as plt +import numpy as np + +x = np.arange(0.0, 2.0, 0.01) +y = np.sin(2 * np.pi * x) -plt.plot([1, 2, 3, 4], 'o-r') -plt.ylabel('some numbers') +plt.plot(x, y) +plt.title("A basic plot using pyplot") +plt.xlabel('Time [s]') +plt.ylabel('Voltage [mV]') plt.show() # %% @@ -25,5 +35,7 @@ # in this example: # # - `matplotlib.pyplot.plot` +# - `matplotlib.pyplot.title` +# - `matplotlib.pyplot.ylabel` # - `matplotlib.pyplot.ylabel` # - `matplotlib.pyplot.show` diff --git a/galleries/examples/pyplots/pyplot_text.py b/galleries/examples/pyplots/pyplot_text.py deleted file mode 100644 index 72f977c2f985..000000000000 --- a/galleries/examples/pyplots/pyplot_text.py +++ /dev/null @@ -1,41 +0,0 @@ -""" -============================== -Text and mathtext using pyplot -============================== - -Set the special text objects `~.pyplot.title`, `~.pyplot.xlabel`, and -`~.pyplot.ylabel` through the dedicated pyplot functions. Additional text -objects can be placed in the Axes using `~.pyplot.text`. - -You can use TeX-like mathematical typesetting in all texts; see also -:ref:`mathtext`. - -.. redirect-from:: /gallery/pyplots/pyplot_mathtext -""" - -import matplotlib.pyplot as plt -import numpy as np - -t = np.arange(0.0, 2.0, 0.01) -s = np.sin(2*np.pi*t) - -plt.plot(t, s) -plt.text(0, -1, r'Hello, world!', fontsize=15) -plt.title(r'$\mathcal{A}\sin(\omega t)$', fontsize=20) -plt.xlabel('Time [s]') -plt.ylabel('Voltage [mV]') -plt.show() - -# %% -# -# .. admonition:: References -# -# The use of the following functions, methods, classes and modules is shown -# in this example: -# -# - `matplotlib.pyplot.hist` -# - `matplotlib.pyplot.xlabel` -# - `matplotlib.pyplot.ylabel` -# - `matplotlib.pyplot.text` -# - `matplotlib.pyplot.grid` -# - `matplotlib.pyplot.show`