Skip to content

Commit 2933275

Browse files
bruswainetimhoffmrcomer
authored
Ensure polar plot radial lower limit remains at 0 after set_rticks + plot (#29798)
Fix #29528 set_rticks makes autoscale move the origin away from zero Co-authored-by: Tim Hoffmann <2836374+timhoffm@users.noreply.github.com> Co-authored-by: Ruth Comer <10599679+rcomer@users.noreply.github.com>
1 parent 06d79ff commit 2933275

File tree

2 files changed

+24
-1
lines changed

2 files changed

+24
-1
lines changed

lib/matplotlib/projections/polar.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1292,7 +1292,10 @@ def set_rscale(self, *args, **kwargs):
12921292
return Axes.set_yscale(self, *args, **kwargs)
12931293

12941294
def set_rticks(self, *args, **kwargs):
1295-
return Axes.set_yticks(self, *args, **kwargs)
1295+
result = Axes.set_yticks(self, *args, **kwargs)
1296+
self.yaxis.set_major_locator(
1297+
self.RadialLocator(self.yaxis.get_major_locator(), self))
1298+
return result
12961299

12971300
def set_thetagrids(self, angles, labels=None, fmt=None, **kwargs):
12981301
"""

lib/matplotlib/tests/test_polar.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -506,3 +506,23 @@ def test_polar_errorbar(order):
506506
ax.errorbar(theta, r, xerr=0.1, yerr=0.1, capsize=7, fmt="o", c="seagreen")
507507
ax.set_theta_zero_location("N")
508508
ax.set_theta_direction(-1)
509+
510+
511+
def test_radial_limits_behavior():
512+
# r=0 is kept as limit if positive data and ticks are used
513+
# negative ticks or data result in negative limits
514+
fig = plt.figure()
515+
ax = fig.add_subplot(projection='polar')
516+
assert ax.get_ylim() == (0, 1)
517+
# upper limit is expanded to include the ticks, but lower limit stays at 0
518+
ax.set_rticks([1, 2, 3, 4])
519+
assert ax.get_ylim() == (0, 4)
520+
# upper limit is autoscaled to data, but lower limit limit stays 0
521+
ax.plot([1, 2], [1, 2])
522+
assert ax.get_ylim() == (0, 2)
523+
# negative ticks also expand the negative limit
524+
ax.set_rticks([-1, 0, 1, 2])
525+
assert ax.get_ylim() == (-1, 2)
526+
# negative data also autoscales to negative limits
527+
ax.plot([1, 2], [-1, -2])
528+
assert ax.get_ylim() == (-2, 2)

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy