10000 Merge pull request #3942 from tacaswell/axis_refactor · matplotlib/matplotlib@67d4bd7 · GitHub
[go: up one dir, main page]

Skip to content

Commit 67d4bd7

Browse files
committed
Merge pull request #3942 from tacaswell/axis_refactor
MNT : slight refactor of Axis.set_ticklabels
2 parents 44e4427 + f2ad3ab commit 67d4bd7

File tree

1 file changed

+14
-13
lines changed

1 file changed

+14
-13
lines changed

lib/matplotlib/axis.py

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1537,20 +1537,21 @@ def set_ticklabels(self, ticklabels, *args, **kwargs):
15371537
else:
15381538
self.set_major_formatter(mticker.FixedFormatter(ticklabels))
15391539
ticks = self.get_major_ticks()
1540+
ret = []
1541+
for tick_label, tick in zip(ticklabels, ticks):
1542+
# deal with label1
1543+
tick.label1.set_text(tick_label)
1544+
tick.label1.update(kwargs)
1545+
# deal with label2
1546+
tick.label2.set_text(tick_label)
1547+
tick.label2.update(kwargs)
1548+
# only return visible tick labels
1549+
if tick.label1On:
1550+
ret.append(tick.label1)
1551+
if tick.label2On:
1552+
ret.append(tick.label2)
15401553

1541-
ret1 = []
1542-
ret2 = []
1543-
for i, tick in enumerate(ticks):
1544-
if i < len(ticklabels):
1545-
if tick.label1On:
1546-
tick.label1.set_text(ticklabels[i])
1547-
tick.label1.update(kwargs)
1548-
ret1.append(tick.label1)
1549-
if tick.label2On:
1550-
tick.label2.set_text(ticklabels[i])
1551-
ret2.append(tick.label2)
1552-
tick.label2.update(kwargs)
1553-
return ret1 + ret2
1554+
return ret
15541555

15551556
def set_ticks(self, ticks, minor=False):
15561557
"""

0 commit comments

Comments
 (0)
0