| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
|
The example claims "Instead of plotting a legend on each axis, a legend for all the artists on all the sub-axes of a figure can be plotted instead." but it does not do this. I think we can consolidate the whole example to import matplotlib.pyplot as plt import numpy as np fig, axs = plt.subplots(1, 2, layout='constrained') x = np.arange(0.0, 4*np.pi, 0.2) axs[0].plot(x, np.sin(x), label='Line 1') axs[0].plot(x, np.exp(-x/2), marker='o', label='Line 2') axs[1].plot(x, np.sin(x), color='tab:green', label='Line 3') axs[1].plot(x, np.exp(-x/4), color='tab:red', marker='^', label='Line 4') fig.legend(loc='outside right upper') plt.show() fig.legend() will also auto-detect the labelled Artists across all axes, so the recommended way is to pass label=... to the plot functions and let the legend detect these. Explicitly passing handles and labels is only needed for very special cases where you need more control, and it's the same as for ax.legend() so does not need mention here. Also, I believe 'outside right upper' is the most used position, so let's use that in the example. The outside positioning is discussed in detail here: https://matplotlib.org/stable/users/explain/axes/legend_guide.html#figure-legends. I'd prefer a link instead of discussing this again in a second plot. |
Sorry, something went wrong.
|
@timhoffm Thank you so much for consolidating the example! I have incorporated the new version into this PR. |
Sorry, something went wrong.
…666-on-v3.10.x Backport PR #29666 on branch v3.10.x (DOC: Revising the Figure Legend Demo Example)
…666-on-v3.10.0-doc Backport PR #29666 on branch v3.10.0-doc (DOC: Revising the Figure Legend Demo Example)
…t-of-pr-29666-on-v3.10.0-doc Backport PR matplotlib#29666 on branch v3.10.0-doc (DOC: Revising the Figure Legend Demo Example)
| Back | FazBrowse Home | New Git URL |
PR summary
Revising the Figure Legend Demo Example. Elaborated on the difference between outside left upper and outside upper right of legend locations.
https://matplotlib.org/devdocs/gallery/text_labels_and_annotations/figlegend_demo.html
PR checklist