From 425e93a78b2ca370326490e570546b80a6cda5a2 Mon Sep 17 00:00:00 2001 From: "Weng, Chia-Ling" Date: Tue, 24 Oct 2023 10:02:36 +0800 Subject: [PATCH 1/9] [Doc] Add Arrow Vector Example --- .../examples_arguments_syntax/arrow_vector.py | 42 +++++++++++++++++ tests/examples_methods_syntax/arrow_vector.py | 46 +++++++++++++++++++ 2 files changed, 88 insertions(+) create mode 100644 tests/examples_arguments_syntax/arrow_vector.py create mode 100644 tests/examples_methods_syntax/arrow_vector.py diff --git a/tests/examples_arguments_syntax/arrow_vector.py b/tests/examples_arguments_syntax/arrow_vector.py new file mode 100644 index 000000000..cf6adbdcc --- /dev/null +++ b/tests/examples_arguments_syntax/arrow_vector.py @@ -0,0 +1,42 @@ +""" +Arrow Vector +------------------------------ +This example shows a basic vector plot use point mark ``triangle`` as shape, +other shape options can be found in :ref:`Point Mark`. +""" +# category: case studies +import altair as alt +import numpy as np +import pandas as pd + +vector1 = [0, 0, 3, -1] +vector2 = [0, 0, 2, 3] + +v = pd.DataFrame([vector1, vector2], columns=['x1','y1','x2','y2']) + +# calculate the vector +v['x_'] = v['x2'] - v["x1"] +v['y_'] = v['y2'] - v["y1"] + +# calculate the angle between current vector and the default point mark direction (0,1) +# dot product = (x_,y_) dot (0,1) = y_ +v["norm"] = np.sqrt(v['x_']**2 + v['y_']**2) +v["theta"] = np.degrees(np.arccos(v['y_']/v["norm"] )) + + +lines = alt.Chart(v).mark_line().encode( + x=alt.X("x1", scale=alt.Scale(domain=(-4, 4)), title='x'), + y=alt.Y("y1", scale=alt.Scale(domain=(-4, 4)), title='y'), + x2="x2", + y2="y2" +) + +wedge = alt.Chart(v).mark_point(shape="triangle", filled=True).encode( + x="x2", + y="y2", + angle=alt.Angle("theta", scale=alt.Scale(domain=[0, 360])), + size=alt.value(300), + color=alt.value('#000000') +) + +lines + wedge \ No newline at end of file diff --git a/tests/examples_methods_syntax/arrow_vector.py b/tests/examples_methods_syntax/arrow_vector.py new file mode 100644 index 000000000..bd729419b --- /dev/null +++ b/tests/examples_methods_syntax/arrow_vector.py @@ -0,0 +1,46 @@ +""" +Arrow Vector +------------------------------ +This example shows a basic vector plot use point mark ``triangle`` as shape, +other shape options can be found in :ref:`Point Mark` +""" +# category: case studies +import altair as alt +import numpy as np +import pandas as pd + +vector1 = [0, 0, 3, -1] +vector2 = [0, 0, 2, 3] + +v = pd.DataFrame([vector1, vector2], columns=['x1','y1','x2','y2']) + +# calculate the vector +v['x_'] = v['x2'] - v["x1"] +v['y_'] = v['y2'] - v["y1"] + +# calculate the angle between current vector and the default point mark direction (0,1) +# dot product = (x_,y_) dot (0,1) = y_ +v["norm"] = np.sqrt(v['x_']**2 + v['y_']**2) +v["theta"] = np.degrees(np.arccos(v['y_']/v["norm"])) + +lines = alt.Chart(v).mark_line().encode( + alt.X("x1") + .title('x') + .scale(domain=(-4, 4)), + alt.Y("y1") + .title('y') + .scale(domain=(-4, 4)), + alt.X2("x2"), + alt.Y2("y2") +) + +wedge = alt.Chart(v).mark_point(shape="triangle", filled=True).encode( + alt.X("x2"), + alt.Y("y2"), + alt.Angle("theta") + .scale(domain=[0, 360]), + alt.SizeValue(300), + alt.ColorValue('#000000') +) + +lines + wedge \ No newline at end of file From b7315ea21167d56db67e101413028b179fe99dc6 Mon Sep 17 00:00:00 2001 From: "Weng, Chia-Ling" Date: Tue, 24 Oct 2023 10:45:41 +0800 Subject: [PATCH 2/9] [Doc] Add Arrow Vector Example --- tests/examples_methods_syntax/arrow_vector.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/examples_methods_syntax/arrow_vector.py b/tests/examples_methods_syntax/arrow_vector.py index bd729419b..e35a8efa3 100644 --- a/tests/examples_methods_syntax/arrow_vector.py +++ b/tests/examples_methods_syntax/arrow_vector.py @@ -2,7 +2,7 @@ Arrow Vector ------------------------------ This example shows a basic vector plot use point mark ``triangle`` as shape, -other shape options can be found in :ref:`Point Mark` +other shape options can be found in :ref:`Point Mark`. """ # category: case studies import altair as alt From 348656ceda6eb3d90febb06fcfbcf27e1f7d784e Mon Sep 17 00:00:00 2001 From: "Weng, Chia-Ling" <75072960+ChiaLingWeng@users.noreply.github.com> Date: Wed, 25 Oct 2023 00:34:11 +0800 Subject: [PATCH 3/9] [Doc] Move arrow vector example to line charts Co-authored-by: Stefan Binder --- tests/examples_arguments_syntax/arrow_vector.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/examples_arguments_syntax/arrow_vector.py b/tests/examples_arguments_syntax/arrow_vector.py index cf6adbdcc..1a35c0de9 100644 --- a/tests/examples_arguments_syntax/arrow_vector.py +++ b/tests/examples_arguments_syntax/arrow_vector.py @@ -4,7 +4,7 @@ This example shows a basic vector plot use point mark ``triangle`` as shape, other shape options can be found in :ref:`Point Mark`. """ -# category: case studies +# category: line charts import altair as alt import numpy as np import pandas as pd From 59b2a10c47b31943b7d0b2877e7f3e19f823cf7a Mon Sep 17 00:00:00 2001 From: "Weng, Chia-Ling" <75072960+ChiaLingWeng@users.noreply.github.com> Date: Wed, 25 Oct 2023 00:34:46 +0800 Subject: [PATCH 4/9] Update language Co-authored-by: Stefan Binder --- tests/examples_arguments_syntax/arrow_vector.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/examples_arguments_syntax/arrow_vector.py b/tests/examples_arguments_syntax/arrow_vector.py index 1a35c0de9..09db64531 100644 --- a/tests/examples_arguments_syntax/arrow_vector.py +++ b/tests/examples_arguments_syntax/arrow_vector.py @@ -1,7 +1,7 @@ """ Arrow Vector ------------------------------ -This example shows a basic vector plot use point mark ``triangle`` as shape, +This example shows a basic vector plot using point mark ``triangle`` as shape, other shape options can be found in :ref:`Point Mark`. """ # category: line charts From 640dcac03709337f90272e4018aa7d0d75e1de35 Mon Sep 17 00:00:00 2001 From: "Weng, Chia-Ling" <75072960+ChiaLingWeng@users.noreply.github.com> Date: Wed, 25 Oct 2023 00:38:37 +0800 Subject: [PATCH 5/9] replace with double quotes --- .../examples_arguments_syntax/arrow_vector.py | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/tests/examples_arguments_syntax/arrow_vector.py b/tests/examples_arguments_syntax/arrow_vector.py index 09db64531..e1eac6fa0 100644 --- a/tests/examples_arguments_syntax/arrow_vector.py +++ b/tests/examples_arguments_syntax/arrow_vector.py @@ -12,21 +12,21 @@ vector1 = [0, 0, 3, -1] vector2 = [0, 0, 2, 3] -v = pd.DataFrame([vector1, vector2], columns=['x1','y1','x2','y2']) +v = pd.DataFrame([vector1, vector2], columns=["x1","y1","x2","y2"]) # calculate the vector -v['x_'] = v['x2'] - v["x1"] -v['y_'] = v['y2'] - v["y1"] +v["x_"] = v["x2"] - v["x1"] +v["y_"] = v["y2"] - v["y1"] # calculate the angle between current vector and the default point mark direction (0,1) # dot product = (x_,y_) dot (0,1) = y_ -v["norm"] = np.sqrt(v['x_']**2 + v['y_']**2) -v["theta"] = np.degrees(np.arccos(v['y_']/v["norm"] )) +v["norm"] = np.sqrt(v["x_"]**2 + v["y_"]**2) +v["theta"] = np.degrees(np.arccos(v["y_"]/v["norm"] )) lines = alt.Chart(v).mark_line().encode( - x=alt.X("x1", scale=alt.Scale(domain=(-4, 4)), title='x'), - y=alt.Y("y1", scale=alt.Scale(domain=(-4, 4)), title='y'), + x=alt.X("x1", scale=alt.Scale(domain=(-4, 4)), title="x"), + y=alt.Y("y1", scale=alt.Scale(domain=(-4, 4)), title="y"), x2="x2", y2="y2" ) @@ -36,7 +36,7 @@ y="y2", angle=alt.Angle("theta", scale=alt.Scale(domain=[0, 360])), size=alt.value(300), - color=alt.value('#000000') + color=alt.value("#000000") ) -lines + wedge \ No newline at end of file +lines + wedge From 261430c8918dfc3bf7d922e39762862ed11195ca Mon Sep 17 00:00:00 2001 From: "Weng, Chia-Ling" <75072960+ChiaLingWeng@users.noreply.github.com> Date: Wed, 25 Oct 2023 00:40:54 +0800 Subject: [PATCH 6/9] Fix language as argument syntax example --- tests/examples_methods_syntax/arrow_vector.py | 22 +++++++++---------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/tests/examples_methods_syntax/arrow_vector.py b/tests/examples_methods_syntax/arrow_vector.py index e35a8efa3..8f3bdc21e 100644 --- a/tests/examples_methods_syntax/arrow_vector.py +++ b/tests/examples_methods_syntax/arrow_vector.py @@ -1,10 +1,10 @@ """ Arrow Vector ------------------------------ -This example shows a basic vector plot use point mark ``triangle`` as shape, +This example shows a basic vector plot using point mark ``triangle`` as shape, other shape options can be found in :ref:`Point Mark`. """ -# category: case studies +# category: line charts import altair as alt import numpy as np import pandas as pd @@ -12,23 +12,23 @@ vector1 = [0, 0, 3, -1] vector2 = [0, 0, 2, 3] -v = pd.DataFrame([vector1, vector2], columns=['x1','y1','x2','y2']) +v = pd.DataFrame([vector1, vector2], columns=["x1","y1","x2","y2"]) # calculate the vector -v['x_'] = v['x2'] - v["x1"] -v['y_'] = v['y2'] - v["y1"] +v["x_"] = v["x2"] - v["x1"] +v["y_"] = v["y2"] - v["y1"] # calculate the angle between current vector and the default point mark direction (0,1) # dot product = (x_,y_) dot (0,1) = y_ -v["norm"] = np.sqrt(v['x_']**2 + v['y_']**2) -v["theta"] = np.degrees(np.arccos(v['y_']/v["norm"])) +v["norm"] = np.sqrt(v["x_"]**2 + v["y_"]**2) +v["theta"] = np.degrees(np.arccos(v["y_"]/v["norm"])) lines = alt.Chart(v).mark_line().encode( alt.X("x1") - .title('x') + .title("x") .scale(domain=(-4, 4)), alt.Y("y1") - .title('y') + .title("y") .scale(domain=(-4, 4)), alt.X2("x2"), alt.Y2("y2") @@ -40,7 +40,7 @@ alt.Angle("theta") .scale(domain=[0, 360]), alt.SizeValue(300), - alt.ColorValue('#000000') + alt.ColorValue("#000000") ) -lines + wedge \ No newline at end of file +lines + wedge From 5dff28252d69b9dfc62b30d57eff78c532d6b5a9 Mon Sep 17 00:00:00 2001 From: "Weng, Chia-Ling" Date: Tue, 7 Nov 2023 14:15:21 +0800 Subject: [PATCH 7/9] showing 2 arrow methods in single chart --- .../examples_arguments_syntax/arrow_vector.py | 42 ------------- .../line_chart_with_arrows.py | 63 +++++++++++++++++++ tests/examples_methods_syntax/arrow_vector.py | 46 -------------- .../line_chart_with_arrows.py | 58 +++++++++++++++++ 4 files changed, 121 insertions(+), 88 deletions(-) delete mode 100644 tests/examples_arguments_syntax/arrow_vector.py create mode 100644 tests/examples_arguments_syntax/line_chart_with_arrows.py delete mode 100644 tests/examples_methods_syntax/arrow_vector.py create mode 100644 tests/examples_methods_syntax/line_chart_with_arrows.py diff --git a/tests/examples_arguments_syntax/arrow_vector.py b/tests/examples_arguments_syntax/arrow_vector.py deleted file mode 100644 index e1eac6fa0..000000000 --- a/tests/examples_arguments_syntax/arrow_vector.py +++ /dev/null @@ -1,42 +0,0 @@ -""" -Arrow Vector ------------------------------- -This example shows a basic vector plot using point mark ``triangle`` as shape, -other shape options can be found in :ref:`Point Mark`. -""" -# category: line charts -import altair as alt -import numpy as np -import pandas as pd - -vector1 = [0, 0, 3, -1] -vector2 = [0, 0, 2, 3] - -v = pd.DataFrame([vector1, vector2], columns=["x1","y1","x2","y2"]) - -# calculate the vector -v["x_"] = v["x2"] - v["x1"] -v["y_"] = v["y2"] - v["y1"] - -# calculate the angle between current vector and the default point mark direction (0,1) -# dot product = (x_,y_) dot (0,1) = y_ -v["norm"] = np.sqrt(v["x_"]**2 + v["y_"]**2) -v["theta"] = np.degrees(np.arccos(v["y_"]/v["norm"] )) - - -lines = alt.Chart(v).mark_line().encode( - x=alt.X("x1", scale=alt.Scale(domain=(-4, 4)), title="x"), - y=alt.Y("y1", scale=alt.Scale(domain=(-4, 4)), title="y"), - x2="x2", - y2="y2" -) - -wedge = alt.Chart(v).mark_point(shape="triangle", filled=True).encode( - x="x2", - y="y2", - angle=alt.Angle("theta", scale=alt.Scale(domain=[0, 360])), - size=alt.value(300), - color=alt.value("#000000") -) - -lines + wedge diff --git a/tests/examples_arguments_syntax/line_chart_with_arrows.py b/tests/examples_arguments_syntax/line_chart_with_arrows.py new file mode 100644 index 000000000..43e27b278 --- /dev/null +++ b/tests/examples_arguments_syntax/line_chart_with_arrows.py @@ -0,0 +1,63 @@ +""" +Line Chart with Arrows +---------------------- +This example shows a simple line chart with arrow annotations. +It utilizes a Unicode character for quick arrow insertion, +and employs the triangle :ref:`point mark ` for customizable arrowheads. +The Unicode method offers ease of use, while the triangle point mark provides greater flexibility. +""" +# category: line charts +import numpy as np +import pandas as pd +import altair as alt + +x = np.linspace(1,7) +y = np.sin(x) + +data = pd.DataFrame({ + "x": x, + "y": y, + }) + +alt.layer( + alt.Chart(data).mark_line(point=True,tooltip=True).encode( + x=alt.X("x").title("x"), + y=alt.Y("y").title("y"), + ), + alt.Chart().mark_text(size=14, align="center", baseline="bottom").encode( + x=alt.datum(1.8), + y=alt.datum(-0.1), + text=alt.datum("decreasing") + ), + alt.Chart().mark_text(size=14, align="center", baseline="bottom").encode( + x=alt.datum(4.7), + y=alt.datum(-0.3), + text=alt.datum("increasing") + ), + # unicode arrow + alt.Chart().mark_text(size=60, align="left", baseline="bottom", fontWeight=100, angle=340).encode( + x=alt.datum(2.8), + y=alt.datum(-0.3), + text=alt.datum("🠃") + ), + # arrow line + alt.Chart().mark_line(size=2).encode( + x=alt.datum(5.4), + y=alt.datum(-0.4), + x2=alt.datum(6), + y2=alt.datum(0) + ), + # arrow head + alt.Chart().mark_point(shape="triangle", filled=True, fillOpacity=1).encode( + x=alt.datum(6), + y=alt.datum(0), + angle=alt.AngleValue(23), + size=alt.SizeValue(100), + color=alt.ColorValue("#000000") + ) +) + + + + + diff --git a/tests/examples_methods_syntax/arrow_vector.py b/tests/examples_methods_syntax/arrow_vector.py deleted file mode 100644 index 8f3bdc21e..000000000 --- a/tests/examples_methods_syntax/arrow_vector.py +++ /dev/null @@ -1,46 +0,0 @@ -""" -Arrow Vector ------------------------------- -This example shows a basic vector plot using point mark ``triangle`` as shape, -other shape options can be found in :ref:`Point Mark`. -""" -# category: line charts -import altair as alt -import numpy as np -import pandas as pd - -vector1 = [0, 0, 3, -1] -vector2 = [0, 0, 2, 3] - -v = pd.DataFrame([vector1, vector2], columns=["x1","y1","x2","y2"]) - -# calculate the vector -v["x_"] = v["x2"] - v["x1"] -v["y_"] = v["y2"] - v["y1"] - -# calculate the angle between current vector and the default point mark direction (0,1) -# dot product = (x_,y_) dot (0,1) = y_ -v["norm"] = np.sqrt(v["x_"]**2 + v["y_"]**2) -v["theta"] = np.degrees(np.arccos(v["y_"]/v["norm"])) - -lines = alt.Chart(v).mark_line().encode( - alt.X("x1") - .title("x") - .scale(domain=(-4, 4)), - alt.Y("y1") - .title("y") - .scale(domain=(-4, 4)), - alt.X2("x2"), - alt.Y2("y2") -) - -wedge = alt.Chart(v).mark_point(shape="triangle", filled=True).encode( - alt.X("x2"), - alt.Y("y2"), - alt.Angle("theta") - .scale(domain=[0, 360]), - alt.SizeValue(300), - alt.ColorValue("#000000") -) - -lines + wedge diff --git a/tests/examples_methods_syntax/line_chart_with_arrows.py b/tests/examples_methods_syntax/line_chart_with_arrows.py new file mode 100644 index 000000000..2e2a4c861 --- /dev/null +++ b/tests/examples_methods_syntax/line_chart_with_arrows.py @@ -0,0 +1,58 @@ +""" +Line Chart with Arrows +---------------------- +This example shows a simple line chart with arrow annotations. +It utilizes a Unicode character for quick arrow insertion, +and employs the triangle :ref:`point mark ` for customizable arrowheads. +The Unicode method offers ease of use, while the triangle point mark provides greater flexibility. +""" +# category: line charts +import numpy as np +import pandas as pd +import altair as alt + +x = np.linspace(1,7) +y = np.sin(x) + +data = pd.DataFrame({ + "x": x, + "y": y, + }) + +alt.layer( + alt.Chart(data).mark_line(point=True,tooltip=True).encode( + x=alt.X("x").title("x"), + y=alt.Y("y").title("y"), + ), + alt.Chart().mark_text(size=14, align="center", baseline="bottom").encode( + x=alt.datum(1.8), + y=alt.datum(-0.1), + text=alt.datum("decreasing") + ), + alt.Chart().mark_text(size=14, align="center", baseline="bottom").encode( + x=alt.datum(4.7), + y=alt.datum(-0.3), + text=alt.datum("increasing") + ), + # unicode arrow + alt.Chart().mark_text(size=60, align="left", baseline="bottom", fontWeight=100, angle=340).encode( + x=alt.datum(2.8), + y=alt.datum(-0.3), + text=alt.datum("🠃") + ), + # arrow line + alt.Chart().mark_line(size=2).encode( + x=alt.datum(5.4), + y=alt.datum(-0.4), + x2=alt.datum(6), + y2=alt.datum(0) + ), + # arrow head + alt.Chart().mark_point(shape="triangle", filled=True, fillOpacity=1).encode( + x=alt.datum(6), + y=alt.datum(0), + angle=alt.AngleValue(23), + size=alt.SizeValue(100), + color=alt.ColorValue("#000000") + ) +) \ No newline at end of file From d3fd5322e3643651077fdaf91c35ef8f3a1df52b Mon Sep 17 00:00:00 2001 From: Joel Ostblom Date: Sat, 11 Nov 2023 16:31:36 -0800 Subject: [PATCH 8/9] Delete tests/examples_methods_syntax/line_chart_with_arrows.py --- .../line_chart_with_arrows.py | 58 ------------------- 1 file changed, 58 deletions(-) delete mode 100644 tests/examples_methods_syntax/line_chart_with_arrows.py diff --git a/tests/examples_methods_syntax/line_chart_with_arrows.py b/tests/examples_methods_syntax/line_chart_with_arrows.py deleted file mode 100644 index 2e2a4c861..000000000 --- a/tests/examples_methods_syntax/line_chart_with_arrows.py +++ /dev/null @@ -1,58 +0,0 @@ -""" -Line Chart with Arrows ----------------------- -This example shows a simple line chart with arrow annotations. -It utilizes a Unicode character for quick arrow insertion, -and employs the triangle :ref:`point mark ` for customizable arrowheads. -The Unicode method offers ease of use, while the triangle point mark provides greater flexibility. -""" -# category: line charts -import numpy as np -import pandas as pd -import altair as alt - -x = np.linspace(1,7) -y = np.sin(x) - -data = pd.DataFrame({ - "x": x, - "y": y, - }) - -alt.layer( - alt.Chart(data).mark_line(point=True,tooltip=True).encode( - x=alt.X("x").title("x"), - y=alt.Y("y").title("y"), - ), - alt.Chart().mark_text(size=14, align="center", baseline="bottom").encode( - x=alt.datum(1.8), - y=alt.datum(-0.1), - text=alt.datum("decreasing") - ), - alt.Chart().mark_text(size=14, align="center", baseline="bottom").encode( - x=alt.datum(4.7), - y=alt.datum(-0.3), - text=alt.datum("increasing") - ), - # unicode arrow - alt.Chart().mark_text(size=60, align="left", baseline="bottom", fontWeight=100, angle=340).encode( - x=alt.datum(2.8), - y=alt.datum(-0.3), - text=alt.datum("🠃") - ), - # arrow line - alt.Chart().mark_line(size=2).encode( - x=alt.datum(5.4), - y=alt.datum(-0.4), - x2=alt.datum(6), - y2=alt.datum(0) - ), - # arrow head - alt.Chart().mark_point(shape="triangle", filled=True, fillOpacity=1).encode( - x=alt.datum(6), - y=alt.datum(0), - angle=alt.AngleValue(23), - size=alt.SizeValue(100), - color=alt.ColorValue("#000000") - ) -) \ No newline at end of file From 1172f189dfa09d0662309e322427bbccd2b82102 Mon Sep 17 00:00:00 2001 From: Joel Ostblom Date: Sat, 11 Nov 2023 16:32:35 -0800 Subject: [PATCH 9/9] Simplify code a bit --- .../line_chart_with_arrows.py | 72 ++++++++++--------- 1 file changed, 37 insertions(+), 35 deletions(-) diff --git a/tests/examples_arguments_syntax/line_chart_with_arrows.py b/tests/examples_arguments_syntax/line_chart_with_arrows.py index 43e27b278..8c7599470 100644 --- a/tests/examples_arguments_syntax/line_chart_with_arrows.py +++ b/tests/examples_arguments_syntax/line_chart_with_arrows.py @@ -1,63 +1,65 @@ """ Line Chart with Arrows ---------------------- -This example shows a simple line chart with arrow annotations. -It utilizes a Unicode character for quick arrow insertion, -and employs the triangle :ref:`point mark ` for customizable arrowheads. -The Unicode method offers ease of use, while the triangle point mark provides greater flexibility. +This example shows a simple line chart with two types of arrow annotations. +The Unicode character approach is simpler, +while the line plus triangle :ref:`point mark ` allows for greater flexibility, +such as customizable arrowheads. """ # category: line charts +import altair as alt import numpy as np import pandas as pd -import altair as alt -x = np.linspace(1,7) -y = np.sin(x) +x = np.linspace(1,7) data = pd.DataFrame({ - "x": x, - "y": y, - }) + "x": x, + "y": np.sin(x), +}) -alt.layer( - alt.Chart(data).mark_line(point=True,tooltip=True).encode( - x=alt.X("x").title("x"), - y=alt.Y("y").title("y"), - ), - alt.Chart().mark_text(size=14, align="center", baseline="bottom").encode( - x=alt.datum(1.8), - y=alt.datum(-0.1), - text=alt.datum("decreasing") - ), - alt.Chart().mark_text(size=14, align="center", baseline="bottom").encode( - x=alt.datum(4.7), - y=alt.datum(-0.3), - text=alt.datum("increasing") - ), - # unicode arrow +unicode_arrow_with_text = alt.layer( + # Arrow alt.Chart().mark_text(size=60, align="left", baseline="bottom", fontWeight=100, angle=340).encode( x=alt.datum(2.8), y=alt.datum(-0.3), - text=alt.datum("🠃") + text=alt.datum("🠃") # Any unicode symbol could be used instead ), - # arrow line + # Text + alt.Chart().mark_text(size=14, align="center", baseline="bottom").encode( + x=alt.datum(1.8), + y=alt.datum(-0.1), + text=alt.datum("decreasing") + ) +) + +mark_arrow_with_text = alt.layer( + # Arrow line alt.Chart().mark_line(size=2).encode( x=alt.datum(5.4), y=alt.datum(-0.4), - x2=alt.datum(6), + x2=alt.datum(5.9), y2=alt.datum(0) ), - # arrow head + # Arrow head alt.Chart().mark_point(shape="triangle", filled=True, fillOpacity=1).encode( - x=alt.datum(6), + x=alt.datum(5.9), y=alt.datum(0), angle=alt.AngleValue(23), size=alt.SizeValue(100), color=alt.ColorValue("#000000") - ) + ), + # Text + alt.Chart().mark_text(size=14, align="center", baseline="bottom").encode( + x=alt.datum(4.7), + y=alt.datum(-0.3), + text=alt.datum("increasing") + ), ) +line_with_points = alt.Chart(data).mark_line(point=True).encode( + x=alt.X("x"), + y=alt.Y("y"), +) - - - +line_with_points + unicode_arrow_with_text + mark_arrow_with_text