@@ -1138,16 +1138,19 @@ class ArtistInspector(object):
1138
1138
def __init__ (self , o ):
1139
1139
"""
1140
1140
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
1143
1143
:class:`Artists` are of the same type) and it is your responsibility
1144
1144
to make sure this is so.
1145
1145
"""
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 ]
1148
1151
1149
1152
self .oorig = o
1150
- if not isinstance ( o , type ):
1153
+ if not inspect . isclass ( o ):
1151
1154
o = type (o )
1152
1155
self .o = o
1153
1156
@@ -1514,8 +1517,8 @@ def setp(obj, *args, **kwargs):
1514
1517
>>> line, = plot([1,2,3])
1515
1518
>>> setp(line, linestyle='--')
1516
1519
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::
1519
1522
1520
1523
>>> setp(line, 'linestyle')
1521
1524
linestyle: [ '-' | '--' | '-.' | ':' | 'steps' | 'None' ]
@@ -1526,12 +1529,12 @@ def setp(obj, *args, **kwargs):
1526
1529
>>> setp(line)
1527
1530
... long output listing omitted
1528
1531
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::
1535
1538
1536
1539
>>> x = arange(0,1.0,0.01)
1537
1540
>>> y1 = sin(2*pi*x)
@@ -1546,7 +1549,12 @@ def setp(obj, *args, **kwargs):
1546
1549
>>> setp(lines, linewidth=2, color='r') # python style
1547
1550
"""
1548
1551
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 ])
1550
1558
1551
1559
if len (kwargs ) == 0 and len (args ) == 0 :
1552
1560
print ('\n ' .join (insp .pprint_setters ()))
@@ -1556,11 +1564,6 @@ def setp(obj, *args, **kwargs):
1556
1564
print (insp .pprint_setters (prop = args [0 ]))
1557
1565
return
1558
1566
1559
- if not cbook .iterable (obj ):
1560
- objs = [obj ]
1561
- else :
1562
- objs = list (cbook .flatten (obj ))
1563
-
1564
1567
if len (args ) % 2 :
1565
1568
raise ValueError ('The set args must be string, value pairs' )
1566
1569
0 commit comments