diff --git a/tests/examples_arguments_syntax/bar_chart_with_highlighted_segment.py b/tests/examples_arguments_syntax/bar_chart_with_highlighted_segment.py index 09292fe55..0322e0ce8 100644 --- a/tests/examples_arguments_syntax/bar_chart_with_highlighted_segment.py +++ b/tests/examples_arguments_syntax/bar_chart_with_highlighted_segment.py @@ -1,7 +1,7 @@ """ Bar Chart with Highlighted Segment ---------------------------------- -This example shows a bar chart that highlights values beyond a threshold. +This example shows a bar chart that highlights values beyond two threshold. """ # category: bar charts import altair as alt @@ -9,23 +9,39 @@ from vega_datasets import data source = data.wheat() -threshold = pd.DataFrame([{"threshold": 90}]) +threshold = pd.DataFrame( + data={"threshold_value": [20, 60], "threshold_label": ["> 20", "> 60"]} + ) -bars = alt.Chart(source).mark_bar().encode( +bars = alt.Chart(source).mark_bar(color="#9CC8E2").encode( x="year:O", - y="wheat:Q", + y=alt.Y("wheat:Q",title="Wheat") ) -highlight = alt.Chart(source).mark_bar(color="#e45755").encode( +highlight = alt.Chart(source).mark_bar(color="#5BA3CF").encode( x='year:O', - y='baseline:Q', - y2='wheat:Q' + y='wheat:Q', + y2=alt.datum(20) ).transform_filter( - alt.datum.wheat > 90 -).transform_calculate("baseline", "90") + alt.datum.wheat > 20 +) + +highlight2 = alt.Chart(source).mark_bar(color="#2978B8").encode( + x='year:O', + y='wheat:Q', + y2=alt.datum(60) +).transform_filter( + alt.datum.wheat > 60 +) rule = alt.Chart(threshold).mark_rule().encode( - y='threshold:Q' + y=alt.Y("threshold_value") +) + +label = rule.mark_text( + x=alt.expr('width'), align="right",dx=20, dy=-5, fontWeight="bold", fontSize=12 +).encode( + text="threshold_label", ) -(bars + highlight + rule).properties(width=600) +(bars + highlight + highlight2 + rule +label).properties(width=600) \ No newline at end of file