@@ -2060,40 +2060,33 @@ def update_datalim_bounds(self, bounds):
20602060 def _process_unit_info (self , xdata = None , ydata = None , kwargs = None ):
20612061 """Look for unit *kwargs* and update the axis instances as necessary"""
20622062
2063- if self .xaxis is None or self .yaxis is None :
2064- return
2065-
2066- if xdata is not None :
2067- # we only need to update if there is nothing set yet.
2068- if not self .xaxis .have_units ():
2069- self .xaxis .update_units (xdata )
2070-
2071- if ydata is not None :
2072- # we only need to update if there is nothing set yet.
2073- if not self .yaxis .have_units ():
2074- self .yaxis .update_units (ydata )
2075-
2076- # process kwargs 2nd since these will override default units
2077- if kwargs is not None :
2078- xunits = kwargs .pop ('xunits' , self .xaxis .units )
2079- if self .name == 'polar' :
2080- xunits = kwargs .pop ('thetaunits' , xunits )
2081- if xunits != self .xaxis .units :
2082- self .xaxis .set_units (xunits )
2083- # If the units being set imply a different converter,
2084- # we need to update.
2085- if xdata is not None :
2086- self .xaxis .update_units (xdata )
2087-
2088- yunits = kwargs .pop ('yunits' , self .yaxis .units )
2089- if self .name == 'polar' :
2090- yunits = kwargs .pop ('runits' , yunits )
2091- if yunits != self .yaxis .units :
2092- self .yaxis .set_units (yunits )
2093- # If the units being set imply a different converter,
2094- # we need to update.
2095- if ydata is not None :
2096- self .yaxis .update_units (ydata )
2063+ def _process_single_axis (data , axis , unit_name , kwargs ):
2064+ # Return if there's no axis set
2065+ if axis is None :
2066+ return kwargs
2067+
2068+ if data is not None :
2069+ # We only need to update if there is nothing set yet.
2070+ if not axis .have_units ():
2071+ axis .update_units (data )
2072+
2073+ # Check for units in the kwargs, and if present update axis
2074+ if kwargs is not None :
2075+ units = kwargs .pop (unit_name , axis .units )
2076+ if self .name == 'polar' :
2077+ polar_units = {'xunits' : 'thetaunits' , 'yunits' : 'runits' }
2078+ units = kwargs .pop (polar_units [unit_name ], units )
2079+
2080+ if units != axis .units :
2081+ axis .set_units (units )
2082+ # If the units being set imply a different converter,
2083+ # we need to update.
2084+ if data is not None :
2085+ axis .update_units (data )
2086+ return kwargs
2087+
2088+ kwargs = _process_single_axis (xdata , self .xaxis , 'xunits' , kwargs )
2089+ kwargs = _process_single_axis (ydata , self .yaxis , 'yunits' , kwargs )
20972090 return kwargs
20982091
20992092 def in_axes (self , mouseevent ):
0 commit comments