Skip to content

Commit

Permalink
Backport PR matplotlib#27578: Fix polar labels with negative theta limit
Browse files Browse the repository at this point in the history
  • Loading branch information
timhoffm authored and meeseeksmachine committed Dec 29, 2023
1 parent 1566e5e commit 2e01b0c
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/matplotlib/projections/polar.py
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,7 @@ def set_axis(self, axis):
def __call__(self):
lim = self.axis.get_view_interval()
if _is_full_circle_deg(lim[0], lim[1]):
return np.arange(8) * 2 * np.pi / 8
return np.deg2rad(min(lim)) + np.arange(8) * 2 * np.pi / 8
else:
return np.deg2rad(self.base())

Expand Down
8 changes: 8 additions & 0 deletions lib/matplotlib/tests/test_polar.py
Original file line number Diff line number Diff line change
Expand Up @@ -446,3 +446,11 @@ def test_polar_log():

n = 100
ax.plot(np.linspace(0, 2 * np.pi, n), np.logspace(0, 2, n))


def test_polar_neg_theta_lims():
fig = plt.figure()
ax = fig.add_subplot(projection='polar')
ax.set_thetalim(-np.pi, np.pi)
labels = [l.get_text() for l in ax.xaxis.get_ticklabels()]
assert labels == ['-180°', '-135°', '-90°', '-45°', '0°', '45°', '90°', '135°']

0 comments on commit 2e01b0c

Please sign in to comment.