Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit ac07e81

Browse files
authored
Merge pull request #13323 from anntzer/formatter.set_locs
Move the call to Formatter.set_locs into Formatter.format_ticks.
2 parents d6899a7 + da55037 commit ac07e81

File tree

7 files changed

+16
-22
lines changed

7 files changed

+16
-22
lines changed

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

Lines changed: 9 additions & 4 deletions
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
11-
`ConciseDateFormatter`.
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_ticks` is intended to be overridden by `Formatter`
15+
subclasses for which the formatting of a tick value depends on other tick
16+
values, such as `ConciseDateFormatter`.

lib/matplotlib/axis.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1017,12 +1017,10 @@ def iter_ticks(self):
10171017
"""
10181018
major_locs = self.major.locator()
10191019
major_ticks = self.get_major_ticks(len(major_locs))
1020-
self.major.formatter.set_locs(major_locs)
10211020
major_labels = self.major.formatter.format_ticks(major_locs)
10221021

10231022
minor_locs = self.minor.locator()
10241023
minor_ticks = self.get_minor_ticks(len(minor_locs))
1025-
self.minor.formatter.set_locs(minor_locs)
10261024
minor_labels = self.minor.formatter.format_ticks(minor_locs)
10271025

10281026
yield from zip(major_ticks, major_locs, major_labels)

lib/matplotlib/colorbar.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -851,7 +851,6 @@ def _ticker(self, locator, formatter):
851851
b = b[(b <= intv[1] + eps) & (b >= intv[0] - eps)]
852852
self._manual_tick_data_values = b
853853
ticks = self._locate(b)
854-
formatter.set_locs(b)
855854
ticklabels = formatter.format_ticks(b)
856855
offset_string = formatter.get_offset()
857856
return ticks, ticklabels, offset_string

lib/matplotlib/ticker.py

Lines changed: 1 addition & 0 deletions
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

Lines changed: 0 additions & 2 deletions
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

Lines changed: 3 additions & 5 deletions
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

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -137,9 +137,7 @@ def init3d(self):
137137
@cbook.deprecated("3.1")
138138
def get_tick_positions(self):
139139
majorLocs = self.major.locator()
140-
self.major.formatter.set_locs(majorLocs)
141-
majorLabels = [self.major.formatter(val, i)
142-
for i, val in enumerate(majorLocs)]
140+
majorLabels = self.major.formatter.format_ticks(majorLocs)
143141
return majorLabels, majorLocs
144142

145143
def get_major_ticks(self, numticks=None):
@@ -238,11 +236,8 @@ def draw(self, renderer):
238236
locmin, locmax = locmax, locmin
239237

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

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

0 commit comments

Comments
 (0)