Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions ultraplot/axes/plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -6236,8 +6236,10 @@ def _apply_bar(
self._inbounds_xylim(extents, x, y, orientation=orientation)

if alphas[i] is not None:
for child in obj.get_children():
child.set_alpha(alphas[i])
# With negpos, each sign has its own BarContainer.
for container in obj if negpos else (obj,):
for child in container.get_children():
child.set_alpha(alphas[i])
objs.append((*eb, obj) if eb else obj)

self._update_guide(objs, **guide_kw)
Expand Down
31 changes: 31 additions & 0 deletions ultraplot/tests/test_1dplots.py
Original file line number Diff line number Diff line change
Expand Up @@ -1012,6 +1012,37 @@ def test_bar_alpha(rng):
uplt.close(fig)


@pytest.mark.parametrize("method", ["bar", "barh"])
@pytest.mark.parametrize("alpha", [0, 0.5, 1])
def test_bar_negpos_alpha(method, alpha):
"""Apply scalar alpha to both sign containers (issue #865)."""
fig, ax = uplt.subplots()
bars = getattr(ax, method)([1, 2, 3], [1, -1, 2], negpos=True, alpha=alpha)
assert len(bars) == 2
for container in bars:
assert len(container.patches) == 3
assert all(patch.get_alpha() == alpha for patch in container.patches)
fig.canvas.draw()
uplt.close(fig)


@pytest.mark.parametrize("method", ["bar", "barh"])
def test_bar_negpos_column_alpha(method):
"""Apply each column's alpha to both of its sign containers."""
fig, ax = uplt.subplots()
values = np.array([[1, -2], [-1, 3], [2, -1]])
alphas = [0.2, 0.8]
bars = getattr(ax, method)([1, 2, 3], values, negpos=True, alpha=alphas)
assert len(bars) == len(alphas)
for group, alpha in zip(bars, alphas):
assert len(group) == 2
for container in group:
assert len(container.patches) == 3
assert all(patch.get_alpha() == alpha for patch in container.patches)
fig.canvas.draw()
uplt.close(fig)


@pytest.mark.mpl_image_compare
def test_lollipop_graph(rng):
"""
Expand Down
Loading