Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit2a4710a

Browse files
committed
MNT: Prevent users from erroneously using legend label API on Axis
Closes#27971.For a complete explanation see#27971 (comment)
1 parent199c31f commit2a4710a

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
returncbook.silent_list('Line2D gridline',
14431443
[tick.gridlinefortickinticks])
14441444

1445+
defset_label(self,s):
1446+
"""Assigning legend labels is supported. Raises RuntimeError."""
1447+
raiseRuntimeError(
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
defget_label(self):
14461455
"""Return the axis label as a Text instance."""
14471456
returnself.label

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp