@@ -3522,10 +3522,11 @@ def _upcast_err(err):
3522
3522
eb_cap_style ['color' ] = ecolor
3523
3523
3524
3524
barcols = []
3525
- caplines = []
3525
+ caplines = { 'x' : [], 'y' : []}
3526
3526
3527
3527
# Vectorized fancy-indexer.
3528
- def apply_mask (arrays , mask ): return [array [mask ] for array in arrays ]
3528
+ def apply_mask (arrays , mask ):
3529
+ return [array [mask ] for array in arrays ]
3529
3530
3530
3531
# dep: dependent dataset, indep: independent dataset
3531
3532
for (dep_axis , dep , err , lolims , uplims , indep , lines_func ,
@@ -3556,9 +3557,15 @@ def apply_mask(arrays, mask): return [array[mask] for array in arrays]
3556
3557
# return dep - elow * ~lolims, dep + ehigh * ~uplims
3557
3558
# except that broadcast_to would strip units.
3558
3559
low , high = dep + np .row_stack ([- (1 - lolims ), 1 - uplims ]) * err
3559
-
3560
- barcols .append (lines_func (
3561
- * apply_mask ([indep , low , high ], everymask ), ** eb_lines_style ))
3560
+ if self .name == "polar" :
3561
+ delta_r = 0
3562
+ if dep_axis == "x" :
3563
+ delta_r = indep * (1 - np .cos ((high - low ).astype (float )/ 2 ))
3564
+ barcols .append (lines_func (
3565
+ * apply_mask ([indep + delta_r , low , high ], everymask ), ** eb_lines_style ))
3566
+ else :
3567
+ barcols .append (lines_func (
3568
+ * apply_mask ([indep , low , high ], everymask ), ** eb_lines_style ))
3562
3569
# Normal errorbars for points without upper/lower limits.
3563
3570
nolims = ~ (lolims | uplims )
3564
3571
if nolims .any () and capsize > 0 :
@@ -3571,7 +3578,7 @@ def apply_mask(arrays, mask): return [array[mask] for array in arrays]
3571
3578
line = mlines .Line2D (indep_masked , indep_masked ,
3572
3579
marker = marker , ** eb_cap_style )
3573
3580
line .set (** {f"{ dep_axis } data" : lh_masked })
3574
- caplines .append (line )
3581
+ caplines [ dep_axis ] .append (line )
3575
3582
for idx , (lims , hl ) in enumerate ([(lolims , high ), (uplims , low )]):
3576
3583
if not lims .any ():
3577
3584
continue
@@ -3585,15 +3592,38 @@ def apply_mask(arrays, mask): return [array[mask] for array in arrays]
3585
3592
line = mlines .Line2D (x_masked , y_masked ,
3586
3593
marker = hlmarker , ** eb_cap_style )
3587
3594
line .set (** {f"{ dep_axis } data" : hl_masked })
3588
- caplines .append (line )
3595
+ caplines [ dep_axis ] .append (line )
3589
3596
if capsize > 0 :
3590
- caplines .append (mlines .Line2D (
3597
+ caplines [ dep_axis ] .append (mlines .Line2D (
3591
3598
x_masked , y_masked , marker = marker , ** eb_cap_style ))
3592
-
3593
- for l in caplines :
3594
- self .add_line (l )
3599
+ if self .name == 'polar' :
3600
+ for axis in caplines :
3601
+ if not caplines [axis ]:
3602
+ continue
3603
+ lo , hi = caplines [axis ]
3604
+ for (lo_theta , lo_r ,
3605
+ hi_theta , hi_r ) in zip (
3606
+ lo .get_xdata (), lo .get_ydata (),
3607
+ hi .get_xdata (), hi .get_ydata ()):
3608
+ # Rotate caps to be perpendicular to the error bars
3609
+ rotation = (lo_theta + hi_theta )/ 2
3610
+ if axis == 'x' :
3611
+ lo_r += lo_r * (1 - np .cos ((hi_theta - lo_theta )/ 2 ))
3612
+ hi_r += hi_r * (1 - np .cos ((hi_theta - lo_theta )/ 2 ))
3613
+ rotation += np .pi / 2
3614
+ ms = mmarkers .MarkerStyle (marker = marker )
3615
+ ms ._transform = mtransforms .Affine2D ().rotate (rotation )
3616
+ self .add_line (mlines .Line2D ([lo_theta ], [lo_r ],
3617
+ marker = ms , ** eb_cap_style ))
3618
+ self .add_line (mlines .Line2D ([hi_theta ], [hi_r ],
3619
+ marker = ms , ** eb_cap_style ))
3620
+ else :
3621
+ for axis in caplines :
3622
+ for l in caplines [axis ]:
3623
+ self .add_line (l )
3595
3624
3596
3625
self ._request_autoscale_view ()
3626
+ caplines = caplines ['x' ] + caplines ['y' ]
3597
3627
errorbar_container = ErrorbarContainer (
3598
3628
(data_line , tuple (caplines ), tuple (barcols )),
3599
3629
has_xerr = (xerr is not None ), has_yerr = (yerr is not None ),
0 commit comments