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

Appearance settings

Commit 76cfff2

Browse filesBrowse files
authored
Merge pull request #10303 from anntzer/simplify-get_ticks
Simplify Axis.get_{major,minor}_ticks.
2 parents b42db80 + 0cc2cea commit 76cfff2
Copy full SHA for 76cfff2

File tree

1 file changed

+16
-35
lines changed
Filter options

1 file changed

+16
-35
lines changed

‎lib/matplotlib/axis.py

Copy file name to clipboardExpand all lines: lib/matplotlib/axis.py
+16-35Lines changed: 16 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -803,8 +803,6 @@ def reset_ticks(self):
803803

804804
self.majorTicks.extend([self._get_tick(major=True)])
805805
self.minorTicks.extend([self._get_tick(major=False)])
806-
self._lastNumMajorTicks = 1
807-
self._lastNumMinorTicks = 1
808806

809807
try:
810808
self.set_clip_path(self.axes.patch)
@@ -1362,48 +1360,31 @@ def get_major_ticks(self, numticks=None):
13621360
'get the tick instances; grow as necessary'
13631361
if numticks is None:
13641362
numticks = len(self.get_major_locator()())
1365-
if len(self.majorTicks) < numticks:
1366-
# update the new tick label properties from the old
1367-
for i in range(numticks - len(self.majorTicks)):
1368-
tick = self._get_tick(major=True)
1369-
self.majorTicks.append(tick)
1370-
1371-
if self._lastNumMajorTicks < numticks:
1372-
protoTick = self.majorTicks[0]
1373-
for i in range(self._lastNumMajorTicks, len(self.majorTicks)):
1374-
tick = self.majorTicks[i]
1375-
if self._gridOnMajor:
1376-
tick.gridOn = True
1377-
self._copy_tick_props(protoTick, tick)
13781363

1379-
self._lastNumMajorTicks = numticks
1380-
ticks = self.majorTicks[:numticks]
1364+
while len(self.majorTicks) < numticks:
1365+
# update the new tick label properties from the old
1366+
tick = self._get_tick(major=True)
1367+
self.majorTicks.append(tick)
1368+
if self._gridOnMajor:
1369+
tick.gridOn = True
1370+
self._copy_tick_props(self.majorTicks[0], tick)
13811371

1382-
return ticks
1372+
return self.majorTicks[:numticks]
13831373

13841374
def get_minor_ticks(self, numticks=None):
13851375
'get the minor tick instances; grow as necessary'
13861376
if numticks is None:
13871377
numticks = len(self.get_minor_locator()())
13881378

1389-
if len(self.minorTicks) < numticks:
1379+
while len(self.minorTicks) < numticks:
13901380
# update the new tick label properties from the old
1391-
for i in range(numticks - len(self.minorTicks)):
1392-
tick = self._get_tick(major=False)
1393-
self.minorTicks.append(tick)
1394-
1395-
if self._lastNumMinorTicks < numticks:
1396-
protoTick = self.minorTicks[0]
1397-
for i in range(self._lastNumMinorTicks, len(self.minorTicks)):
1398-
tick = self.minorTicks[i]
1399-
if self._gridOnMinor:
1400-
tick.gridOn = True
1401-
self._copy_tick_props(protoTick, tick)
1402-
1403-
self._lastNumMinorTicks = numticks
1404-
ticks = self.minorTicks[:numticks]
1405-
1406-
return ticks
1381+
tick = self._get_tick(major=False)
1382+
self.minorTicks.append(tick)
1383+
if self._gridOnMinor:
1384+
tick.gridOn = True
1385+
self._copy_tick_props(self.minorTicks[0], tick)
1386+
1387+
return self.minorTicks[:numticks]
14071388

14081389
def grid(self, b=None, which='major', **kwargs):
14091390
"""

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.