In [1]:
using React, Interact
Interactive plotting can be useful and fun. Here we have a few examples to get you started creating your own interactive plots. We will extensively use the @manipulate
macro from the introductory notebook.
In [2]:
using Gadfly
In [3]:
@manipulate for ϕ = 0:π/16:4π, f = [:sin => sin, :cos => cos], both = false
if both
plot([θ -> sin(θ + ϕ), θ -> cos(θ + ϕ)], 0, 8)
else
plot(θ -> f(θ + ϕ), 0, 8)
end
end
Out[3]:
In [7]:
@manipulate for n=1:25, g = [Geom.line, Geom.point]
Gadfly.plot(y=rand(n), x=rand(n), g)
end
Out[7]:
In [5]:
using PyPlot
Since PyPlot API has functions with side effects, you want to create a figure first and use it in each iteration of @manipulate
with withfig
. Notice f = figure()
and withfig(f)
in the example below. The rest of it is straightforward.
In [6]:
f = figure()
x = linspace(0,2π,1000)
@manipulate for α=1:0.1:3, β=1:0.1:3, γ=1:0.1:3, leg="a funny plot"; withfig(f) do
PyPlot.plot(x, cos(α*x + sin(β*x + γ)))
legend([leg])
end
end;
As an added bonus, you can even fire up a Python GUI with pyplot(true)
and be able to use the widgets above to update the plot.