diff --git a/lib/matplotlib/units.py b/lib/matplotlib/units.py index c700e2576277..dd307a59aeae 100644 --- a/lib/matplotlib/units.py +++ b/lib/matplotlib/units.py @@ -44,7 +44,7 @@ def default_units(x, axis): from __future__ import (absolute_import, division, print_function, unicode_literals) -from matplotlib.cbook import iterable, is_numlike +from matplotlib.cbook import iterable, is_numlike, safe_first_element import numpy as np @@ -155,14 +155,11 @@ def get_converter(self, x): converter = self.get_converter(next_item) return converter - if converter is None and iterable(x): - for thisx in x: - # Make sure that recursing might actually lead to a solution, - # if we are just going to re-examine another item of the same - # kind, then do not look at it. - if classx and classx != getattr(thisx, '__class__', None): - converter = self.get_converter(thisx) - return converter + if converter is None and iterable(x) and (len(x) > 0): + thisx = safe_first_element(x) + if classx and classx != getattr(thisx, '__class__', None): + converter = self.get_converter(thisx) + return converter # DISABLED self._cached[idx] = converter return converter