@@ -146,8 +146,13 @@ def set_coord_type(self, coord_type, coord_wrap=None):
146146
147147 # Initialize tick formatter/locator
148148 if coord_type == 'scalar' :
149+ self ._coord_unit_scale = None
149150 self ._formatter_locator = ScalarFormatterLocator (unit = self .coord_unit )
150151 elif coord_type in ['longitude' , 'latitude' ]:
152+ if self .coord_unit is u .deg :
153+ self ._coord_unit_scale = None
154+ else :
155+ self ._coord_unit_scale = self .coord_unit .to (u .deg )
151156 self ._formatter_locator = AngleFormatterLocator ()
152157 else :
153158 raise ValueError ("coord_type should be one of 'scalar', 'longitude', or 'latitude'" )
@@ -174,16 +179,25 @@ def format_coord(self, value):
174179 Given the value of a coordinate, will format it according to the
175180 format of the formatter_locator.
176181 """
182+
177183 if not hasattr (self , "_fl_spacing" ):
178184 return "" # _update_ticks has not been called yet
185+
179186 fl = self ._formatter_locator
180187 if isinstance (fl , AngleFormatterLocator ):
188+
189+ # Convert to degrees if needed
190+ if self ._coord_unit_scale is not None :
191+ value *= self ._coord_unit_scale
192+
181193 if self .coord_type == 'longitude' :
182194 value = wrap_angle_at (value , self .coord_wrap )
183195 value = value * u .degree
184196 value = value .to (fl ._unit ).value
197+
185198 spacing = self ._fl_spacing
186199 string = fl .formatter (values = [value ] * fl ._unit , spacing = spacing )
200+
187201 return string [0 ]
188202
189203 def set_separator (self , separator ):
@@ -460,6 +474,10 @@ def _update_ticks(self, renderer):
460474 # Rotate by 90 degrees
461475 dx , dy = - dy , dx
462476
477+ if self ._coord_unit_scale is not None :
478+ dx *= self ._coord_unit_scale
479+ dy *= self ._coord_unit_scale
480+
463481 if self .coord_type == 'longitude' :
464482 # Here we wrap at 180 not self.coord_wrap since we want to
465483 # always ensure abs(dx) < 180 and abs(dy) < 180
@@ -479,6 +497,11 @@ def _update_ticks(self, renderer):
479497 # longitudes.
480498 w1 = spine .world [:- 1 , self .coord_index ]
481499 w2 = spine .world [1 :, self .coord_index ]
500+
501+ if self ._coord_unit_scale is not None :
502+ w1 = w1 * self ._coord_unit_scale
503+ w2 = w2 * self ._coord_unit_scale
504+
482505 if self .coord_type == 'longitude' :
483506 w1 = wrap_angle_at (w1 , self .coord_wrap )
484507 w2 = wrap_angle_at (w2 , self .coord_wrap )
@@ -631,6 +654,11 @@ def _update_grid_lines(self):
631654 # single go rather than doing this in the gridline to path conversion
632655 # to fully benefit from vectorized coordinate transformations.
633656
657+ # Currently xy_world is in deg, but transform function needs it in
658+ # native units
659+ if self ._coord_unit_scale is not None :
660+ xy_world /= self ._coord_unit_scale
661+
634662 # Transform line to pixel coordinates
635663 pixel = self .transform .inverted ().transform (xy_world )
636664
0 commit comments