From 792d1b43eaba40b515572afb06323621ba882b0e Mon Sep 17 00:00:00 2001 From: "Weng, Chia-Ling" Date: Wed, 8 Nov 2023 10:11:17 +0800 Subject: [PATCH 1/2] [Doc] Add scatter plot with shaded area example --- .../scatter_with_shaded_area.py | 48 +++++++++++++++++++ .../scatter_with_shaded_area.py | 48 +++++++++++++++++++ 2 files changed, 96 insertions(+) create mode 100644 tests/examples_arguments_syntax/scatter_with_shaded_area.py create mode 100644 tests/examples_methods_syntax/scatter_with_shaded_area.py diff --git a/tests/examples_arguments_syntax/scatter_with_shaded_area.py b/tests/examples_arguments_syntax/scatter_with_shaded_area.py new file mode 100644 index 000000000..3096e420b --- /dev/null +++ b/tests/examples_arguments_syntax/scatter_with_shaded_area.py @@ -0,0 +1,48 @@ +""" +Scatter Plot with Shaded Area +----------------------------- +This example shows a scatter plot with shaded area, +constructed using :ref:`area mark ` and :ref:`rect mark `. +""" +# category: scatter plots + +import altair as alt +import pandas as pd +import numpy as np + +data = pd.DataFrame({ + "x": np.random.uniform(-4, 5, size=50), + "y": np.random.uniform(2, 5, size=50), +}) + +rect_data = pd.DataFrame({ + "x1": [-2], + "x2": [-1] +}) + +# define this interval between y = -x and y = -x +df = pd.DataFrame({ + "x": range(7), + "ymin": range(7), + "ymax": range(1,8) +}) + +points = alt.Chart(data).mark_point().encode( + x="x", + y="y" +) + +interval = alt.Chart(df).mark_area(opacity=0.3).encode( + x="x:Q", + y="ymin:Q", + y2="ymax:Q" +) + + +rect = alt.Chart(rect_data).mark_rect(opacity=0.3).encode( + x="x1", + x2="x2", + color=alt.ColorValue("#FF0000") +) + +points + interval + rect \ No newline at end of file diff --git a/tests/examples_methods_syntax/scatter_with_shaded_area.py b/tests/examples_methods_syntax/scatter_with_shaded_area.py new file mode 100644 index 000000000..3096e420b --- /dev/null +++ b/tests/examples_methods_syntax/scatter_with_shaded_area.py @@ -0,0 +1,48 @@ +""" +Scatter Plot with Shaded Area +----------------------------- +This example shows a scatter plot with shaded area, +constructed using :ref:`area mark ` and :ref:`rect mark `. +""" +# category: scatter plots + +import altair as alt +import pandas as pd +import numpy as np + +data = pd.DataFrame({ + "x": np.random.uniform(-4, 5, size=50), + "y": np.random.uniform(2, 5, size=50), +}) + +rect_data = pd.DataFrame({ + "x1": [-2], + "x2": [-1] +}) + +# define this interval between y = -x and y = -x +df = pd.DataFrame({ + "x": range(7), + "ymin": range(7), + "ymax": range(1,8) +}) + +points = alt.Chart(data).mark_point().encode( + x="x", + y="y" +) + +interval = alt.Chart(df).mark_area(opacity=0.3).encode( + x="x:Q", + y="ymin:Q", + y2="ymax:Q" +) + + +rect = alt.Chart(rect_data).mark_rect(opacity=0.3).encode( + x="x1", + x2="x2", + color=alt.ColorValue("#FF0000") +) + +points + interval + rect \ No newline at end of file From b0764ba607a45031f5c7667b1e1f3dd8a0a94465 Mon Sep 17 00:00:00 2001 From: Joel Ostblom Date: Sat, 11 Nov 2023 16:46:04 -0800 Subject: [PATCH 2/2] Delete tests/examples_methods_syntax/scatter_with_shaded_area.py --- .../scatter_with_shaded_area.py | 48 ------------------- 1 file changed, 48 deletions(-) delete mode 100644 tests/examples_methods_syntax/scatter_with_shaded_area.py diff --git a/tests/examples_methods_syntax/scatter_with_shaded_area.py b/tests/examples_methods_syntax/scatter_with_shaded_area.py deleted file mode 100644 index 3096e420b..000000000 --- a/tests/examples_methods_syntax/scatter_with_shaded_area.py +++ /dev/null @@ -1,48 +0,0 @@ -""" -Scatter Plot with Shaded Area ------------------------------ -This example shows a scatter plot with shaded area, -constructed using :ref:`area mark ` and :ref:`rect mark `. -""" -# category: scatter plots - -import altair as alt -import pandas as pd -import numpy as np - -data = pd.DataFrame({ - "x": np.random.uniform(-4, 5, size=50), - "y": np.random.uniform(2, 5, size=50), -}) - -rect_data = pd.DataFrame({ - "x1": [-2], - "x2": [-1] -}) - -# define this interval between y = -x and y = -x -df = pd.DataFrame({ - "x": range(7), - "ymin": range(7), - "ymax": range(1,8) -}) - -points = alt.Chart(data).mark_point().encode( - x="x", - y="y" -) - -interval = alt.Chart(df).mark_area(opacity=0.3).encode( - x="x:Q", - y="ymin:Q", - y2="ymax:Q" -) - - -rect = alt.Chart(rect_data).mark_rect(opacity=0.3).encode( - x="x1", - x2="x2", - color=alt.ColorValue("#FF0000") -) - -points + interval + rect \ No newline at end of file