File tree Expand file tree Collapse file tree 2 files changed +16
-3
lines changed
Filter options
Expand file tree Collapse file tree 2 files changed +16
-3
lines changed
Original file line number Diff line number Diff line change 10
10
from matplotlib .testing .decorators import cleanup , image_comparison
11
11
from matplotlib import pyplot as plt
12
12
from nose .tools import assert_equal , assert_raises
13
+ from numpy .testing import assert_array_almost_equal
13
14
import warnings
14
15
15
16
import re
@@ -292,6 +293,15 @@ def test_contourf_decreasing_levels():
292
293
assert_equal (len (w ), 2 )
293
294
294
295
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
+
295
305
if __name__ == '__main__' :
296
306
import nose
297
307
nose .runmodule (argv = ['-s' , '--with-doctest' ], exit = False )
Original file line number Diff line number Diff line change @@ -1701,9 +1701,13 @@ def __call__(self):
1701
1701
return self .tick_values (vmin , vmax )
1702
1702
1703
1703
def tick_values (self , vmin , vmax ):
1704
+ if self ._symmetric :
1705
+ vmax = max (abs (vmin ), abs (vmax ))
1706
+ vmin = - vmax
1704
1707
vmin , vmax = mtransforms .nonsingular (
1705
1708
vmin , vmax , expander = 1e-13 , tiny = 1e-14 )
1706
1709
locs = self ._raw_ticks (vmin , vmax )
1710
+
1707
1711
prune = self ._prune
1708
1712
if prune == 'lower' :
1709
1713
locs = locs [1 :]
@@ -1715,9 +1719,8 @@ def tick_values(self, vmin, vmax):
1715
1719
1716
1720
def view_limits (self , dmin , dmax ):
1717
1721
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
1721
1724
1722
1725
dmin , dmax = mtransforms .nonsingular (
1723
1726
dmin , dmax , expander = 1e-12 , tiny = 1e-13 )
You can’t perform that action at this time.
0 commit comments