Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 5c8cf78

Browse filesBrowse files
authored
Merge pull request #20012 from anntzer/pt
Fix default theta tick locations for non-full-circle polar plots.
2 parents 6015417 + 90161c0 commit 5c8cf78
Copy full SHA for 5c8cf78

File tree

Expand file treeCollapse file tree

3 files changed

+25
-0
lines changed
Filter options
Expand file treeCollapse file tree

3 files changed

+25
-0
lines changed
+5Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
Default theta tick locations for non-full-circle polar plots have changed
2+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
3+
For polar plots that don't cover a full circle, the default theta tick
4+
locations are now at multiples of 10°, 15°, 30°, 45°, 90°, rather than using
5+
values that mostly make sense for linear plots (20°, 25°, etc.).

‎lib/matplotlib/projections/polar.py

Copy file name to clipboardExpand all lines: lib/matplotlib/projections/polar.py
+4Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -393,6 +393,10 @@ def _set_scale(self, value, **kwargs):
393393
raise NotImplementedError(
394394
"The xscale cannot be set on a polar plot")
395395
super()._set_scale(value, **kwargs)
396+
# LinearScale.set_default_locators_and_formatters just set the major
397+
# locator to be an AutoLocator, so we customize it here to have ticks
398+
# at sensible degree multiples.
399+
self.get_major_locator().set_params(steps=[1, 1.5, 3, 4.5, 9, 10])
396400
self._wrap_locator_formatter()
397401

398402
def _copy_tick_props(self, src, dest):

‎lib/matplotlib/tests/test_polar.py

Copy file name to clipboardExpand all lines: lib/matplotlib/tests/test_polar.py
+16Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,8 @@ def test_polar_theta_limits():
249249
direction=DIRECTIONS[i % len(DIRECTIONS)],
250250
rotation='auto')
251251
ax.yaxis.set_tick_params(label2On=True, rotation='auto')
252+
ax.xaxis.get_major_locator().base.set_params( # backcompat
253+
steps=[1, 2, 2.5, 5, 10])
252254

253255

254256
@check_figures_equal(extensions=["png"])
@@ -357,3 +359,17 @@ def test_thetalim_args():
357359
assert tuple(np.radians((ax.get_thetamin(), ax.get_thetamax()))) == (0, 1)
358360
ax.set_thetalim((2, 3))
359361
assert tuple(np.radians((ax.get_thetamin(), ax.get_thetamax()))) == (2, 3)
362+
363+
364+
def test_default_thetalocator():
365+
# Ideally we would check AAAABBC, but the smallest axes currently puts a
366+
# single tick at 150° because MaxNLocator doesn't have a way to accept 15°
367+
# while rejecting 150°.
368+
fig, axs = plt.subplot_mosaic(
369+
"AAAABB.", subplot_kw={"projection": "polar"})
370+
for ax in axs.values():
371+
ax.set_thetalim(0, np.pi)
372+
for ax in axs.values():
373+
ticklocs = np.degrees(ax.xaxis.get_majorticklocs()).tolist()
374+
assert pytest.approx(90) in ticklocs
375+
assert pytest.approx(100) not in ticklocs

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.