diff --git a/lib/matplotlib/axes/_axes.py b/lib/matplotlib/axes/_axes.py index 7681edf57f44..612b6f77a999 100644 --- a/lib/matplotlib/axes/_axes.py +++ b/lib/matplotlib/axes/_axes.py @@ -2190,39 +2190,17 @@ def bar(self, *args, **kwargs): adjust_xlim = True x = 0 - x, height, width, y, linewidth = np.broadcast_arrays( - # Make args iterable too. - np.atleast_1d(x), height, width, y, linewidth) - if orientation == 'vertical': self._process_unit_info(xdata=x, ydata=height, kwargs=kwargs) if log: self.set_yscale('log', nonposy='clip') - - tick_label_axis = self.xaxis - tick_label_position = x elif orientation == 'horizontal': self._process_unit_info(xdata=width, ydata=y, kwargs=kwargs) if log: self.set_xscale('log', nonposx='clip') - - tick_label_axis = self.yaxis - tick_label_position = y else: raise ValueError('invalid orientation: %s' % orientation) - linewidth = itertools.cycle(np.atleast_1d(linewidth)) - color = itertools.chain(itertools.cycle(mcolors.to_rgba_array(color)), - # Fallback if color == "none". - itertools.repeat([0, 0, 0, 0])) - if edgecolor is None: - edgecolor = itertools.repeat(None) - else: - edgecolor = itertools.chain( - itertools.cycle(mcolors.to_rgba_array(edgecolor)), - # Fallback if edgecolor == "none". - itertools.repeat([0, 0, 0, 0])) - # lets do some conversions now since some types cannot be # subtracted uniformly if self.xaxis is not None: @@ -2237,6 +2215,30 @@ def bar(self, *args, **kwargs): if yerr is not None: yerr = self.convert_yunits(yerr) + x, height, width, y, linewidth = np.broadcast_arrays( + # Make args iterable too. + np.atleast_1d(x), height, width, y, linewidth) + + # Now that units have been converted, set the tick locations. + if orientation == 'vertical': + tick_label_axis = self.xaxis + tick_label_position = x + elif orientation == 'horizontal': + tick_label_axis = self.yaxis + tick_label_position = y + + linewidth = itertools.cycle(np.atleast_1d(linewidth)) + color = itertools.chain(itertools.cycle(mcolors.to_rgba_array(color)), + # Fallback if color == "none". + itertools.repeat([0, 0, 0, 0])) + if edgecolor is None: + edgecolor = itertools.repeat(None) + else: + edgecolor = itertools.chain( + itertools.cycle(mcolors.to_rgba_array(edgecolor)), + # Fallback if edgecolor == "none". + itertools.repeat([0, 0, 0, 0])) + # We will now resolve the alignment and really have # left, bottom, width, height vectors if align == 'center': diff --git a/lib/matplotlib/testing/jpl_units/EpochConverter.py b/lib/matplotlib/testing/jpl_units/EpochConverter.py index ccf02e858717..eecf3321135b 100644 --- a/lib/matplotlib/testing/jpl_units/EpochConverter.py +++ b/lib/matplotlib/testing/jpl_units/EpochConverter.py @@ -101,7 +101,7 @@ def duration2float( value ): = RETURN VALUE - Returns the value parameter converted to floats. """ - return value.days() + return value.seconds() / 86400.0 #------------------------------------------------------------------------ @staticmethod diff --git a/lib/matplotlib/testing/jpl_units/__init__.py b/lib/matplotlib/testing/jpl_units/__init__.py index 9b6ab73bdad6..074af4e83589 100644 --- a/lib/matplotlib/testing/jpl_units/__init__.py +++ b/lib/matplotlib/testing/jpl_units/__init__.py @@ -65,6 +65,7 @@ def register(): mplU.registry[ str ] = StrConverter() mplU.registry[ Epoch ] = EpochConverter() + mplU.registry[ Duration ] = EpochConverter() mplU.registry[ UnitDbl ] = UnitDblConverter() #======================================================================= diff --git a/lib/matplotlib/tests/baseline_images/test_units/jpl_bar_units.png b/lib/matplotlib/tests/baseline_images/test_units/jpl_bar_units.png new file mode 100644 index 000000000000..8c79da4c7c4e Binary files /dev/null and b/lib/matplotlib/tests/baseline_images/test_units/jpl_bar_units.png differ diff --git a/lib/matplotlib/tests/baseline_images/test_units/jpl_barh_units.png b/lib/matplotlib/tests/baseline_images/test_units/jpl_barh_units.png new file mode 100644 index 000000000000..d76f147fe667 Binary files /dev/null and b/lib/matplotlib/tests/baseline_images/test_units/jpl_barh_units.png differ diff --git a/lib/matplotlib/tests/test_units.py b/lib/matplotlib/tests/test_units.py index 14e8341e4b5d..65c8da7ea7d4 100644 --- a/lib/matplotlib/tests/test_units.py +++ b/lib/matplotlib/tests/test_units.py @@ -3,6 +3,7 @@ from matplotlib.testing.decorators import image_comparison import matplotlib.units as munits import numpy as np +import datetime try: # mock in python 3.3+ @@ -95,3 +96,37 @@ def test_plot_masked_units(): fig, ax = plt.subplots() ax.plot(data_masked_units) + + +@image_comparison(baseline_images=['jpl_bar_units'], extensions=['png'], + savefig_kwarg={'dpi': 120}, style='mpl20') +def test_jpl_bar_units(): + from datetime import datetime + import matplotlib.testing.jpl_units as units + units.register() + + day = units.Duration("ET", 24.0 * 60.0 * 60.0) + x = [0*units.km, 1*units.km, 2*units.km] + w = [1*day, 2*day, 3*day] + b = units.Epoch("ET", dt=datetime(2009, 4, 25)) + + fig, ax = plt.subplots() + ax.bar(x, w, bottom=b) + ax.set_ylim([b-1*day, b+w[-1]+1*day]) + + +@image_comparison(baseline_images=['jpl_barh_units'], extensions=['png'], + savefig_kwarg={'dpi': 120}, style='mpl20') +def test_jpl_barh_units(): + from datetime import datetime + import matplotlib.testing.jpl_units as units + units.register() + + day = units.Duration("ET", 24.0 * 60.0 * 60.0) + x = [0*units.km, 1*units.km, 2*units.km] + w = [1*day, 2*day, 3*day] + b = units.Epoch("ET", dt=datetime(2009, 4, 25)) + + fig, ax = plt.subplots() + ax.barh(x, w, left=b) + ax.set_xlim([b-1*day, b+w[-1]+1*day])