Skip to content

Move the call to Formatter.set_locs into Formatter.format_ticks. #13323

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
Feb 14, 2019
Merged
Show file tree
Hide file tree
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
13 changes: 9 additions & 4 deletions doc/api/next_api_changes/2018-01-28-AL.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,13 @@ New `Formatter.format_ticks` method
The `Formatter` class gained a new `~Formatter.format_ticks` method, which
takes the list of all tick locations as a single argument and returns the list
of all formatted values. It is called by the axis tick handling code and, by
default, repeatedly calls `~Formatter.__call__`.
default, first calls `~Formatter.set_locs` with all locations, then repeatedly
calls `~Formatter.__call__` for each location.

It is intended to be overridden by `Formatter` subclasses for which
the formatting of a tick value depends on other tick values, such as
`ConciseDateFormatter`.
Tick-handling code in the codebase that previously performed this sequence
(`~Formatter.set_locs` followed by repeated `~Formatter.__call__`) have been
updated to use `~Formatter.format_ticks`.

`~Formatter.format_ticks` is intended to be overridden by `Formatter`
subclasses for which the formatting of a tick value depends on other tick
values, such as `ConciseDateFormatter`.
2 changes: 0 additions & 2 deletions lib/matplotlib/axis.py
Original file line number Diff line number Diff line change
Expand Up @@ -934,12 +934,10 @@ def iter_ticks(self):
"""
major_locs = self.major.locator()
major_ticks = self.get_major_ticks(len(major_locs))
self.major.formatter.set_locs(major_locs)
major_labels = self.major.formatter.format_ticks(major_locs)

minor_locs = self.minor.locator()
minor_ticks = self.get_minor_ticks(len(minor_locs))
self.minor.formatter.set_locs(minor_locs)
minor_labels = self.minor.formatter.format_ticks(minor_locs)

yield from zip(major_ticks, major_locs, major_labels)
Expand Down
1 change: 0 additions & 1 deletion lib/matplotlib/colorbar.py
Original file line number Diff line number Diff line change
Expand Up @@ -788,7 +788,6 @@ def _ticker(self, locator, formatter):
b = b[(b <= intv[1] + eps) & (b >= intv[0] - eps)]
self._manual_tick_data_values = b
ticks = self._locate(b)
formatter.set_locs(b)
ticklabels = formatter.format_ticks(b)
offset_string = formatter.get_offset()
return ticks, ticklabels, offset_string
Expand Down
1 change: 1 addition & 0 deletions lib/matplotlib/ticker.py
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,7 @@ def __call__(self, x, pos=None):

def format_ticks(self, values):
"""Return the tick labels for all the ticks at once."""
self.set_locs(values)
return [self(value, i) for i, value in enumerate(values)]

def format_data(self, value):
Expand Down
2 changes: 0 additions & 2 deletions lib/mpl_toolkits/axisartist/axislines.py
Original file line number Diff line number Diff line change
Expand Up @@ -225,12 +225,10 @@ def get_tick_iterators(self, axes):

major = self.axis.major
majorLocs = major.locator()
major.formatter.set_locs(majorLocs)
majorLabels = major.formatter.format_ticks(majorLocs)

minor = self.axis.minor
minorLocs = minor.locator()
minor.formatter.set_locs(minorLocs)
minorLabels = minor.formatter.format_ticks(minorLocs)

trans_tick = self.get_tick_transform(axes)
Expand Down
8 changes: 3 additions & 5 deletions lib/mpl_toolkits/axisartist/grid_finder.py
Original file line number Diff line number Diff line change
Expand Up @@ -291,11 +291,9 @@ def __init__(self, useMathText=True):
def __call__(self, direction, factor, values):
if not self._ignore_factor:
if factor is None:
factor = 1.
values = [v/factor for v in values]
#values = [v for v in values]
self._fmt.set_locs(values)
return [self._fmt(v) for v in values]
factor = 1
values = [v / factor for v in values]
return self._fmt.format_ticks(values)


class DictFormatter(object):
Expand Down
11 changes: 3 additions & 8 deletions lib/mpl_toolkits/mplot3d/axis3d.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,9 +135,7 @@ def init3d(self):

def get_tick_positions(self):
majorLocs = self.major.locator()
self.major.formatter.set_locs(majorLocs)
majorLabels = [self.major.formatter(val, i)
for i, val in enumerate(majorLocs)]
majorLabels = self.major.formatter.format_ticks(majorLocs)
return majorLabels, majorLocs

def get_major_ticks(self, numticks=None):
Expand Down Expand Up @@ -236,11 +234,8 @@ def draw(self, renderer):
locmin, locmax = locmax, locmin

# Rudimentary clipping
majorLocs = [loc for loc in majorLocs if
locmin <= loc <= locmax]
self.major.formatter.set_locs(majorLocs)
majorLabels = [self.major.formatter(val, i)
for i, val in enumerate(majorLocs)]
majorLocs = [loc for loc in majorLocs if locmin <= loc <= locmax]
majorLabels = self.major.formatter.format_ticks(majorLocs)

mins, maxs, centers, deltas, tc, highs = self._get_coord_info(renderer)

Expand Down