Scientific Computing, TU Berlin, WS 2019/2020, Lecture 06
Jürgen Fuhrmann, WIAS Berlin
Human perception is much better adapted to visual representation than to numbers
Purposes of plotting:
glClear()
glBegin(GL_TRIANGLES)
glVertex3d(1,2,3)
glVertex3d(1,5,4)
glVertex3d(3,9,15)
glEnd()
glSwapBuffers()
GPUs are ubiquitous, why aren't they used for visualization ?
Plots.gr()
¶Plots
so you see which methods come from there import Plots
injupyter=isdefined(Main, :IJulia) && Main.IJulia.inited
function example1(;n=100)
f(x)=sin(exp(4.0*x))
X=collect(-1.0:1.0/n:1.0)
p=Plots.plot(X,f.(X))
end
Run example
injupyter&& example1()
function example2(;n=100)
f(x)=sin(exp(4x))
X=collect(-1.0:1.0/n:1.0)
p=Plots.plot(framestyle=:full,legend=:topleft, title="Example2")
Plots.plot!(p, xlabel="x",ylabel="y")
Plots.plot!(p, X,f.(X), label="y=sin(exp(4x))")
Plots.savefig(p,"example2.pdf")
return p
end
Run this example
injupyter&& example2()
function example3(;n=100)
f(x)=sin(exp(4x))
g(x)=sin(exp(-4x))
X=collect(-1.0:1.0/n:1.0)
p=Plots.plot(framestyle=:full,legend=:topleft, title="Example3")
Plots.plot!(p, xlabel="x",ylabel="y")
Plots.plot!(p, X,f.(X), label="y=sin(exp(4x))", color=Plots.RGB(1,0,0))
Plots.plot!(p, X,g.(X), label="y=sin(exp(-4x))", color=Plots.RGB(0,0,1))
end
Run this example
injupyter&& example3()
function example4(;n=100)
f(x)=sin(exp(4x))
g(x)=sin(exp(-4x))
X=collect(-1.0:1.0/n:1.0)
p1=Plots.plot(framestyle=:full,legend=:topleft, title="Example4")
Plots.plot!(p1, xlabel="x",ylabel="y")
Plots.plot!(p1, X,f.(X), label="y=sin(exp(4x))", color=Plots.RGB(1,0,0))
p2=Plots.plot(framestyle=:full,legend=:topright)
Plots.plot!(p2, xlabel="x",ylabel="y")
Plots.plot!(p2, X,g.(X), label="y=sin(exp(-4x))", color=Plots.RGB(0,0,1))
p=Plots.plot(p1,p2,layout=(2,1))
end
Run this example
injupyter&& example4()
function example5(;n=100)
f(x)=sin(exp(4x))
g(x)=sin(exp(-4x))
X=collect(-1.0:1.0/n:1.0)
p1=Plots.plot(framestyle=:full,legend=:topleft, title="Example5")
Plots.plot!(p1, xlabel="x",ylabel="y")
Plots.plot!(p1, X,f.(X), label="y=sin(exp(4x))", color=Plots.RGB(1,0,0))
p2=Plots.plot(framestyle=:full,legend=:topright)
Plots.plot!(p2, xlabel="x",ylabel="y")
Plots.plot!(p2, X,g.(X), label="y=sin(exp(-4x))", seriestype=:scatter, color=Plots.RGB(0,0,1), markersize=0.5)
p=Plots.plot(p1,p2,layout=(2,1))
end
Run this example
injupyter&& example5()
Plots.plot()
,Plots.plot!()
Plots.plotattr()
$~$
Plots.plotattr(:Series)
$~$
Plots.plotattr("seriestype")
function example6(;n=100)
f(x,y)=sin(10x)*cos(10y)*exp(x*y)
X=collect(-1.0:1.0/n:1.0)
Y=view(X,:)
Z=[f(X[i],Y[j]) for i=1:length(X),j=1:length(Y)]
p=Plots.plot(X,Y,Z, seriestype=:heatmap,seriescolor=Plots.cgrad([:red,:yellow,:blue]))
p=Plots.plot!(p,X,Y,Z, seriestype=:contour, seriescolor=:black)
end
Run this example
injupyter&& example6()
# import PyPlot
$~$
function example7(;n=100,tend=10)
f(x,y,t)=sin((10+sin(t))*x-t)*cos(10y-t)
X=collect(-1.0:1.0/n:1.0)
Y=view(X,:)
Z=[f(X[i],Y[j],0) for i=1:length(X),j=1:length(Y)]
for t=1:0.1:tend
injupyter && IJulia.clear_output(true)
for i=1:length(X),j=1:length(Y)
Z[i,j]=f(X[i],Y[j],t)
end
p=Plots.plot(title="t=$(t)")
p=Plots.plot!(p,X,Y,Z, seriestype=:heatmap,seriescolor=Plots.cgrad([:red,:yellow,:blue]))
p=Plots.plot!(p,X,Y,Z, seriestype=:contour, seriescolor=:black)
Plots.display(p)
if Plots.backend_name()==:pyplot
PyPlot.pause(1.0e-10)
end
end
end
Run this example
injupyter&& example7()
This notebook was generated using Literate.jl.