Skip to content

Commit 0b6cc58

Browse files
committed
ENH: Don't round degree digits when zoomed on PolarAxes.
1 parent 3809803 commit 0b6cc58

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

lib/matplotlib/projections/polar.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -173,15 +173,21 @@ class ThetaFormatter(Formatter):
173173
unit of radians into degrees and adds a degree symbol.
174174
"""
175175
def __call__(self, x, pos=None):
176+
vmin, vmax = self.axis.get_view_interval()
177+
d = np.rad2deg(abs(vmax - vmin))
178+
digits = max(-int(np.log10(d) - 1.5), 0)
179+
176180
if rcParams['text.usetex'] and not rcParams['text.latex.unicode']:
177-
return r"$%0.0f^\circ$" % ((x / np.pi) * 180.0)
181+
format_str = r"${value:0.{digits:d}f}^\circ$"
182+
return format_str.format(value=np.rad2deg(x), digits=digits)
178183
else:
179184
# we use unicode, rather than mathtext with \circ, so
180185
# that it will work correctly with any arbitrary font
181186
# (assuming it has a degree sign), whereas $5\circ$
182187
# will only work correctly with one of the supported
183188
# math fonts (Computer Modern and STIX)
184-
return "%0.0f\N{DEGREE SIGN}" % ((x / np.pi) * 180.0)
189+
format_str = "{value:0.{digits:d}f}\N{DEGREE SIGN}"
190+
return format_str.format(value=np.rad2deg(x), digits=digits)
185191

186192

187193
class RadialLocator(Locator):

0 commit comments

Comments
 (0)