File tree Expand file tree Collapse file tree 1 file changed +8
-2
lines changed
Filter options
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,16 +173,22 @@ 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 = abs (vmax - vmin ) / np .pi * 180.0
178
+ digits = max (- int (np .log10 (d ) - 1.5 ), 0 )
179
+
176
180
# \u00b0 : degree symbol
177
181
if rcParams ['text.usetex' ] and not rcParams ['text.latex.unicode' ]:
178
- return r"$%0.0f^\circ$" % ((x / np .pi ) * 180.0 )
182
+ format_str = r"$%%0.%df^\circ$" % (digits , )
183
+ return format_str % ((x / np .pi ) * 180.0 )
179
184
else :
180
185
# we use unicode, rather than mathtext with \circ, so
181
186
# that it will work correctly with any arbitrary font
182
187
# (assuming it has a degree sign), whereas $5\circ$
183
188
# will only work correctly with one of the supported
184
189
# math fonts (Computer Modern and STIX)
185
- return "%0.0f\u00b0 " % ((x / np .pi ) * 180.0 )
190
+ format_str = "%%0.%df\u00b0 " % (digits , )
191
+ return format_str % ((x / np .pi ) * 180.0 )
186
192
187
193
188
194
class ThetaLocator (MaxNLocator ):
You can’t perform that action at this time.
0 commit comments