Skip to content

Fix default theta tick locations for non-full-circle polar plots. #20012

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 20, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions doc/api/next_api_changes/behavior/20012-AL.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Default theta tick locations for non-full-circle polar plots have changed
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
For polar plots that don't cover a full circle, the default theta tick
locations are now at multiples of 10°, 15°, 30°, 45°, 90°, rather than using
values that mostly make sense for linear plots (20°, 25°, etc.).
4 changes: 4 additions & 0 deletions lib/matplotlib/projections/polar.py
Original file line number Diff line number Diff line change
Expand Up @@ -393,6 +393,10 @@ def _set_scale(self, value, **kwargs):
raise NotImplementedError(
"The xscale cannot be set on a polar plot")
super()._set_scale(value, **kwargs)
# LinearScale.set_default_locators_and_formatters just set the major
# locator to be an AutoLocator, so we customize it here to have ticks
# at sensible degree multiples.
self.get_major_locator().set_params(steps=[1, 1.5, 3, 4.5, 9, 10])
self._wrap_locator_formatter()

def _copy_tick_props(self, src, dest):
Expand Down
16 changes: 16 additions & 0 deletions lib/matplotlib/tests/test_polar.py
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,8 @@ def test_polar_theta_limits():
direction=DIRECTIONS[i % len(DIRECTIONS)],
rotation='auto')
ax.yaxis.set_tick_params(label2On=True, rotation='auto')
ax.xaxis.get_major_locator().base.set_params( # backcompat
steps=[1, 2, 2.5, 5, 10])


@check_figures_equal(extensions=["png"])
Expand Down Expand Up @@ -357,3 +359,17 @@ def test_thetalim_args():
assert tuple(np.radians((ax.get_thetamin(), ax.get_thetamax()))) == (0, 1)
ax.set_thetalim((2, 3))
assert tuple(np.radians((ax.get_thetamin(), ax.get_thetamax()))) == (2, 3)


def test_default_thetalocator():
# Ideally we would check AAAABBC, but the smallest axes currently puts a
# single tick at 150° because MaxNLocator doesn't have a way to accept 15°
# while rejecting 150°.
fig, axs = plt.subplot_mosaic(
"AAAABB.", subplot_kw={"projection": "polar"})
for ax in axs.values():
ax.set_thetalim(0, np.pi)
for ax in axs.values():
ticklocs = np.degrees(ax.xaxis.get_majorticklocs()).tolist()
assert pytest.approx(90) in ticklocs
assert pytest.approx(100) not in ticklocs