Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

BUG: make MaxNLocator.tick_values() obey _symmetric value. #7292

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 18, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
BUG: make MaxNLocator.tick_values() obey _symmetric value.
A likely use case is contouring fields such as a velocity
component, where one wants to use a diverging colormap
centered on zero.
Closes #7271.
  • Loading branch information
efiring committed Oct 17, 2016
commit d4efb18547f241567dfe9720a3c5cfed08c12651
10 changes: 10 additions & 0 deletions 10 lib/matplotlib/tests/test_contour.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
from matplotlib.testing.decorators import cleanup, image_comparison
from matplotlib import pyplot as plt
from nose.tools import assert_equal, assert_raises
from numpy.testing import assert_array_almost_equal
import warnings

import re
Expand Down Expand Up @@ -292,6 +293,15 @@ def test_contourf_decreasing_levels():
assert_equal(len(w), 2)


@cleanup
def test_contourf_symmetric_locator():
# github issue 7271
z = np.arange(12).reshape((3, 4))
locator = plt.MaxNLocator(nbins=4, symmetric=True)
cs = plt.contourf(z, locator=locator)
assert_array_almost_equal(cs.levels, np.linspace(-12, 12, 5))


if __name__ == '__main__':
import nose
nose.runmodule(argv=['-s', '--with-doctest'], exit=False)
9 changes: 6 additions & 3 deletions 9 lib/matplotlib/ticker.py
Original file line number Diff line number Diff line change
Expand Up @@ -1701,9 +1701,13 @@ def __call__(self):
return self.tick_values(vmin, vmax)

def tick_values(self, vmin, vmax):
if self._symmetric:
vmax = max(abs(vmin), abs(vmax))
vmin = -vmax
vmin, vmax = mtransforms.nonsingular(
vmin, vmax, expander=1e-13, tiny=1e-14)
locs = self._raw_ticks(vmin, vmax)

prune = self._prune
if prune == 'lower':
locs = locs[1:]
Expand All @@ -1715,9 +1719,8 @@ def tick_values(self, vmin, vmax):

def view_limits(self, dmin, dmax):
if self._symmetric:
maxabs = max(abs(dmin), abs(dmax))
dmin = -maxabs
dmax = maxabs
dmax = max(abs(dmin), abs(dmax))
dmin = -dmax

dmin, dmax = mtransforms.nonsingular(
dmin, dmax, expander=1e-12, tiny=1e-13)
Expand Down
Morty Proxy This is a proxified and sanitized view of the page, visit original site.