From a0d5b0a8aecd28ae9269c383d26aa0459a1b00e0 Mon Sep 17 00:00:00 2001 From: Tim Hoffmann <2836374+timhoffm@users.noreply.github.com> Date: Fri, 7 Feb 2025 23:21:15 +0100 Subject: [PATCH] DOC: Remove simple_legend examples from User Demo The same plots are contained in the legend guide at https://matplotlib.org/devdocs/users/explain/axes/legend_guide.html#legend-location https://matplotlib.org/devdocs/users/explain/axes/legend_guide.html#multiple-legends-on-the-same-axes And there, they aleady have accompanying descriptions. Instead of moving these examples to the text_labels_and_annotations section, I've decided to remove them and instead link the existing legend examples with a see also to the legend guide. I believe this is more helpful than having more uncommented legend examples. --- .../figlegend_demo.py | 6 +++++ .../text_labels_and_annotations/legend.py | 5 ++++ .../legend_demo.py | 7 ++++++ .../examples/userdemo/simple_legend01.py | 25 ------------------- .../examples/userdemo/simple_legend02.py | 23 ----------------- galleries/users_explain/axes/legend_guide.py | 2 ++ 6 files changed, 20 insertions(+), 48 deletions(-) delete mode 100644 galleries/examples/userdemo/simple_legend01.py delete mode 100644 galleries/examples/userdemo/simple_legend02.py diff --git a/galleries/examples/text_labels_and_annotations/figlegend_demo.py b/galleries/examples/text_labels_and_annotations/figlegend_demo.py index 50b3eeabc085..64253430b085 100644 --- a/galleries/examples/text_labels_and_annotations/figlegend_demo.py +++ b/galleries/examples/text_labels_and_annotations/figlegend_demo.py @@ -25,3 +25,9 @@ # %% # The outside positioning is discussed in detail here: # https://matplotlib.org/stable/users/explain/axes/legend_guide.html#figure-legends +# +# +# .. seealso:: +# +# The :ref:`legend_guide` contains an in depth discussion on the configuration +# options for legends. diff --git a/galleries/examples/text_labels_and_annotations/legend.py b/galleries/examples/text_labels_and_annotations/legend.py index 3113b4c5aad9..82e7fdcc4544 100644 --- a/galleries/examples/text_labels_and_annotations/legend.py +++ b/galleries/examples/text_labels_and_annotations/legend.py @@ -37,3 +37,8 @@ # # - `matplotlib.axes.Axes.plot` / `matplotlib.pyplot.plot` # - `matplotlib.axes.Axes.legend` / `matplotlib.pyplot.legend` +# +# .. seealso:: +# +# The :ref:`legend_guide` contains an in depth discussion on the configuration +# options for legends. diff --git a/galleries/examples/text_labels_and_annotations/legend_demo.py b/galleries/examples/text_labels_and_annotations/legend_demo.py index 2f550729837e..ea948eb4ba14 100644 --- a/galleries/examples/text_labels_and_annotations/legend_demo.py +++ b/galleries/examples/text_labels_and_annotations/legend_demo.py @@ -178,3 +178,10 @@ def create_artists(self, legend, orig_handle, handlelength=2.5, handleheight=3) plt.show() + +# %% +# +# .. seealso:: +# +# The :ref:`legend_guide` contains an in depth discussion on the configuration +# options for legends. diff --git a/galleries/examples/userdemo/simple_legend01.py b/galleries/examples/userdemo/simple_legend01.py deleted file mode 100644 index 6c74597ee5cc..000000000000 --- a/galleries/examples/userdemo/simple_legend01.py +++ /dev/null @@ -1,25 +0,0 @@ -""" -=============== -Simple Legend01 -=============== - -""" -import matplotlib.pyplot as plt - -fig = plt.figure() - -ax = fig.add_subplot(211) -ax.plot([1, 2, 3], label="test1") -ax.plot([3, 2, 1], label="test2") -# Place a legend above this subplot, expanding itself to -# fully use the given bounding box. -ax.legend(bbox_to_anchor=(0., 1.02, 1., .102), loc='lower left', - ncols=2, mode="expand", borderaxespad=0.) - -ax = fig.add_subplot(223) -ax.plot([1, 2, 3], label="test1") -ax.plot([3, 2, 1], label="test2") -# Place a legend to the right of this smaller subplot. -ax.legend(bbox_to_anchor=(1.05, 1), loc='upper left', borderaxespad=0.) - -plt.show() diff --git a/galleries/examples/userdemo/simple_legend02.py b/galleries/examples/userdemo/simple_legend02.py deleted file mode 100644 index 2f9be1172572..000000000000 --- a/galleries/examples/userdemo/simple_legend02.py +++ /dev/null @@ -1,23 +0,0 @@ -""" -=============== -Simple Legend02 -=============== - -""" -import matplotlib.pyplot as plt - -fig, ax = plt.subplots() - -line1, = ax.plot([1, 2, 3], label="Line 1", linestyle='--') -line2, = ax.plot([3, 2, 1], label="Line 2", linewidth=4) - -# Create a legend for the first line. -first_legend = ax.legend(handles=[line1], loc='upper right') - -# Add the legend manually to the current Axes. -ax.add_artist(first_legend) - -# Create another legend for the second line. -ax.legend(handles=[line2], loc='lower right') - -plt.show() diff --git a/galleries/users_explain/axes/legend_guide.py b/galleries/users_explain/axes/legend_guide.py index 1164ec92ff71..5da3ceafe387 100644 --- a/galleries/users_explain/axes/legend_guide.py +++ b/galleries/users_explain/axes/legend_guide.py @@ -1,5 +1,7 @@ """ .. redirect-from:: /tutorials/intermediate/legend_guide +.. redirect-from:: /galleries/examples/userdemo/simple_legend01 +.. redirect-from:: /galleries/examples/userdemo/simple_legend02 .. _legend_guide: