8000 Merge pull request #6146 from maqifrnswa/master · matplotlib/matplotlib@e785afb · GitHub
[go: up one dir, main page]

Skip to content

Commit e785afb

Browse files
committed
Merge pull request #6146 from maqifrnswa/master
API: ticker.LinearLocator view_limits algorithm changes closes #6142
1 parent 25bdedd commit e785afb

File tree

3 files changed

+21
-3
lines changed

3 files changed

+21
-3
lines changed
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
``matplotlib.ticker.LinearLocator`` algorithm update
2+
```````````````````````````
3+
4+
The ``matplotlib.ticker.LinearLocator`` is used to define the range and location
5+
of tickmarks of a plot when the user wants a exact number of ticks.
6+
``LinearLocator`` thus differs from the default locator ``MaxNLocator``, which
7+
does not necessarily return the exact user requested number of ticks.
8+
9+
The view range algorithm in ``matplotlib.ticker.LinearLocator`` has been
10+
changed so that more convenient tick location are chosen. The new algorithm
11+
returns a plot view range that is a multiple of the user requested number of
12+
ticks. This ensures tick marks to be located at whole integers more
13+
constistently. For example, when both y-axis of a``twinx`` plot use
14+
``matplotlib.ticker.LinearLocator`` with the same number of ticks, the grids of
15+
both axis will be properly aligned at convenient tick locations.
16+

lib/matplotlib/axes/_base.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3762,7 +3762,8 @@ def twinx(self):
37623762
create a twin of Axes for generating a plot with a sharex
37633763
x-axis but independent y axis. The y-axis of self will have
37643764
ticks on left and the returned axes will have ticks on the
3765-
right.
3765+
right. To ensure tick marks of both axis align, see
3766+
:class:`~matplotlib.ticker.LinearLocator`
37663767
37673768
.. note::
37683769
For those who are 'picking' artists while using twinx, pick

lib/matplotlib/ticker.py

Lines changed: 3 additions & 2 deletions
< 8F5E /div>
Original file line numberDiff line numberDiff line change
@@ -1348,10 +1348,11 @@ def view_limits(self, vmin, vmax):
13481348
vmax += 1
13491349

13501350
if rcParams['axes.autolimit_mode'] == 'round_numbers':
1351-
exponent, remainder = _divmod(math.log10(vmax - vmin), 1)
1351+
exponent, remainder = _divmod(math.log10(vmax - vmin),
1352+
math.log10(max([self.numticks-1, 1])))
13521353
if remainder < 0.5:
13531354
exponent -= 1
1354-
scale = 10 ** (-exponent)
1355+
scale = max([self.numticks-1, 1]) ** (-exponent)
13551356
vmin = math.floor(scale * vmin) / scale
13561357
vmax = math.ceil(scale * vmax) / scale
13571358

0 commit comments

Comments
 (0)
0