Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit a529004

Browse files
authored
Merge pull request #10639 from matplotlib/auto-backport-of-pr-10623
Backport PR #10623 on branch v2.2.x
2 parents 7ccdefd + caefff7 commit a529004

File tree

6 files changed

+61
-23
lines changed

6 files changed

+61
-23
lines changed

lib/matplotlib/axes/_axes.py

Lines changed: 24 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -2189,39 +2189,17 @@ def bar(self, *args, **kwargs):
21892189
adjust_xlim = True
21902190
x = 0
21912191

2192-
x, height, width, y, linewidth = np.broadcast_arrays(
2193-
# Make args iterable too.
2194-
np.atleast_1d(x), height, width, y, linewidth)
2195-
21962192
if orientation == 'vertical':
21972193
self._process_unit_info(xdata=x, ydata=height, kwargs=kwargs)
21982194
if log:
21992195
self.set_yscale('log', nonposy='clip')
2200-
2201-
tick_label_axis = self.xaxis
2202-
tick_label_position = x
22032196
elif orientation == 'horizontal':
22042197
self._process_unit_info(xdata=width, ydata=y, kwargs=kwargs)
22052198
if log:
22062199
self.set_xscale('log', nonposx='clip')
2207-
2208-
tick_label_axis = self.yaxis
2209-
tick_label_position = y
22102200
else:
22112201
raise ValueError('invalid orientation: %s' % orientation)
22122202

2213-
linewidth = itertools.cycle(np.atleast_1d(linewidth))
2214-
color = itertools.chain(itertools.cycle(mcolors.to_rgba_array(color)),
2215-
# Fallback if color == "none".
2216-
itertools.repeat([0, 0, 0, 0]))
2217-
if edgecolor is None:
2218-
edgecolor = itertools.repeat(None)
2219-
else:
2220-
edgecolor = itertools.chain(
2221-
itertools.cycle(mcolors.to_rgba_array(edgecolor)),
2222-
# Fallback if edgecolor == "none".
2223-
itertools.repeat([0, 0, 0, 0]))
2224-
22252203
# lets do some conversions now since some types cannot be
22262204
# subtracted uniformly
22272205
if self.xaxis is not None:
@@ -2236,6 +2214,30 @@ def bar(self, *args, **kwargs):
22362214
if yerr is not None:
22372215
yerr = self.convert_yunits(yerr)
22382216

2217+
x, height, width, y, linewidth = np.broadcast_arrays(
2218+
# Make args iterable too.
2219+
np.atleast_1d(x), height, width, y, linewidth)
2220+
2221+
# Now that units have been converted, set the tick locations.
2222+
if orientation == 'vertical':
2223+
tick_label_axis = self.xaxis
2224+
tick_label_position = x
2225+
elif orientation == 'horizontal':
2226+
tick_label_axis = self.yaxis
2227+
tick_label_position = y
2228+
2229+
linewidth = itertools.cycle(np.atleast_1d(linewidth))
2230+
color = itertools.chain(itertools.cycle(mcolors.to_rgba_array(color)),
2231+
# Fallback if color == "none".
2232+
itertools.repeat([0, 0, 0, 0]))
2233+
if edgecolor is None:
2234+
edgecolor = itertools.repeat(None)
2235+
else:
2236+
edgecolor = itertools.chain(
2237+
itertools.cycle(mcolors.to_rgba_array(edgecolor)),
2238+
# Fallback if edgecolor == "none".
2239+
itertools.repeat([0, 0, 0, 0]))
2240+
22392241
# We will now resolve the alignment and really have
22402242
# left, bottom, width, height vectors
22412243
if align == 'center':

lib/matplotlib/testing/jpl_units/EpochConverter.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ def duration2float( value ):
101101
= RETURN VALUE
102102
- Returns the value parameter converted to floats.
103103
"""
104-
return value.days()
104+
return value.seconds() / 86400.0
105105

106106
#------------------------------------------------------------------------
107107
@staticmethod

lib/matplotlib/testing/jpl_units/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ def register():
6565

6666
mplU.registry[ str ] = StrConverter()
6767
mplU.registry[ Epoch ] = EpochConverter()
68+
mplU.registry[ Duration ] = EpochConverter()
6869
mplU.registry[ UnitDbl ] = UnitDblConverter()
6970

7071
#=======================================================================

lib/matplotlib/tests/test_units.py

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
from matplotlib.testing.decorators import image_comparison
44
import matplotlib.units as munits
55
import numpy as np
6+
import datetime
67

78
try:
89
# mock in python 3.3+
@@ -95,3 +96,37 @@ def test_plot_masked_units():
9596

9697
fig, ax = plt.subplots()
9798
ax.plot(data_masked_units)
99+
100+
101+
@image_comparison(baseline_images=['jpl_bar_units'], extensions=['png'],
102+
savefig_kwarg={'dpi': 120}, style='mpl20')
103+
def test_jpl_bar_units():
104+
from datetime import datetime
105+
import matplotlib.testing.jpl_units as units
106+
units.register()
107+
108+
day = units.Duration("ET", 24.0 * 60.0 * 60.0)
109+
x = [0*units.km, 1*units.km, 2*units.km]
110+
w = [1*day, 2*day, 3*day]
111+
b = units.Epoch("ET", dt=datetime(2009, 4, 25))
112+
113+
fig, ax = plt.subplots()
114+
ax.bar(x, w, bottom=b)
115+
ax.set_ylim([b-1*day, b+w[-1]+1*day])
116+
117+
118+
@image_comparison(baseline_images=['jpl_barh_units'], extensions=['png'],
119+
savefig_kwarg={'dpi': 120}, style='mpl20')
120+
def test_jpl_barh_units():
121+
from datetime import datetime
122+
import matplotlib.testing.jpl_units as units
123+
units.register()
124+
125+
day = units.Duration("ET", 24.0 * 60.0 * 60.0)
126+
x = [0*units.km, 1*units.km, 2*units.km]
127+
w = [1*day, 2*day, 3*day]
128+
b = units.Epoch("ET", dt=datetime(2009, 4, 25))
129+
130+
fig, ax = plt.subplots()
131+
ax.barh(x, w, left=b)
132+
ax.set_xlim([b-1*day, b+w[-1]+1*day])

0 commit comments

Comments
 (0)