@@ -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
@@ -1506,8 +1509,8 @@ def setp(obj, *args, **kwargs):
1506
1509
>>> line, = plot([1,2,3])
1507
1510
>>> setp(line, linestyle='--')
1508
1511
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::
1511
1514
1512
1515
>>> setp(line, 'linestyle')
1513
1516
linestyle: [ '-' | '--' | '-.' | ':' | 'steps' | 'None' ]
@@ -1518,12 +1521,12 @@ def setp(obj, *args, **kwargs):
1518
1521
>>> setp(line)
1519
1522
... long output listing omitted
1520
1523
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::
1527
1530
1528
1531
>>> x = arange(0,1.0,0.01)
1529
1532
>>> y1 = sin(2*pi*x)
@@ -1538,7 +1541,12 @@ def setp(obj, *args, **kwargs):
1538
1541
>>> setp(lines, linewidth=2, color='r') # python style
1539
1542
"""
1540
1543
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 ])
1542
1550
1543
1551
if len (kwargs ) == 0 and len (args ) == 0 :
1544
1552
print ('\n ' .join (insp .pprint_setters ()))
@@ -1548,11 +1556,6 @@ def setp(obj, *args, **kwargs):
1548
1556
print (insp .pprint_setters (prop = args [0 ]))
1549
1557
return
1550
1558
1551
- if not cbook .iterable (obj ):
1552
- objs = [obj ]
1553
- else :
1554
- objs = list (cbook .flatten (obj ))
1555
-
1556
1559
if len (args ) % 2 :
1557
1560
raise ValueError ('The set args must be string, value pairs' )
1558
1561
0 commit comments