Skip to content

[Bug]: Polar plot error bars don't rotate with angle for set_theta_direction and set_theta_offset #27784

@th0ger

Description

@th0ger

Bug summary

Reopening #441 since the fix seems not to work on two corner cases:

  • Clockwise direction with set_theta_direction(-1)
  • Angle offset set by set_theta_offset(np.pi/2)

Code for reproduction

from numpy import *
from matplotlib import pyplot as py

r = zeros([16])
err = zeros([16])
for i in range(16):
    r[i] = random.randint(400, 600)
    err[i] = random.randint(20, 50)
theta = arange(0, 2 * pi, 2 * pi / 16)
width = pi * 2 / 16

fig = py.figure(figsize=(8, 8))
ax = fig.add_axes([0.1, 0.1, 0.75, 0.79], polar=True)

bars = ax.bar(
    theta + pi / 16,
    r,
    width=width,
    bottom=0.0,
    yerr=err,
    capsize=15 # Capsize set to exaggerate issue
    )  
ax.set_ylim(0, 700)

ax.set_theta_direction(-1)  # Clockwise direction

py.show()
from numpy import *
from matplotlib import pyplot as py

r = zeros([16])
err = zeros([16])
for i in range(16):
    r[i] = random.randint(400, 600)
    err[i] = random.randint(20, 50)
theta = arange(0, 2 * pi, 2 * pi / 16)
width = pi * 2 / 16

fig = py.figure(figsize=(8, 8))
ax = fig.add_axes([0.1, 0.1, 0.75, 0.79], polar=True)

bars = ax.bar(
    theta + pi / 16,
    r,
    width=width,
    bottom=0.0,
    yerr=err,
    capsize=15 # Capsize set to exaggerate issue
    )  
ax.set_ylim(0, 700)

ax.set_theta_offset(np.pi/2)  # Start from the top

py.show()

Actual outcome

image
image

Expected outcome

Errorbar caps perpendicular to the error bars.

Additional information

No response

Operating system

Ubuntu

Matplotlib Version

3.8.1

Matplotlib Backend

agg

Python version

3.11.4

Jupyter version

7.0.6

Installation

None

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions