From 07af129bbb23d8155b45d38c9278bd27c36167c1 Mon Sep 17 00:00:00 2001 From: Tim Hoffmann <2836374+timhoffm@users.noreply.github.com> Date: Tue, 15 Nov 2022 08:26:40 +0100 Subject: [PATCH] Backport PR #24434: Fix pyplot.figlegend docstring --- lib/matplotlib/figure.py | 9 ++++++--- lib/matplotlib/pyplot.py | 5 ++++- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/lib/matplotlib/figure.py b/lib/matplotlib/figure.py index 9d1eea7822da..c2e64eab073f 100644 --- a/lib/matplotlib/figure.py +++ b/lib/matplotlib/figure.py @@ -984,9 +984,12 @@ def clf(self, keep_observers=False): """ return self.clear(keep_observers=keep_observers) - # Note: in the docstring below, the newlines in the examples after the - # calls to legend() allow replacing it with figlegend() to generate the - # docstring of pyplot.figlegend. + # Note: the docstring below is modified with replace for the pyplot + # version of this function because the method name differs (plt.figlegend) + # the replacements are: + # " legend(" -> " figlegend(" for the signatures + # "fig.legend(" -> "plt.figlegend" for the code examples + # "ax.plot" -> "plt.plot" for consistency in using pyplot when able @_docstring.dedent_interpd def legend(self, *args, **kwargs): """ diff --git a/lib/matplotlib/pyplot.py b/lib/matplotlib/pyplot.py index 6f757ae031ef..3e47c9ee744b 100644 --- a/lib/matplotlib/pyplot.py +++ b/lib/matplotlib/pyplot.py @@ -962,7 +962,10 @@ def savefig(*args, **kwargs): def figlegend(*args, **kwargs): return gcf().legend(*args, **kwargs) if Figure.legend.__doc__: - figlegend.__doc__ = Figure.legend.__doc__.replace("legend(", "figlegend(") + figlegend.__doc__ = Figure.legend.__doc__ \ + .replace(" legend(", " figlegend(") \ + .replace("fig.legend(", "plt.figlegend(") \ + .replace("ax.plot(", "plt.plot(") ## Axes ##
Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.
Alternative Proxies: