Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs: add example with overlapping bars in a grouped bar chart #3612

Merged
merged 2 commits into from
Sep 26, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
"""
Grouped Bar Chart with xOffset and overlapping bars
---------------------------------------------------
Like :ref:`gallery_grouped_bar_chart2`, this example shows a grouped bar chart using the ``xOffset`` encoding channel, but in this example the bars are partly overlapping within each group.
"""
# category: bar charts
import altair as alt
import pandas as pd

source = pd.DataFrame(
{
"category": list("AABBCC"),
"group": list("xyxyxy"),
"value": [0.1, 0.6, 0.7, 0.2, 0.6, 0.1],
}
)

base = alt.Chart(source, width=alt.Step(12)).encode(
x="category:N",
y="value:Q",
xOffset=alt.XOffset("group:N", scale=alt.Scale(paddingOuter=0.5)),
)

alt.layer(
base.mark_bar(size=20, stroke="white", fillOpacity=0.9).encode(fill="group:N"),
base.mark_text(dy=-5).encode(text="value:Q"),
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
"""
Grouped Bar Chart with xOffset and overlapping bars
---------------------------------------------------
Like :ref:`gallery_grouped_bar_chart2`, this example shows a grouped bar chart using the ``xOffset`` encoding channel, but in this example the bars are partly overlapping within each group.
"""
# category: bar charts
import altair as alt
import pandas as pd

source = pd.DataFrame(
{
"category": list("AABBCC"),
"group": list("xyxyxy"),
"value": [0.1, 0.6, 0.7, 0.2, 0.6, 0.1],
}
)

base = alt.Chart(source, width=alt.Step(12)).encode(
x="category:N",
y="value:Q",
xOffset=alt.XOffset("group:N").scale(paddingOuter=0.5),
)

alt.layer(
base.mark_bar(size=20, stroke="white", fillOpacity=0.9).encode(fill="group:N"),
base.mark_text(dy=-5).encode(text="value:Q"),
mattijn marked this conversation as resolved.
Show resolved Hide resolved
)