@@ -2117,40 +2117,32 @@ def update_datalim_bounds(self, bounds):
21172117 def _process_unit_info (self , xdata = None , ydata = None , kwargs = None ):
21182118 """Look for unit *kwargs* and update the axis instances as necessary"""
21192119
2120- if self .xaxis is None or self .yaxis is None :
2121- return
2122-
2123- if xdata is not None :
2124- # we only need to update if there is nothing set yet.
2125- if not self .xaxis .have_units ():
2126- self .xaxis .update_units (xdata )
2127-
2128- if ydata is not None :
2129- # we only need to update if there is nothing set yet.
2130- if not self .yaxis .have_units ():
2131- self .yaxis .update_units (ydata )
2120+ def _process_single_axis (data , axis , unit_name , kwargs ):
2121+ if axis is None :
2122+ return
21322123
2133- # process kwargs 2nd since these will override default units
2134- if kwargs is not None :
2135- xunits = kwargs .pop ('xunits' , self .xaxis .units )
2136- if self .name == 'polar' :
2137- xunits = kwargs .pop ('thetaunits' , xunits )
2138- if xunits != self .xaxis .units :
2139- self .xaxis .set_units (xunits )
2140- # If the units being set imply a different converter,
2141- # we need to update.
2142- if xdata is not None :
2143- self .xaxis .update_units (xdata )
2144-
2145- yunits = kwargs .pop ('yunits' , self .yaxis .units )
2146- if self .name == 'polar' :
2147- yunits = kwargs .pop ('runits' , yunits )
2148- if yunits != self .yaxis .units :
2149- self .yaxis .set_units (yunits )
2150- # If the units being set imply a different converter,
2151- # we need to update.
2152- if ydata is not None :
2153- self .yaxis .update_units (ydata )
2124+ if data is not None :
2125+ # We only need to update if there is nothing set yet.
2126+ if not axis .have_units ():
2127+ axis .update_units (data )
2128+
2129+ # Process kwargs 2nd since these will override default units
2130+ if kwargs is not None :
2131+ units = kwargs .pop (unit_name , axis .units )
2132+ if self .name == 'polar' :
2133+ polar_units = {'xunits' : 'thetaunits' , 'yunits' : 'runits' }
2134+ units = kwargs .pop (polar_units [unit_name ], units )
2135+
2136+ if units != axis .units :
2137+ axis .set_units (units )
2138+ # If the units being set imply a different converter,
2139+ # we need to update.
2140+ if data is not None :
2141+ axis .update_units (data )
2142+ return kwargs
2143+
2144+ kwargs = _process_single_axis (xdata , self .xaxis , 'xunits' , kwargs )
2145+ kwargs = _process_single_axis (ydata , self .yaxis , 'yunits' , kwargs )
21542146 return kwargs
21552147
21562148 def in_axes (self , mouseevent ):
0 commit comments