@@ -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
@@ -1514,8 +1517,8 @@ def setp(obj, *args, **kwargs):
15141517 >>> line, = plot([1,2,3])
15151518 >>> setp(line, linestyle='--')
15161519
1517- If you want to know the valid types of arguments, you can provide the
1518- name of the property you want to set without a value::
1520+ If you want to know the valid types of arguments, you can provide
1521+ the name of the property you want to set without a value::
15191522
15201523 >>> setp(line, 'linestyle')
15211524 linestyle: [ '-' | '--' | '-.' | ':' | 'steps' | 'None' ]
@@ -1526,12 +1529,12 @@ def setp(obj, *args, **kwargs):
15261529 >>> setp(line)
15271530 ... long output listing omitted
15281531
1529- :func:`setp` operates on a single instance or a list of instances.
1530- If you are in query mode introspecting the possible values, only
1531- the first instance in the sequence is used. When actually setting
1532- values, all the instances will be set. e.g., suppose you have a
1533- list of two lines, the following will make both lines thicker and
1534- red::
1532+ :func:`setp` operates on a single instance or a iterable of
1533+ instances. If you are in query mode introspecting the possible
1534+ values, only the first instance in the sequence is used. When
1535+ actually setting values, all the instances will be set. e.g.,
1536+ suppose you have a list of two lines, the following will make both
1537+ lines thicker and red::
15351538
15361539 >>> x = arange(0,1.0,0.01)
15371540 >>> y1 = sin(2*pi*x)
@@ -1546,7 +1549,12 @@ def setp(obj, *args, **kwargs):
15461549 >>> setp(lines, linewidth=2, color='r') # python style
15471550 """
15481551
1549- insp = ArtistInspector (obj )
1552+ if not cbook .iterable (obj ):
1553+ objs = [obj ]
1554+ else :
1555+ objs = list (cbook .flatten (obj ))
1556+
1557+ insp = ArtistInspector (objs [0 ])
15501558
15511559 if len (kwargs ) == 0 and len (args ) == 0 :
15521560 print ('\n ' .join (insp .pprint_setters ()))
@@ -1556,11 +1564,6 @@ def setp(obj, *args, **kwargs):
15561564 print (insp .pprint_setters (prop = args [0 ]))
15571565 return
15581566
1559- if not cbook .iterable (obj ):
1560- objs = [obj ]
1561- else :
1562- objs = list (cbook .flatten (obj ))
1563-
15641567 if len (args ) % 2 :
15651568 raise ValueError ('The set args must be string, value pairs' )
15661569
0 commit comments