@@ -1138,16 +1138,19 @@ class ArtistInspector(object):
11381138 def __init__ (self , o ):
11391139 """
11401140 Initialize the artist inspector with an
1141- :class:`~matplotlib.artist.Artist` or sequence of :class:`Artists`.
1142- If a sequence is used, we assume it is a homogeneous sequence (all
1141+ :class:`~matplotlib.artist.Artist` or iterable of :class:`Artists`.
1142+ If an iterable is used, we assume it is a homogeneous sequence (all
11431143 :class:`Artists` are of the same type) and it is your responsibility
11441144 to make sure this is so.
11451145 """
1146- if cbook .iterable (o ) and len (o ):
1147- o = o [0 ]
1146+ if cbook .iterable (o ):
1147+ # Wrapped in list instead of doing try-except around next(iter(o))
1148+ o = list (o )
1149+ if len (o ):
1150+ o = o [0 ]
11481151
11491152 self .oorig = o
1150- if not isinstance ( o , type ):
1153+ if not inspect . isclass ( o ):
11511154 o = type (o )
11521155 self .o = o
11531156
@@ -1506,8 +1509,8 @@ def setp(obj, *args, **kwargs):
15061509 >>> line, = plot([1,2,3])
15071510 >>> setp(line, linestyle='--')
15081511
1509- If you want to know the valid types of arguments, you can provide the
1510- name of the property you want to set without a value::
1512+ If you want to know the valid types of arguments, you can provide
1513+ the name of the property you want to set without a value::
15111514
15121515 >>> setp(line, 'linestyle')
15131516 linestyle: [ '-' | '--' | '-.' | ':' | 'steps' | 'None' ]
@@ -1518,12 +1521,12 @@ def setp(obj, *args, **kwargs):
15181521 >>> setp(line)
15191522 ... long output listing omitted
15201523
1521- :func:`setp` operates on a single instance or a list of instances.
1522- If you are in query mode introspecting the possible values, only
1523- the first instance in the sequence is used. When actually setting
1524- values, all the instances will be set. e.g., suppose you have a
1525- list of two lines, the following will make both lines thicker and
1526- red::
1524+ :func:`setp` operates on a single instance or a iterable of
1525+ instances. If you are in query mode introspecting the possible
1526+ values, only the first instance in the sequence is used. When
1527+ actually setting values, all the instances will be set. e.g.,
1528+ suppose you have a list of two lines, the following will make both
1529+ lines thicker and red::
15271530
15281531 >>> x = arange(0,1.0,0.01)
15291532 >>> y1 = sin(2*pi*x)
@@ -1538,7 +1541,12 @@ def setp(obj, *args, **kwargs):
15381541 >>> setp(lines, linewidth=2, color='r') # python style
15391542 """
15401543
1541- insp = ArtistInspector (obj )
1544+ if not cbook .iterable (obj ):
1545+ objs = [obj ]
1546+ else :
1547+ objs = list (cbook .flatten (obj ))
1548+
1549+ insp = ArtistInspector (objs [0 ])
15421550
15431551 if len (kwargs ) == 0 and len (args ) == 0 :
15441552 print ('\n ' .join (insp .pprint_setters ()))
@@ -1548,11 +1556,6 @@ def setp(obj, *args, **kwargs):
15481556 print (insp .pprint_setters (prop = args [0 ]))
15491557 return
15501558
1551- if not cbook .iterable (obj ):
1552- objs = [obj ]
1553- else :
1554- objs = list (cbook .flatten (obj ))
1555-
15561559 if len (args ) % 2 :
15571560 raise ValueError ('The set args must be string, value pairs' )
15581561
0 commit comments