From 41d733e01201dcb58ac342bad1f3d9da5aa93574 Mon Sep 17 00:00:00 2001 From: cdubUF <128617287+cdubUF@users.noreply.github.com> Date: Fri, 4 Oct 2024 00:38:47 +0000 Subject: [PATCH] By adjusting the rotation calculation with theta_direction and theta_offset, you ensure that the error bar caps are properly aligned when the polar plot has non-default settings for theta direction or zero location. --- lib/matplotlib/axes/_axes.py | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/lib/matplotlib/axes/_axes.py b/lib/matplotlib/axes/_axes.py index de0c6854cbb1..b2ac1b7e3437 100644 --- a/lib/matplotlib/axes/_axes.py +++ b/lib/matplotlib/axes/_axes.py @@ -3766,17 +3766,23 @@ def apply_mask(arrays, mask): caplines[dep_axis].append(mlines.Line2D( x_masked, y_masked, marker=marker, **eb_cap_style)) if self.name == 'polar': + # Get theta direction and theta offset for proper cap alignment + theta_direction = self.get_theta_direction() + theta_offset = self.get_theta_offset() + for axis in caplines: for l in caplines[axis]: # Rotate caps to be perpendicular to the error bars for theta, r in zip(l.get_xdata(), l.get_ydata()): - rotation = mtransforms.Affine2D().rotate(theta) + # Adjust rotation using theta direction and offset + rotation = mtransforms.Affine2D().rotate((theta * theta_direction) + theta_offset) + if axis == 'y': rotation.rotate(-np.pi / 2) - ms = mmarkers.MarkerStyle(marker=marker, - transform=rotation) - self.add_line(mlines.Line2D([theta], [r], marker=ms, - **eb_cap_style)) + + ms = mmarkers.MarkerStyle(marker=marker, transform=rotation) + self.add_line(mlines.Line2D([theta], [r], marker=ms, **eb_cap_style)) + else: for axis in caplines: for l in caplines[axis]: