8000 Adjust number of ticks based on length of axis by mdboom · Pull Request #5588 · matplotlib/matplotlib · GitHub
[go: up one dir, main page]

Skip to content

Adjust number of ticks based on length of axis #5588

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 13 commits into from
Dec 14, 2015
Prev Previous commit
Next Next commit
Cache tick space calculation
  • Loading branch information
mdboom committed Dec 10, 2015
commit 63c9b43f38bc15b427bbf669a20a7923a2f3290a
19 changes: 11 additions & 8 deletions lib/matplotlib/axis.py
Original file line number Diff line number Diff line change
Expand Up @@ -654,6 +654,7 @@ def __init__(self, axes, pickradius=15):
# Initialize here for testing; later add API
self._major_tick_kw = dict()
self._minor_tick_kw = dict()
self._tick_space = None

self.cla()
self._set_scale('linear')
Expand Down Expand Up @@ -785,6 +786,7 @@ def set_tick_params(self, which='major', reset=False, **kw):
for tick in self.minorTicks:
tick._apply_params(**self._minor_tick_kw)
self.stale = True
self._tick_space = None

@staticmethod
def _translate_tick_kw(kw, to_init_kw=True):
Expand Down Expand Up @@ -2339,11 +2341,12 @@ def set_default_intervals(self):
self.stale = True

def get_tick_space(self):
# TODO: cache this computation
ends = self.axes.transAxes.transform([[0, 0], [0, 1]])
length = ((ends[1][1] - ends[0][1]) / self.axes.figure.dpi) * 72.0
tick = self._get_tick(True)
# Having a spacing of at least 2 just looks good.
size = tick.label1.get_size() * 2.0
size *= np.cos(np.deg2rad(tick.label1.get_rotation()))
return np.floor(length / size)
if self._tick_space is None:
ends = self.axes.transAxes.transform([[0, 0], [0, 1]])
length = ((ends[1][1] - ends[0][1]) / self.axes.figure.dpi) * 72.0
tick = self._get_tick(True)
# Having a spacing of at least 2 just looks good.
size = tick.label1.get_size() * 2.0
size *= np.cos(np.deg2rad(tick.label1.get_rotation()))
self._tick_space = np.floor(length / size)
return self._tick_space
0