@@ -3505,7 +3505,7 @@ def pie(self, x, explode=None, labels=None,
3505
3505
texts = []
3506
3506
slices = []
3507
3507
autotexts = []
3508
- for frac , label , expl in zip (x ,labels , explode ):
3508
+ for frac , label , expl in cbook . safezip (x ,labels , explode ):
3509
3509
x , y = center
3510
3510
theta2 = theta1 + frac
3511
3511
thetam = 2 * math .pi * 0.5 * (theta1 + theta2 )
@@ -3645,11 +3645,11 @@ def errorbar(self, x, y, yerr=None, xerr=None,
3645
3645
3646
3646
if xerr is not None :
3647
3647
if not iterable (xerr ):
3648
- xerr = [xerr ]
3648
+ xerr = [xerr ]* len ( x )
3649
3649
3650
3650
if yerr is not None :
3651
3651
if not iterable (yerr ):
3652
- yerr = [yerr ]
3652
+ yerr = [yerr ]* len ( y )
3653
3653
3654
3654
l0 = None
3655
3655
@@ -3679,6 +3679,18 @@ def errorbar(self, x, y, yerr=None, xerr=None,
3679
3679
if not iterable (xuplims ): xuplims = npy .array ([xuplims ]* len (x ), bool )
3680
3680
else : xuplims = npy .asarray (xuplims , bool )
3681
3681
3682
+ def xywhere (xs , ys , mask ):
3683
+ """
3684
+ return xs[mask], ys[mask] where mask is True but xs and
3685
+ ys are not arrays
3686
+ """
3687
+ assert len (xs )== len (ys )
3688
+ assert len (xs )== len (mask )
3689
+ xs = [thisx for thisx , b in zip (xs , mask ) if b ]
3690
+ ys = [thisy for thisy , b in zip (ys , mask ) if b ]
3691
+ return xs , ys
3692
+
3693
+
3682
3694
if capsize > 0 :
3683
3695
plot_kw = {
3684
3696
'ms' :2 * capsize ,
@@ -3691,53 +3703,66 @@ def errorbar(self, x, y, yerr=None, xerr=None,
3691
3703
if xerr is not None :
3692
3704
if iterable (xerr ) and len (xerr )== 2 :
3693
3705
# using list comps rather than arrays to preserve units
3694
- left = [thisx - thiserr for (thisx , thiserr ) in zip (x ,xerr [0 ])]
3695
- right = [thisx + thiserr for (thisx , thiserr ) in zip (x ,xerr [1 ])]
3706
+ left = [thisx - thiserr for (thisx , thiserr ) in cbook . safezip (x ,xerr [0 ])]
3707
+ right = [thisx + thiserr for (thisx , thiserr ) in cbook . safezip (x ,xerr [1 ])]
3696
3708
else :
3697
3709
# using list comps rather than arrays to preserve units
3698
- left = [thisx - thiserr for (thisx , thiserr ) in zip (x ,xerr )]
3699
- right = [thisx + thiserr for (thisx , thiserr ) in zip (x ,xerr )]
3710
+ left = [thisx - thiserr for (thisx , thiserr ) in cbook . safezip (x ,xerr )]
3711
+ right = [thisx + thiserr for (thisx , thiserr ) in cbook . safezip (x ,xerr )]
3700
3712
3701
3713
barcols .append ( self .hlines (y , left , right , ** lines_kw ) )
3702
3714
if capsize > 0 :
3703
3715
if xlolims .any ():
3704
- caplines .extend ( self .plot (left [xlolims ], y [xlolims ], ls = 'None' , marker = mlines .CARETLEFT , ** plot_kw ) )
3716
+ # can't use numpy logical indexing since left and
3717
+ # y are lists
3718
+ leftlo , ylo = xywhere (left , y , xlolims )
3719
+
3720
+ caplines .extend ( self .plot (leftlo , ylo , ls = 'None' , marker = mlines .CARETLEFT , ** plot_kw ) )
3705
3721
xlolims = ~ xlolims
3706
- caplines .extend ( self .plot (left [xlolims ], y [xlolims ], 'k|' , ** plot_kw ) )
3722
+ leftlo , ylo = xywhere (left , y , xlolims )
3723
+ caplines .extend ( self .plot (leftlo , ylo , 'k|' , ** plot_kw ) )
3707
3724
else :
3708
3725
caplines .extend ( self .plot (left , y , 'k|' , ** plot_kw ) )
3709
3726
3710
3727
if xuplims .any ():
3711
- caplines .extend ( self .plot (right [xuplims ], y [xuplims ], ls = 'None' , marker = mlines .CARETRIGHT , ** plot_kw ) )
3728
+
3729
+ rightup , yup = xywhere (right , y , xuplims )
3730
+ caplines .extend ( self .plot (rightup , yup , ls = 'None' , marker = mlines .CARETRIGHT , ** plot_kw ) )
3712
3731
xuplims = ~ xuplims
3713
- caplines .extend ( self .plot (right [xuplims ], y [xuplims ], 'k|' , ** plot_kw ) )
3732
+ rightup , yup = xywhere (right , y , xuplims )
3733
+ caplines .extend ( self .plot (rightup , yup , 'k|' , ** plot_kw ) )
3714
3734
else :
3715
3735
caplines .extend ( self .plot (right , y , 'k|' , ** plot_kw ) )
3716
3736
3717
3737
if yerr is not None :
3718
3738
if iterable (yerr ) and len (yerr )== 2 :
3719
3739
# using list comps rather than arrays to preserve units
3720
- lower = [thisy - thiserr for (thisy , thiserr ) in zip (y ,yerr [0 ])]
3721
- upper = [thisy + thiserr for (thisy , thiserr ) in zip (y ,yerr [1 ])]
3740
+ lower = [thisy - thiserr for (thisy , thiserr ) in cbook . safezip (y ,yerr [0 ])]
3741
+ upper = [thisy + thiserr for (thisy , thiserr ) in cbook . safezip (y ,yerr [1 ])]
3722
3742
else :
3723
3743
# using list comps rather than arrays to preserve units
3724
- lower = [thisy - thiserr for (thisy , thiserr ) in zip (y ,yerr )]
3725
- upper = [thisy + thiserr for (thisy , thiserr ) in zip (y ,yerr )]
3744
+ lower = [thisy - thiserr for (thisy , thiserr ) in cbook . safezip (y ,yerr )]
3745
+ upper = [thisy + thiserr for (thisy , thiserr ) in cbook . safezip (y ,yerr )]
3726
3746
3727
3747
barcols .append ( self .vlines (x , lower , upper , ** lines_kw ) )
3728
3748
if capsize > 0 :
3729
3749
3730
3750
if lolims .any ():
3731
- caplines .extend ( self .plot (x [lolims ], lower [lolims ], ls = 'None' , marker = mlines .CARETDOWN , ** plot_kw ) )
3751
+ xlo , lowerlo = xywhere (x , lower , lolims )
3752
+ caplines .extend ( self .plot (xlo , lowerlo , ls = 'None' , marker = mlines .CARETDOWN , ** plot_kw ) )
3732
3753
lolims = ~ lolims
3733
- caplines .extend ( self .plot (x [lolims ], lower [lolims ], 'k_' , ** plot_kw ) )
3754
+ xlo , lowerlo = xywhere (x , lower , lolims )
3755
+ caplines .extend ( self .plot (xlo , lowerlo , 'k_' , ** plot_kw ) )
3734
3756
else :
3735
3757
caplines .extend ( self .plot (x , lower , 'k_' , ** plot_kw ) )
3736
3758
3737
3759
if uplims .any ():
3738
- caplines .extend ( self .plot (x [uplims ], upper [uplims ], ls = 'None' , marker = mlines .CARETUP , ** plot_kw ) )
3760
+ xup , upperup = xywhere (x , upper , uplims )
3761
+
3762
+ caplines .extend ( self .plot (xup , upperup , ls = 'None' , marker = mlines .CARETUP , ** plot_kw ) )
3739
3763
uplims = ~ uplims
3740
- caplines .extend ( self .plot (x [uplims ], upper [uplims ], 'k_' , ** plot_kw ) )
3764
+ xup , upperup = xywhere (x , upper , uplims )
3765
+ caplines .extend ( self .plot (xup , upperup , 'k_' , ** plot_kw ) )
3741
3766
else :
3742
3767
caplines .extend ( self .plot (x , upper , 'k_' , ** plot_kw ) )
3743
3768
0 commit comments