Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 16 additions & 35 deletions lib/matplotlib/axis.py
Original file line number Diff line number Diff line change
Expand Up @@ -803,8 +803,6 @@ def reset_ticks(self):

self.majorTicks.extend([self._get_tick(major=True)])
self.minorTicks.extend([self._get_tick(major=False)])
self._lastNumMajorTicks = 1
self._lastNumMinorTicks = 1

try:
self.set_clip_path(self.axes.patch)
Expand Down Expand Up @@ -1362,48 +1360,31 @@ def get_major_ticks(self, numticks=None):
'get the tick instances; grow as necessary'
if numticks is None:
numticks = len(self.get_major_locator()())
if len(self.majorTicks) < numticks:
# update the new tick label properties from the old
for i in range(numticks - len(self.majorTicks)):
tick = self._get_tick(major=True)
self.majorTicks.append(tick)

if self._lastNumMajorTicks < numticks:
protoTick = self.majorTicks[0]
for i in range(self._lastNumMajorTicks, len(self.majorTicks)):
tick = self.majorTicks[i]
if self._gridOnMajor:
tick.gridOn = True
self._copy_tick_props(protoTick, tick)

self._lastNumMajorTicks = numticks
ticks = self.majorTicks[:numticks]
while len(self.majorTicks) < numticks:

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did we decide that the _lastNumMajorTicks logic wasn't needed? What did all that do and why can we remove it? Certainly your change is simpler, but it seems most of the un-simpleness in the old code was because of the _lastNumMajorTicks logic.

@anntzer anntzer Jan 23, 2018 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's private, unused anywhere else, and, to the best of my understanding, this implementation does the same thing...
It was introduced in 08610fc and never touched since.

# update the new tick label properties from the old
tick = self._get_tick(major=True)
self.majorTicks.append(tick)
if self._gridOnMajor:
tick.gridOn = True
self._copy_tick_props(self.majorTicks[0], tick)

return ticks
return self.majorTicks[:numticks]

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

if len(self.minorTicks) < numticks:
while len(self.minorTicks) < numticks:
# update the new tick label properties from the old
for i in range(numticks - len(self.minorTicks)):
tick = self._get_tick(major=False)
self.minorTicks.append(tick)

if self._lastNumMinorTicks < numticks:
protoTick = self.minorTicks[0]
for i in range(self._lastNumMinorTicks, len(self.minorTicks)):
tick = self.minorTicks[i]
if self._gridOnMinor:
tick.gridOn = True
self._copy_tick_props(protoTick, tick)

self._lastNumMinorTicks = numticks
ticks = self.minorTicks[:numticks]

return ticks
tick = self._get_tick(major=False)
self.minorTicks.append(tick)
if self._gridOnMinor:
tick.gridOn = True
self._copy_tick_props(self.minorTicks[0], tick)

return self.minorTicks[:numticks]

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