10000 MNT: Prevent users from erroneously using legend label API on Axis · matplotlib/matplotlib@2a4710a · GitHub
[go: up one dir, main page]

Skip to content

Commit 2a4710a

Browse files
committed
MNT: Prevent users from erroneously using legend label API on Axis
Closes #27971. For a complete explanation see #27971 (comment)
1 parent 199c31f commit 2a4710a

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
``Axis.get_label``
2+
~~~~~~~~~~~~~~~~~~
3+
`.Artist.get_label` is reserved for legend labels. `.Axis.get_label` had overwritten
4+
this, providing the axis label `.Text` instance. `.Axis.get_label` will raise a
5+
RuntimeError in the future. If you want the axis label `.Text` instance, use the
6+
property `.Axis.label` instead.

lib/matplotlib/axis.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1442,6 +1442,15 @@ def get_gridlines(self):
14421442
return cbook.silent_list('Line2D gridline',
14431443
[tick.gridline for tick in ticks])
14441444

1445+
def set_label(self, s):
1446+
"""Assigning legend labels is supported. Raises RuntimeError."""
1447+
raise RuntimeError(
1448+
"A legend label cannot be assigned to an Axis. Did you mean to "
1449+
"set the axis label via set_label_text()?")
1450+
1451+
@_api.deprecated("3.10", message="Use the property 'Axis.label' instead")
1452+
# Note: After the deprecation, this should raise a RuntimeError; see
1453+
# https://github.com/matplotlib/matplotlib/issues/27971#issuecomment-2016955731
14451454
def get_label(self):
14461455
"""Return the axis label as a Text instance."""
14471456
return self.label

0 commit comments

Comments
 (0)
0