Skip to content

Commit a8c5557

Browse files
committed
Move the call to Formatter.set_locs into Formatter.format_ticks.
All calls to Formatter.set_locs occur before a call to Formatter.format_ticks (or its predecessor, a list of calls to `Formatter.__call__`); it was basically a bandaid around the fact that all tick locations were needed to properly format an individual tick. Move the call to set_locs into format_ticks, with the intention to later deprecate set_locs. Convert a few more places to use format_ticks.
1 parent 64c84b4 commit a8c5557

File tree

7 files changed

+15
-21
lines changed

7 files changed

+15
-21
lines changed

doc/api/next_api_changes/2018-01-28-AL.rst

+8-3
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,13 @@ New `Formatter.format_ticks` method
44
The `Formatter` class gained a new `~Formatter.format_ticks` method, which
55
takes the list of all tick locations as a single argument and returns the list
66
of all formatted values. It is called by the axis tick handling code and, by
7-
default, repeatedly calls `~Formatter.__call__`.
7+
default, first calls `~Formatter.set_locs` with all locations, then repeatedly
8+
calls `~Formatter.__call__` for each location.
89

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

lib/matplotlib/axis.py

-2
Original file line numberDiff line numberDiff line change
@@ -934,12 +934,10 @@ def iter_ticks(self):
934934
"""
935935
major_locs = self.major.locator()
936936
major_ticks = self.get_major_ticks(len(major_locs))
937-
self.major.formatter.set_locs(major_locs)
938937
major_labels = self.major.formatter.format_ticks(major_locs)
939938

940939
minor_locs = self.minor.locator()
941940
minor_ticks = self.get_minor_ticks(len(minor_locs))
942-
self.minor.formatter.set_locs(minor_locs)
943941
minor_labels = self.minor.formatter.format_ticks(minor_locs)
944942

945943
yield from zip(major_ticks, major_locs, major_labels)

lib/matplotlib/colorbar.py

-1
Original file line numberDiff line numberDiff line change
@@ -788,7 +788,6 @@ def _ticker(self, locator, formatter):
788788
b = b[(b <= intv[1] + eps) & (b >= intv[0] - eps)]
789789
self._manual_tick_data_values = b
790790
ticks = self._locate(b)
791-
formatter.set_locs(b)
792791
ticklabels = formatter.format_ticks(b)
793792
offset_string = formatter.get_offset()
794793
return ticks, ticklabels, offset_string

lib/matplotlib/ticker.py

+1
Original file line numberDiff line numberDiff line change
@@ -255,6 +255,7 @@ def __call__(self, x, pos=None):
255255

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

260261
def format_data(self, value):

lib/mpl_toolkits/axisartist/axislines.py

-2
Original file line numberDiff line numberDiff line change
@@ -225,12 +225,10 @@ def get_tick_iterators(self, axes):
225225

226226
major = self.axis.major
227227
majorLocs = major.locator()
228-
major.formatter.set_locs(majorLocs)
229228
majorLabels = major.formatter.format_ticks(majorLocs)
230229

231230
minor = self.axis.minor
232231
minorLocs = minor.locator()
233-
minor.formatter.set_locs(minorLocs)
234232
minorLabels = minor.formatter.format_ticks(minorLocs)
235233

236234
trans_tick = self.get_tick_transform(axes)

lib/mpl_toolkits/axisartist/grid_finder.py

+3-5
Original file line numberDiff line numberDiff line change
@@ -291,11 +291,9 @@ def __init__(self, useMathText=True):
291291
def __call__(self, direction, factor, values):
292292
if not self._ignore_factor:
293293
if factor is None:
294-
factor = 1.
295-
values = [v/factor for v in values]
296-
#values = [v for v in values]
297-
self._fmt.set_locs(values)
298-
return [self._fmt(v) for v in values]
294+
factor = 1
295+
values = [v / factor for v in values]
296+
return self._fmt.format_ticks(values)
299297

300298

301299
class DictFormatter(object):

lib/mpl_toolkits/mplot3d/axis3d.py

+3-8
Original file line numberDiff line numberDiff line change
@@ -135,9 +135,7 @@ def init3d(self):
135135

136136
def get_tick_positions(self):
137137
majorLocs = self.major.locator()
138-
self.major.formatter.set_locs(majorLocs)
139-
majorLabels = [self.major.formatter(val, i)
140-
for i, val in enumerate(majorLocs)]
138+
majorLabels = self.major.formatter.format_ticks(majorLocs)
141139
return majorLabels, majorLocs
142140

143141
def get_major_ticks(self, numticks=None):
@@ -236,11 +234,8 @@ def draw(self, renderer):
236234
locmin, locmax = locmax, locmin
237235

238236
# Rudimentary clipping
239-
majorLocs = [loc for loc in majorLocs if
240-
locmin <= loc <= locmax]
241-
self.major.formatter.set_locs(majorLocs)
242-
majorLabels = [self.major.formatter(val, i)
243-
for i, val in enumerate(majorLocs)]
237+
majorLocs = [loc for loc in majorLocs if locmin <= loc <= locmax]
238+
majorLabels = self.major.format_ticks(majorLocs)
244239

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

0 commit comments

Comments
 (0)