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 range bar chart #3250

Merged
merged 4 commits into from
Nov 6, 2023
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
32 changes: 32 additions & 0 deletions tests/examples_arguments_syntax/bar_chart_with_range.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
"""
Bar Chart with Range
====================
This example shows a range bar chart where each bar displays information of a low and high value.
"""
# category: bar charts
import altair as alt
from vega_datasets import data

source = data.seattle_weather()

bar = alt.Chart(source).mark_bar(cornerRadius=10, height=10).encode(
x=alt.X('min(temp_min):Q', scale=alt.Scale(domain=[-15, 45]), title='Temperature (°C)'),
x2='max(temp_max):Q',
y=alt.Y('month(date):O', title=None)
)

text_min = alt.Chart(source).mark_text(align='right', dx=-5).encode(
x='min(temp_min):Q',
y=alt.Y('month(date):O'),
text='min(temp_min):Q'
)

text_max = alt.Chart(source).mark_text(align='left', dx=5).encode(
x='max(temp_max):Q',
y=alt.Y('month(date):O'),
text='max(temp_max):Q'
)

(bar + text_min + text_max).properties(
title=alt.Title(text='Temperature variation by month', subtitle='Seatle weather, 2012-2015')
)
32 changes: 32 additions & 0 deletions tests/examples_methods_syntax/bar_chart_with_range.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
"""
Bar Chart with Range
====================
This example shows a range bar chart where each bar displays information of a low and high value.
"""
# category: bar charts
import altair as alt
from vega_datasets import data

source = data.seattle_weather()

bar = alt.Chart(source).mark_bar(cornerRadius=10, height=10).encode(
x=alt.X('min(temp_min):Q').scale(domain=[-15, 45]).title('Temperature (°C)'),
x2='max(temp_max):Q',
y=alt.Y('month(date):O').title(None)
)

text_min = alt.Chart(source).mark_text(align='right', dx=-5).encode(
x='min(temp_min):Q',
y=alt.Y('month(date):O'),
text='min(temp_min):Q'
)

text_max = alt.Chart(source).mark_text(align='left', dx=5).encode(
x='max(temp_max):Q',
y=alt.Y('month(date):O'),
text='max(temp_max):Q'
)

(bar + text_min + text_max).properties(
title=alt.Title(text='Temperature variation by month', subtitle='Seatle weather, 2012-2015')
)