Repository: climate
Updated Branches:
  refs/heads/master 90b1b9ffe -> bd1b8edef


Make automatic contour intervals consistent between matplotlib versions


Project: http://git-wip-us.apache.org/repos/asf/climate/repo
Commit: http://git-wip-us.apache.org/repos/asf/climate/commit/bd1b8ede
Tree: http://git-wip-us.apache.org/repos/asf/climate/tree/bd1b8ede
Diff: http://git-wip-us.apache.org/repos/asf/climate/diff/bd1b8ede

Branch: refs/heads/master
Commit: bd1b8edef58b73abfaf873d46bebf125b8fbc8c5
Parents: 90b1b9f
Author: Alex Goodman <[email protected]>
Authored: Wed Feb 22 16:11:15 2017 -0800
Committer: Alex Goodman <[email protected]>
Committed: Wed Feb 22 16:11:15 2017 -0800

----------------------------------------------------------------------
 ocw/plotter.py | 15 ++++++++++-----
 1 file changed, 10 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/climate/blob/bd1b8ede/ocw/plotter.py
----------------------------------------------------------------------
diff --git a/ocw/plotter.py b/ocw/plotter.py
index dafa8ad..9e2e0ad 100755
--- a/ocw/plotter.py
+++ b/ocw/plotter.py
@@ -65,20 +65,25 @@ def _nice_intervals(data, nlevs):
     data = data.ravel()
     mn = mstats.scoreatpercentile(data, 5)
     mx = mstats.scoreatpercentile(data, 95)
-    # if there min less than 0 and
-    # or max more than 0
-    # put 0 in center of color bar
+    # if min less than 0 and or max more than 0 put 0 in center of color bar
     if mn < 0 and mx > 0:
         level = max(abs(mn), abs(mx))
         mnlvl = -1 * level
         mxlvl = level
-    # if min is larger than 0 then
-    # have color bar between min and max
+    # if min is larger than 0 then have color bar between min and max
     else:
         mnlvl = mn
         mxlvl = mx
+    
+    # hack to make generated intervals from mpl the same for all versions
+    autolimit_mode = mpl.rcParams.get('axes.autolimit_mode')
+    if autolimit_mode:
+        mpl.rc('axes', autolimit_mode='round_numbers')
+    
     locator = mpl.ticker.MaxNLocator(nlevs)
     clevs = locator.tick_values(mnlvl, mxlvl)
+    if autolimit_mode:
+        mpl.rc('axes', autolimit_mode=autolimit_mode)
 
     # Make sure the bounds of clevs are reasonable since sometimes
     # MaxNLocator gives values outside the domain of the input data

Reply via email to