Skip to content

Commit 62325e9

Browse files
committed
Correct error bar cap orientation in polar plots
1 parent 54d718e commit 62325e9

File tree

3 files changed

+22
-5
lines changed

3 files changed

+22
-5
lines changed

lib/matplotlib/axes/_axes.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3766,17 +3766,21 @@ def apply_mask(arrays, mask):
37663766
caplines[dep_axis].append(mlines.Line2D(
37673767
x_masked, y_masked, marker=marker, **eb_cap_style))
37683768
if self.name == 'polar':
3769+
theta_offset = self.get_theta_offset()
3770+
theta_direction = self.get_theta_direction()
37693771
for axis in caplines:
37703772
for l in caplines[axis]:
3771-
# Rotate caps to be perpendicular to the error bars
37723773
for theta, r in zip(l.get_xdata(), l.get_ydata()):
3773-
rotation = mtransforms.Affine2D().rotate(theta)
3774+
adjusted_theta = theta_direction * theta + theta_offset
37743775
if axis == 'y':
3775-
rotation.rotate(-np.pi / 2)
3776-
ms = mmarkers.MarkerStyle(marker=marker,
3777-
transform=rotation)
3776+
rotation = (mtransforms.Affine2D()
3777+
.rotate(adjusted_theta - np.pi / 2))
3778+
else:
3779+
rotation = mtransforms.Affine2D().rotate(adjusted_theta)
3780+
ms = mmarkers.MarkerStyle(marker=marker, transform=rotation)
37783781
self.add_line(mlines.Line2D([theta], [r], marker=ms,
37793782
**eb_cap_style))
3783+
37803784
else:
37813785
for axis in caplines:
37823786
for l in caplines[axis]:

lib/matplotlib/tests/test_polar.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -481,3 +481,16 @@ def test_polar_neg_theta_lims():
481481
ax.set_thetalim(-np.pi, np.pi)
482482
labels = [l.get_text() for l in ax.xaxis.get_ticklabels()]
483483
assert labels == ['-180°', '-135°', '-90°', '-45°', '0°', '45°', '90°', '135°']
484+
485+
486+
@image_comparison(baseline_images=['polar_errorbar'], remove_text=True,
487+
extensions=['png'], style='mpl20')
488+
def test_polar_errorbar():
489+
theta = np.arange(0, 2 * np.pi, np.pi / 8)
490+
r = theta / np.pi / 2 + 0.5
491+
492+
fig = plt.figure(figsize=(5, 5))
493+
ax = fig.add_subplot(projection='polar')
494+
ax.set_theta_zero_location("N")
495+
ax.set_theta_direction(-1)
496+
ax.errorbar(theta, r, xerr=0.1, yerr=0.1, capsize=7, fmt="o", c="seagreen")

0 commit comments

Comments
 (0)