Skip to content

Commit f1f2a5a

Browse files
committed
Fix more issues with grouped bar plots
1 parent 5fb245b commit f1f2a5a

File tree

1 file changed

+21
-21
lines changed

1 file changed

+21
-21
lines changed

proplot/axes/plot.py

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1310,8 +1310,11 @@ def bar_wrapper(
13101310
"""
13111311
%(axes.bar)s
13121312
"""
1313+
# Parse arguments
1314+
# WARNING: Implementation is really weird... we flip around arguments for horizontal
1315+
# plots only to flip them back in cycle_changer when iterating through columns.
13131316
if vert is not None:
1314-
orientation = ('vertical' if vert else 'horizontal')
1317+
orientation = 'vertical' if vert else 'horizontal'
13151318
if orientation == 'horizontal':
13161319
x, bottom = bottom, x
13171320
width, height = height, width
@@ -1771,12 +1774,9 @@ def cycle_changer(
17711774
stacked = kwargs.pop('stacked', False)
17721775
if name in ('bar',):
17731776
barh = kwargs.get('orientation', None) == 'horizontal'
1774-
if barh:
1775-
kwargs.setdefault('x', 0)
1776-
kwargs.setdefault('height', 0.8)
1777-
else:
1778-
kwargs.setdefault('y', 0)
1779-
kwargs.setdefault('width', 0.8)
1777+
width = kwargs.pop('width', 0.8) # 'width' for bar *and* barh (see bar_wrapper)
1778+
bottom = 'x' if barh else 'bottom'
1779+
kwargs.setdefault(bottom, 0) # 'x' required even though 'y' isn't for bar plots
17801780
cycle_kw = cycle_kw or {}
17811781
legend_kw = legend_kw or {}
17821782
colorbar_kw = colorbar_kw or {}
@@ -1859,21 +1859,21 @@ def cycle_changer(
18591859
# Get step size for bar plots
18601860
# WARNING: This will fail for non-numeric non-datetime64 singleton
18611861
# datatypes but this is good enough for vast majority of most cases.
1862-
if name in ('bar',) and not stacked:
1863-
x_test = np.atleast_1d(_to_ndarray(x))
1864-
if len(x_test) >= 2:
1865-
x_step = x_test[1:] - x_test[:-1]
1866-
x_step = np.concatenate((x_step, x_step[-1:]))
1867-
elif x_test.dtype == np.datetime64:
1868-
x_step = np.timedelta64(1, 'D')
1869-
else:
1870-
x_step = np.array(0.5)
1871-
if np.issubdtype(x_test.dtype, np.datetime64):
1872-
# Avoid integer timedelta truncation
1873-
x_step = x_step.astype('timedelta64[ns]')
1862+
if name in ('bar',):
1863+
if not stacked:
1864+
x_test = np.atleast_1d(_to_ndarray(x))
1865+
if len(x_test) >= 2:
1866+
x_step = x_test[1:] - x_test[:-1]
1867+
x_step = np.concatenate((x_step, x_step[-1:]))
1868+
elif x_test.dtype == np.datetime64:
1869+
x_step = np.timedelta64(1, 'D')
1870+
else:
1871+
x_step = np.array(0.5)
1872+
if np.issubdtype(x_test.dtype, np.datetime64):
1873+
# Avoid integer timedelta truncation
1874+
x_step = x_step.astype('timedelta64[ns]')
1875+
width = width * x_step / ncols
18741876
key = 'height' if barh else 'width'
1875-
width = kwargs.pop(key, 0.8)
1876-
width = width * x_step / ncols
18771877
kwargs[key] = width
18781878

18791879
# Plot susccessive columns

0 commit comments

Comments
 (0)