Skip to content

Commit

Permalink
MNT: Prevent users from erroneously using legend label API on Axis
Browse files Browse the repository at this point in the history
Closes matplotlib#27971.

For a complete explanation see matplotlib#27971 (comment)
  • Loading branch information
timhoffm committed Jul 17, 2024
1 parent 199c31f commit 15bc099
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions lib/matplotlib/axis.py
Original file line number Diff line number Diff line change
Expand Up @@ -1442,6 +1442,14 @@ def get_gridlines(self):
return cbook.silent_list('Line2D gridline',
[tick.gridline for tick in ticks])

def set_label(self, s):
raise RuntimeError(
"A legend label cannot be assigned to an Axis. Did you mean "
"set the axis label via set_label_text()?")

@_api.deprecated("3.10", "Use the property 'Axis.label' instead")
# Note: After the deprecation, this should raise a RuntimeError; see
# https://github.com/matplotlib/matplotlib/issues/27971#issuecomment-2016955731
def get_label(self):
"""Return the axis label as a Text instance."""
return self.label
Expand Down

0 comments on commit 15bc099

Please sign in to comment.