Skip to content

Commit

Permalink
range bar chart
Browse files Browse the repository at this point in the history
  • Loading branch information
mattijn committed Nov 4, 2023
1 parent e5fb1f0 commit 42e0bd5
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 0 deletions.
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')
)

0 comments on commit 42e0bd5

Please sign in to comment.