Skip to content

Commit d09526f

Browse files
authored
Merge pull request #24434 from ksunden/figlegend_plt
Fix pyplot.figlegend docstring
2 parents 8cf9fc1 + f5e1e2d commit d09526f

File tree

2 files changed

+10
-4
lines changed

2 files changed

+10
-4
lines changed

lib/matplotlib/figure.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -979,9 +979,12 @@ def clf(self, keep_observers=False):
979979
"""
980980
return self.clear(keep_observers=keep_observers)
981981

982-
# Note: in the docstring below, the newlines in the examples after the
983-
# calls to legend() allow replacing it with figlegend() to generate the
984-
# docstring of pyplot.figlegend.
982+
# Note: the docstring below is modified with replace for the pyplot
983+
# version of this function because the method name differs (plt.figlegend)
984+
# the replacements are:
985+
# " legend(" -> " figlegend(" for the signatures
986+
# "fig.legend(" -> "plt.figlegend" for the code examples
987+
# "ax.plot" -> "plt.plot" for consistency in using pyplot when able
985988
@_docstring.dedent_interpd
986989
def legend(self, *args, **kwargs):
987990
"""

lib/matplotlib/pyplot.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -980,7 +980,10 @@ def savefig(*args, **kwargs):
980980
def figlegend(*args, **kwargs):
981981
return gcf().legend(*args, **kwargs)
982982
if Figure.legend.__doc__:
983-
figlegend.__doc__ = Figure.legend.__doc__.replace("legend(", "figlegend(")
983+
figlegend.__doc__ = Figure.legend.__doc__ \
984+
.replace(" legend(", " figlegend(") \
985+
.replace("fig.legend(", "plt.figlegend(") \
986+
.replace("ax.plot(", "plt.plot(")
984987

985988

986989
## Axes ##

0 commit comments

Comments
 (0)