File tree Expand file tree Collapse file tree
lib/matplotlib/projections Expand file tree Collapse file tree Original file line number Diff line number Diff 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
187193class RadialLocator (Locator ):
You can’t perform that action at this time.
0 commit comments