-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathinteractive_figure_generator.py
32 lines (28 loc) · 1.21 KB
/
interactive_figure_generator.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
from ifigures import InteractiveFigure, RangeWidget, RangeWidgetViridis, RadioWidget,DropDownWidget
import numpy as np
import matplotlib.pyplot as plt
def plot(amplitude, omega, time, color, f):
fig, ax = plt.subplots(figsize=(8, 4))
x = np.linspace(0, 10, 1000)
if f=="sin":
func = np.sin
else:
func = np.cos
ax.plot(x, amplitude * func(omega*x), color=color,
lw=5, alpha=0.4)
ax.set_xlim(0, 10)
ax.set_ylim(-1.1, 1.1)
ax.set_xlabel(r"Time, $t$")
ax.set_ylabel(r"$f(t)$")
ax.set_title("Figure title. f(x) = amplitude * %s(omega*x)"
% (f))
ax.axvspan(time-0.1, time+0.1, color="0.9")
caption = "Figure caption. Amplitude = %.2f, omega = %.2f, color = %s, f(t) = amplitude * %s(omega*x). Highlighted time = %.2f" % (amplitude, omega, color, f, time)
return (fig, caption)
figure_example1 = InteractiveFigure(plot,
amplitude=RangeWidget(0.1, 0.9, 0.4),
omega=RangeWidget(1.0, 5.01, 2.0),
time=RangeWidgetViridis(1,9,4),
color=RadioWidget(['blue', 'green', 'red']),
f=DropDownWidget(["sin","cos"]))
figure_example1.saveStandaloneHTML("interactive_figure.html")