File tree Expand file tree Collapse file tree 1 file changed +8
-2
lines changed
lib/matplotlib/projections Expand file tree Collapse file tree 1 file changed +8
-2
lines changed Original file line number Diff line number Diff line change @@ -173,15 +173,21 @@ class ThetaFormatter(Formatter):
173
173
unit of radians into degrees and adds a degree symbol.
174
174
"""
175
175
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
+
176
180
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 )
178
183
else :
179
184
# we use unicode, rather than mathtext with \circ, so
180
185
# that it will work correctly with any arbitrary font
181
186
# (assuming it has a degree sign), whereas $5\circ$
182
187
# will only work correctly with one of the supported
183
188
# 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 )
185
191
186
192
187
193
class RadialLocator (Locator ):
You can’t perform that action at this time.
0 commit comments