File tree Expand file tree Collapse file tree 2 files changed +20
-13
lines changed
Filter options
Expand file tree Collapse file tree 2 files changed +20
-13
lines changed
Original file line number Diff line number Diff line change 7
7
import six
8
8
from six .moves import xrange
9
9
10
+ from numbers import Integral
10
11
import warnings
12
+
11
13
import matplotlib as mpl
12
14
import numpy as np
13
15
from numpy import ma
@@ -1206,21 +1208,15 @@ def _contour_level_args(self, z, args):
1206
1208
self ._auto = False
1207
1209
if self .levels is None :
1208
1210
if len (args ) == 0 :
1209
- lev = self . _autolev ( 7 )
1211
+ levels_arg = 7 # Default, hard-wired.
1210
1212
else :
1211
- level_arg = args [0 ]
1212
- try :
1213
- if type (level_arg ) == int :
1214
- lev = self ._autolev (level_arg )
1215
- else :
1216
- lev = np .asarray (level_arg ).astype (np .float64 )
1217
- except :
1218
- raise TypeError (
1219
- "Last {0} arg must give levels; see help({0})"
1220
- .format (fn ))
1221
- self .levels = lev
1213
+ levels_arg = args [0 ]
1214
+ else :
1215
+ levels_arg = self .levels
1216
+ if isinstance (levels_arg , Integral ):
1217
+ self .levels = self ._autolev (levels_arg )
1222
1218
else :
1223
- self .levels = np .asarray (self . levels ).astype (np .float64 )
1219
+ self .levels = np .asarray (levels_arg ).astype (np .float64 )
1224
1220
1225
1221
if not self .filled :
1226
1222
inside = (self .levels > self .zmin ) & (self .levels < self .zmax )
Original file line number Diff line number Diff line change @@ -131,6 +131,17 @@ def test_contour_empty_levels():
131
131
assert len (record ) == 1
132
132
133
133
134
+ def test_contour_Nlevels ():
135
+ # A scalar levels arg or kwarg should trigger auto level generation.
136
+ # https://github.com/matplotlib/matplotlib/issues/11913
137
+ z = np .arange (12 ).reshape ((3 , 4 ))
138
+ fig , ax = plt .subplots ()
139
+ cs1 = ax .contour (z , 5 )
140
+ assert len (cs1 .levels ) > 1
141
+ cs2 = ax .contour (z , levels = 5 )
142
+ assert (cs1 .levels == cs2 .levels ).all ()
143
+
144
+
134
145
def test_contour_badlevel_fmt ():
135
146
# test funny edge case from
136
147
# https://github.com/matplotlib/matplotlib/issues/9742
You can’t perform that action at this time.
0 commit comments