From f5e1e2d8f22053f445927ff31f70603303e3f286 Mon Sep 17 00:00:00 2001 From: Kyle Sunden Date: Sat, 12 Nov 2022 00:14:38 -0600 Subject: [PATCH] Fix pyplot.figlegend docstring Closes #24433 --- 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 147500dd5451..580a8e7df59d 100644 --- a/lib/matplotlib/figure.py +++ b/lib/matplotlib/figure.py @@ -979,9 +979,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 4777327bfe99..885fccb16eec 100644 --- a/lib/matplotlib/pyplot.py +++ b/lib/matplotlib/pyplot.py @@ -980,7 +980,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 ##