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

Skip to content

Commit 6bed1be

Browse files
committed
Merge pull request matplotlib#6146 from maqifrnswa/master
API: ticker.LinearLocator view_limits algorithm changes closes matplotlib#6142
2 parents 515ba4b + ed7331d commit 6bed1be

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
@@ -3812,7 +3812,8 @@ def twinx(self):
38123812
create a twin of Axes for generating a plot with a sharex
38133813
x-axis but independent y axis. The y-axis of self will have
38143814
ticks on left and the returned axes will have ticks on the
3815-
right.
3815+
right. To ensure tick marks of both axis align, see
3816+
:class:`~matplotlib.ticker.LinearLocator`
38163817
38173818
.. note::
38183819
For those who are 'picking' artists while using twinx, pick

lib/matplotlib/ticker.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1440,10 +1440,11 @@ def view_limits(self, vmin, vmax):
14401440
vmax += 1
14411441

14421442
if rcParams['axes.autolimit_mode'] == 'round_numbers':
1443-
exponent, remainder = _divmod(math.log10(vmax - vmin), 1)
1443+
exponent, remainder = _divmod(math.log10(vmax - vmin),
1444+
math.log10(max([self.numticks-1, 1])))
14441445
if remainder < 0.5:
14451446
exponent -= 1
1446-
scale = 10 ** (-exponent)
1447+
scale = max([self.numticks-1, 1]) ** (-exponent)
14471448
vmin = math.floor(scale * vmin) / scale
14481449
vmax = math.ceil(scale * vmax) / scale
14491450

0 commit comments

Comments
 (0)
0