diff --git a/exercises/exercise_12_0_0_plotly.py b/exercises/exercise_12_0_0_plotly.py new file mode 100644 index 0000000..bbc8fb3 --- /dev/null +++ b/exercises/exercise_12_0_0_plotly.py @@ -0,0 +1,8 @@ +import plotly.graph_objs as go + +x = [0, 1] +y = [1, 0] + +fig = go.Figure(data=go.Scatter(x=x, y=y, mode='lines')) + +fig.show() diff --git a/exercises/exercise_12_0_1_plotly.py b/exercises/exercise_12_0_1_plotly.py new file mode 100644 index 0000000..a4f68d7 --- /dev/null +++ b/exercises/exercise_12_0_1_plotly.py @@ -0,0 +1,10 @@ +import plotly.graph_objs as go + +x = [0, 1] +y = [1, 0] + +fig = go.Figure(data=go.Scatter(x=x, y=y, mode='lines', line=dict(color='rgba(0, 128, 0, 0.4)', width=10), name="straight line")) + +fig.update_layout(title="My first plot", showlegend=True, xaxis=dict(showgrid=True), yaxis=dict(showgrid=True)) + +fig.show() diff --git a/exercises/exercise_12_0_2_plotly.py b/exercises/exercise_12_0_2_plotly.py new file mode 100644 index 0000000..d3390d2 --- /dev/null +++ b/exercises/exercise_12_0_2_plotly.py @@ -0,0 +1,11 @@ +import numpy as np +import plotly.graph_objs as go + +x = np.linspace(-3, 3, 200) +y = 4 * x ** 3 + x ** 2 + +fig = go.Figure(data=go.Scatter(x=x, y=y, mode='lines', line=dict(color='black'), name="f(x)")) + +fig.update_layout(title="f(x)", showlegend=True, xaxis=dict(showgrid=True), yaxis=dict(showgrid=True)) + +fig.show() diff --git a/exercises/exercise_12_0_3_plotly.py b/exercises/exercise_12_0_3_plotly.py new file mode 100644 index 0000000..dd81225 --- /dev/null +++ b/exercises/exercise_12_0_3_plotly.py @@ -0,0 +1,19 @@ +import numpy as np +import plotly.graph_objs as go + +x = np.linspace(-3, 3, 200) +y = np.exp(x**2)**-0.5 + +fig = go.Figure() + +fig.add_trace(go.Scatter(x=x, y=y, mode='lines', line=dict(color='black'), name="f(x)")) + +highlighted_region_1 = np.where((x > -3) & (x < -1), y, None) +highlighted_region_2 = np.where((x > 1) & (x < 3), y, None) + +fig.add_trace(go.Scatter(x=x, y=highlighted_region_1, fill='tozeroy', fillcolor='rgba(0, 128, 0, 0.3)', line=dict(color='rgba(0, 0, 0, 0)'), showlegend=False)) +fig.add_trace(go.Scatter(x=x, y=highlighted_region_2, fill='tozeroy', fillcolor='rgba(0, 128, 0, 0.3)', line=dict(color='rgba(0, 0, 0, 0)'), showlegend=False)) + +fig.update_layout(title="f(x)", showlegend=True, xaxis=dict(showgrid=True), yaxis=dict(showgrid=True)) + +fig.show()