Skip to content

Commit

Permalink
Merge pull request #6146 from maqifrnswa/master
Browse files Browse the repository at this point in the history
API: ticker.LinearLocator view_limits algorithm changes

closes #6142
  • Loading branch information
tacaswell committed May 13, 2016
1 parent 25bdedd commit e785afb
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 3 deletions.
16 changes: 16 additions & 0 deletions doc/api/api_changes/2015-03-14-SSH.rst
@@ -0,0 +1,16 @@
``matplotlib.ticker.LinearLocator`` algorithm update
```````````````````````````

The ``matplotlib.ticker.LinearLocator`` is used to define the range and location
of tickmarks of a plot when the user wants a exact number of ticks.
``LinearLocator`` thus differs from the default locator ``MaxNLocator``, which
does not necessarily return the exact user requested number of ticks.

The view range algorithm in ``matplotlib.ticker.LinearLocator`` has been
changed so that more convenient tick location are chosen. The new algorithm
returns a plot view range that is a multiple of the user requested number of
ticks. This ensures tick marks to be located at whole integers more
constistently. For example, when both y-axis of a``twinx`` plot use
``matplotlib.ticker.LinearLocator`` with the same number of ticks, the grids of
both axis will be properly aligned at convenient tick locations.

3 changes: 2 additions & 1 deletion lib/matplotlib/axes/_base.py
Expand Up @@ -3762,7 +3762,8 @@ def twinx(self):
create a twin of Axes for generating a plot with a sharex
x-axis but independent y axis. The y-axis of self will have
ticks on left and the returned axes will have ticks on the
right.
right. To ensure tick marks of both axis align, see
:class:`~matplotlib.ticker.LinearLocator`
.. note::
For those who are 'picking' artists while using twinx, pick
Expand Down
5 changes: 3 additions & 2 deletions lib/matplotlib/ticker.py
Expand Up @@ -1348,10 +1348,11 @@ def view_limits(self, vmin, vmax):
vmax += 1

if rcParams['axes.autolimit_mode'] == 'round_numbers':
exponent, remainder = _divmod(math.log10(vmax - vmin), 1)
exponent, remainder = _divmod(math.log10(vmax - vmin),
math.log10(max([self.numticks-1, 1])))
if remainder < 0.5:
exponent -= 1
scale = 10 ** (-exponent)
scale = max([self.numticks-1, 1]) ** (-exponent)
vmin = math.floor(scale * vmin) / scale
vmax = math.ceil(scale * vmax) / scale

Expand Down

0 comments on commit e785afb

Please sign in to comment.