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

Skip to content

Commit 6090828

Browse files
authored
Merge pull request #7292 from efiring/contour_symmetric
BUG: make MaxNLocator.tick_values() obey _symmetric value.
2 parents 568b523 + d4efb18 commit 6090828

File tree

2 files changed

+16
-3
lines changed

2 files changed

+16
-3
lines changed

lib/matplotlib/tests/test_contour.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
from matplotlib.testing.decorators import cleanup, image_comparison
1111
from matplotlib import pyplot as plt
1212
from nose.tools import assert_equal, assert_raises
13+
from numpy.testing import assert_array_almost_equal
1314
import warnings
1415

1516
import re
@@ -292,6 +293,15 @@ def test_contourf_decreasing_levels():
292293
assert_equal(len(w), 2)
293294

294295

296+
@cleanup
297+
def test_contourf_symmetric_locator():
298+
# github issue 7271
299+
z = np.arange(12).reshape((3, 4))
300+
locator = plt.MaxNLocator(nbins=4, symmetric=True)
301+
cs = plt.contourf(z, locator=locator)
302+
assert_array_almost_equal(cs.levels, np.linspace(-12, 12, 5))
303+
304+
295305
if __name__ == '__main__':
296306
import nose
297307
nose.runmodule(argv=['-s', '--with-doctest'], exit=False)

lib/matplotlib/ticker.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1701,9 +1701,13 @@ def __call__(self):
17011701
return self.tick_values(vmin, vmax)
17021702

17031703
def tick_values(self, vmin, vmax):
1704+
if self._symmetric:
1705+
vmax = max(abs(vmin), abs(vmax))
1706+
vmin = -vmax
17041707
vmin, vmax = mtransforms.nonsingular(
17051708
vmin, vmax, expander=1e-13, tiny=1e-14)
17061709
locs = self._raw_ticks(vmin, vmax)
1710+
17071711
prune = self._prune
17081712
if prune == 'lower':
17091713
locs = locs[1:]
@@ -1715,9 +1719,8 @@ def tick_values(self, vmin, vmax):
17151719

17161720
def view_limits(self, dmin, dmax):
17171721
if self._symmetric:
1718-
maxabs = max(abs(dmin), abs(dmax))
1719-
dmin = -maxabs
1720-
dmax = maxabs
1722+
dmax = max(abs(dmin), abs(dmax))
1723+
dmin = -dmax
17211724

17221725
dmin, dmax = mtransforms.nonsingular(
17231726
dmin, dmax, expander=1e-12, tiny=1e-13)

0 commit comments

Comments
 (0)