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

Commitfd4cce7

Browse files
authored
Merge pull request#23170 from jklymak/enh-update-ticks
ENH: update ticks when requesting labels
2 parents6cba8d9 +bbff015 commitfd4cce7

File tree

3 files changed

+16
-7
lines changed

3 files changed

+16
-7
lines changed
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
``get_ticklabels`` now always populates labels
2+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
3+
Previously `.Axis.get_ticklabels` (and `.Axes.get_xticklabels`,
4+
`.Axes.get_yticklabels`) would only return empty strings unless a draw had
5+
already been performed. Now the ticks and their labels are updated when the
6+
labels are requested.

‎lib/matplotlib/axis.py

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1312,13 +1312,15 @@ def get_pickradius(self):
13121312

13131313
defget_majorticklabels(self):
13141314
"""Return this Axis' major tick labels, as a list of `~.text.Text`."""
1315+
self._update_ticks()
13151316
ticks=self.get_major_ticks()
13161317
labels1= [tick.label1fortickinticksiftick.label1.get_visible()]
13171318
labels2= [tick.label2fortickinticksiftick.label2.get_visible()]
13181319
returnlabels1+labels2
13191320

13201321
defget_minorticklabels(self):
13211322
"""Return this Axis' minor tick labels, as a list of `~.text.Text`."""
1323+
self._update_ticks()
13221324
ticks=self.get_minor_ticks()
13231325
labels1= [tick.label1fortickinticksiftick.label1.get_visible()]
13241326
labels2= [tick.label2fortickinticksiftick.label2.get_visible()]
@@ -1341,13 +1343,6 @@ def get_ticklabels(self, minor=False, which=None):
13411343
Returns
13421344
-------
13431345
list of `~matplotlib.text.Text`
1344-
1345-
Notes
1346-
-----
1347-
The tick label strings are not populated until a ``draw`` method has
1348-
been called.
1349-
1350-
See also: `~.pyplot.draw` and `~.FigureCanvasBase.draw`.
13511346
"""
13521347
ifwhichisnotNone:
13531348
ifwhich=='minor':

‎lib/matplotlib/tests/test_axes.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7766,3 +7766,11 @@ def test_bezier_autoscale():
77667766
# Bottom ylim should be at the edge of the curve (-0.5), and not include
77677767
# the control point (at -1)
77687768
assertax.get_ylim()[0]==-0.5
7769+
7770+
7771+
deftest_get_xticklabel():
7772+
fig,ax=plt.subplots()
7773+
ax.plot(np.arange(10))
7774+
forindinrange(10):
7775+
assertax.get_xticklabels()[ind].get_text()==f'{ind}'
7776+
assertax.get_yticklabels()[ind].get_text()==f'{ind}'

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp