From 42e0bd5ddd172be09448c2b72387f44771d2a926 Mon Sep 17 00:00:00 2001 From: Mattijn van Hoek Date: Sat, 4 Nov 2023 21:52:14 +0100 Subject: [PATCH 1/4] range bar chart --- .../bar_chart_with_range.py | 32 +++++++++++++++++++ .../bar_chart_with_range.py | 32 +++++++++++++++++++ 2 files changed, 64 insertions(+) create mode 100644 tests/examples_arguments_syntax/bar_chart_with_range.py create mode 100644 tests/examples_methods_syntax/bar_chart_with_range.py diff --git a/tests/examples_arguments_syntax/bar_chart_with_range.py b/tests/examples_arguments_syntax/bar_chart_with_range.py new file mode 100644 index 000000000..a721d5dec --- /dev/null +++ b/tests/examples_arguments_syntax/bar_chart_with_range.py @@ -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') +) \ No newline at end of file diff --git a/tests/examples_methods_syntax/bar_chart_with_range.py b/tests/examples_methods_syntax/bar_chart_with_range.py new file mode 100644 index 000000000..c2bc99c45 --- /dev/null +++ b/tests/examples_methods_syntax/bar_chart_with_range.py @@ -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') +) \ No newline at end of file From 98e94bd150f852737f18bccfa9c78aec54ebbc7c Mon Sep 17 00:00:00 2001 From: Mattijn van Hoek Date: Sat, 4 Nov 2023 21:56:18 +0100 Subject: [PATCH 2/4] fix arguments syntax --- tests/examples_arguments_syntax/bar_chart_with_range.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/examples_arguments_syntax/bar_chart_with_range.py b/tests/examples_arguments_syntax/bar_chart_with_range.py index a721d5dec..82daceb37 100644 --- a/tests/examples_arguments_syntax/bar_chart_with_range.py +++ b/tests/examples_arguments_syntax/bar_chart_with_range.py @@ -10,7 +10,7 @@ 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)')), + 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) ) From d84792c875790722295cff5b1db98afb1c9f8626 Mon Sep 17 00:00:00 2001 From: Mattijn van Hoek Date: Mon, 6 Nov 2023 22:18:43 +0100 Subject: [PATCH 3/4] Update tests/examples_methods_syntax/bar_chart_with_range.py Co-authored-by: Stefan Binder --- tests/examples_methods_syntax/bar_chart_with_range.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/examples_methods_syntax/bar_chart_with_range.py b/tests/examples_methods_syntax/bar_chart_with_range.py index c2bc99c45..5f5ce2e94 100644 --- a/tests/examples_methods_syntax/bar_chart_with_range.py +++ b/tests/examples_methods_syntax/bar_chart_with_range.py @@ -10,7 +10,7 @@ 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)'), + 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) ) From bdf7ce2dbeed4de24f90ee9e1b1ff45232a16d9d Mon Sep 17 00:00:00 2001 From: Mattijn van Hoek Date: Mon, 6 Nov 2023 22:18:49 +0100 Subject: [PATCH 4/4] Update tests/examples_arguments_syntax/bar_chart_with_range.py Co-authored-by: Stefan Binder --- tests/examples_arguments_syntax/bar_chart_with_range.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/examples_arguments_syntax/bar_chart_with_range.py b/tests/examples_arguments_syntax/bar_chart_with_range.py index 82daceb37..ef9e1dea2 100644 --- a/tests/examples_arguments_syntax/bar_chart_with_range.py +++ b/tests/examples_arguments_syntax/bar_chart_with_range.py @@ -10,7 +10,7 @@ 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)'), + 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) )