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

Simplify Axis.get_{major,minor}_ticks. #10303

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 24, 2018
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 51 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
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.

Copy link
Contributor Author

@anntzer anntzer Jan 23, 2018

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
Morty Proxy This is a proxified and sanitized view of the page, visit original site.