added examples for plots in 2d and 3d

This commit is contained in:
lazaro 2020-03-20 23:11:21 +01:00
parent 06574ea26f
commit 6e61eca636
23 changed files with 260 additions and 0 deletions

BIN
examples/.DS_Store vendored Normal file

Binary file not shown.

7
examples/2dplots/ex1.jl Normal file
View File

@ -0,0 +1,7 @@
# This file was generated, do not modify it. # hide
using Gnuplot
@gp 1:10
#save("plt2_ex1.gp")
#save(term="cairolatex standalone", output="plt2_ex1.tex")
#save(term="pdf", output="plt2_ex1.pdf")
save(term="png", output="plt2_ex1.png")

6
examples/2dplots/ex10.jl Normal file
View File

@ -0,0 +1,6 @@
# This file was generated, do not modify it. # hide
using Gnuplot, Random
Random.seed!(123)
goffset = "set offsets graph .05, graph .05, graph .05, graph .05"
@gp rand(30) rand(30) "w p pt 4 ps 3 lc '#0072B2' lw 2 t 'marker'" goffset
save(term="pngcairo size 600,400", output="plt_ex10.png") # hide

8
examples/2dplots/ex11.jl Normal file
View File

@ -0,0 +1,8 @@
# This file was generated, do not modify it. # hide
using Gnuplot, Random
Random.seed!(123)
goffset = "set offsets graph .05, graph .05, graph .05, graph .05"
@gp(rand(30), rand(30), "w p pt 6 ps 2 lc '#D55E00' lw 2 t 'marker'",
goffset, title = "scatter plot", xlabel ="X", ylabel = "Y",
"set key b l box opaque")
save(term="pngcairo size 600,400", output="plt_ex11.png") # hide

23
examples/2dplots/ex12.jl Normal file
View File

@ -0,0 +1,23 @@
# This file was generated, do not modify it. # hide
using Gnuplot, Colors, ColorSchemes, Random
Random.seed!(123)
function custom_palette(colormap=:viridis)
cmap = get(colorschemes[colormap], LinRange(0,1,256))
ctmp = "0 '#$(hex(cmap[1]))',"
for i in 2:256; ctmp = ctmp*"$(i-1) '#$(hex(cmap[i]))'," end;
"set palette defined("*ctmp[1:end-1]*")"
end
@gp " " :- # this is just to reset session
@gp :- "set multiplot layout 3,3; set key off" :-
cmaps = [:magma, :viridis, :plasma, :inferno, :berlin, :leonardo,
:devon, :spring, :ice]
for i in 1:9
@gp :- i title = "$(cmaps[i]), pt $(i)" "set size square" :-
@gp(:-, rand(15), rand(15), rand(15),
"w p pt $(i) ps 3 lc palette", custom_palette(cmaps[i]),
"set cbtics out nomirror", "set xtics 0,1", "set ytics 0,1",
"set cbtics 0.0,0.2,1.0", xrange= (-0.1,1.1),
yrange= (-0.1,1.1), :-)
end
@gp
save(term="pngcairo size 900,800", output="plt_ex12.png") # hide

7
examples/2dplots/ex2.jl Normal file
View File

@ -0,0 +1,7 @@
# This file was generated, do not modify it. # hide
using Gnuplot
t = 0:0.001:1
@gp(t, sin.(2π*5*t), "with lines title 'sin' linecolor 'black'")
#save("plt2_ex2.gp") # hide
#save(term="pdf size 5,3", output="plt2_ex2.pdf") # hide
save(term="pngcairo size 600,400", output="plt2_ex2.png") # hide

7
examples/2dplots/ex3.jl Normal file
View File

@ -0,0 +1,7 @@
# This file was generated, do not modify it. # hide
using Gnuplot
x = -2π:0.001:2π
@gp(x, sin.(x), "w l t 'sin'", "set yrange [-1.1:1.1]", "set grid",
x, cos.(x), "with linespoints ls 1 t 'cos' ",
"set style line 1 lc rgb 'black' lt 1 lw 1 pt 6 pi -200 ps 1.5")
save(term="pngcairo size 600,400", output="plt2_ex3.png") # hide

7
examples/2dplots/ex4.jl Normal file
View File

@ -0,0 +1,7 @@
# This file was generated, do not modify it. # hide
using Gnuplot
x = -2π:0.001:2π
@gp(x, sin.(x),"w l t 'sin' lw 2 lc '#56B4E9'", "set grid",
xrange = (-2π - 0.3, 2π + 0.3), yrange = (-1.1,1.1))
@gp(:-, x, cos.(x), "w l t 'cos' lw 2 lc rgb '#E69F00'")
save(term="pngcairo size 600,400", output="plt2_ex4.png") # hide

10
examples/2dplots/ex5.jl Normal file
View File

@ -0,0 +1,10 @@
# This file was generated, do not modify it. # hide
using Gnuplot
x = -2π:0.001:2π
@gp(x, sin.(x), "w l t 'sin' lw 2 lc '#56B4E9'", "set grid",
"set auto fix",
"set offsets graph .05, graph .05, graph .05, graph .05",
ylabel="Y label", xlabel="X label", title = "Title",
"set key bottom left font ',12' title 'Legend' box 2",)
@gp(:-, x, cos.(x), "w l t 'cos' lw 1.5 dashtype 2 lc '#E69F00'")
save(term="pngcairo font 'Consolas, 12' size 600,400", output="plt2_ex5.png") # hide

14
examples/2dplots/ex6.jl Normal file
View File

@ -0,0 +1,14 @@
# This file was generated, do not modify it. # hide
using Gnuplot
x = -2π:0.001:2π
linCol = ["#000000", "#E69F00", "#56B4E9", "#009E73","#F0E442"]
@gp(x, cos.(x), "w l t 'dt 1' lw 2 dt 1 lc '$(linCol[1])'",
"set grid", "set auto fix",
"set offsets graph .05, graph .05, graph .05, graph .05",
ylabel="Y label", xlab="X label",
"set key b r font ',10' title 'dashtype' opaque")
for (idx,ϕ) in enumerate(0.3:0.3:1.3)
@gp(:-, x, cos.(x .+ 2ϕ),
"w l t 'dt $(idx+1)' lw 2 dt $(idx+1) lc '$(linCol[idx+1])'")
end
save(term="pngcairo font 'Consolas, 12' size 600,400", output="plt2_ex6.png") # hide

16
examples/2dplots/ex6_1.jl Normal file
View File

@ -0,0 +1,16 @@
# This file was generated, do not modify it. # hide
using Gnuplot
ecycl_x(r,k,θ) = r*(k .+ 1).*cos.(θ) .- r*cos.((k .+ 1) .* θ)
ecycl_y(r,k,θ) = r*(k .+ 1).*sin.(θ) .- r*sin.((k .+ 1) .* θ)
θ = LinRange(0,6.2π,1000)
@gp(ecycl_x(1,1,θ), ecycl_y(1,1,θ), "w l lw 2 t '1'",
"set size square")
for k in 2:0.5:5.
@gp(:-, ecycl_x(2k,k,θ), ecycl_y(2k,k,θ), "w l lw 2 t '$(k)' ",
"set key outside title 'k, r=2k' box opaque",
xlabel = "x(θ) = r(k+1)cos(θ) -rcos((k+1)θ)",
ylabel = "y(θ) = r(k+1)cos(θ) -rcos((k+1)θ) ",
title = "Epicycloid",:-)
end
@gp
save(term="pngcairo font 'Consolas, 12' size 600,600", output="plt2_ex6dot1.png") # hide

26
examples/2dplots/ex7.jl Normal file
View File

@ -0,0 +1,26 @@
# This file was generated, do not modify it. # hide
using Gnuplot, ColorSchemes
x = -2π:0.001:2π
function circShape(h,k,r)
θ = LinRange(0,2π,500)
h .+ r*sin.(θ), k .+ r*cos.(θ)
end
bgcp1 = "set object rectangle from screen 0,0 to screen 1,1"
bgcp2 = " behind fillcolor rgb 'black' fillstyle solid noborder"
bgcolor = bgcp1*bgcp2
cmap = get(colorschemes[:viridis], LinRange(0,1,15))
@gp " " :- # this is just to reset session
@gp(circShape(0,0,1)..., "w l lw 2 lc '#$(hex(cmap[3]))'",
"set key off", "set auto fix", "set size square",
"set offsets graph .05, graph .05, graph .05, graph .05",
"set border lw 1 lc rgb 'white'",
"set ylabel 'y' textcolor rgb 'white'",
"set xlabel 'x' textcolor rgb 'white'",
"set xzeroaxis linetype 3 linewidth 1",
"set yzeroaxis linetype 3 linewidth 1",
bgcolor)
for (indx,r) in enumerate(0.9:-0.1:0.1)
@gp(:-, circShape(0,0,r)..., "w l lw 2 lc '#$(hex(cmap[indx+3]))'",
"set key off")
end
save(term="pngcairo size 400,400 ", output="plt2_ex7.png") # hide

20
examples/2dplots/ex8.jl Normal file
View File

@ -0,0 +1,20 @@
# This file was generated, do not modify it. # hide
using Gnuplot, Colors, ColorSchemes
x = LinRange(-2π,2π,200)
#colorbar tricks... # hide
cbwt = 0.02 # hide
rightmargin = 0.875 # hide
cboxp="set colorbox user origin graph 1.01, graph 0 size $cbwt, graph 1" # hide
addmargin="set rmargin at screen $rightmargin" # hide
goffset="set offsets graph .05, graph .05, graph .05, graph .05" # hide
#custom palette, colormap # hide
function custom_palette(colormap=:viridis) # hide
cmap = get(colorschemes[colormap], LinRange(0,1,256)) # hide
ctmp = "0 '#$(hex(cmap[1]))'," # hide
for i in 2:256; ctmp = ctmp*"$(i-1) '#$(hex(cmap[i]))'," end; # hide
"set palette defined("*ctmp[1:end-1]*")" # hide
end # hide
@gp(x, -0.65sin.(3x), x, "w l lw 3 dt 1 lc palette",
"set key off", "set auto fix")
#goffset, cboxp, addmargin) # hide
save(term="pngcairo size 600,400", output="plt_ex8.png") # hide

27
examples/2dplots/ex9.jl Normal file
View File

@ -0,0 +1,27 @@
# This file was generated, do not modify it. # hide
using Gnuplot, Colors, ColorSchemes, Random
Random.seed!(123)
function custom_palette(colormap=:viridis)
cmap = get(colorschemes[colormap], LinRange(0,1,256))
ctmp = "0 '#$(hex(cmap[1]))',"
for i in 2:256; ctmp = ctmp*"$(i-1) '#$(hex(cmap[i]))'," end;
"set palette defined("*ctmp[1:end-1]*")"
end
# Archimedes spiral
a = 1.5
b = -2.4
t = LinRange(0,5*π,500)
x = (a .+ b*t) .* cos.(t)
y = (a .+ b*t) .* sin.(t)
@gp " " :- # this is just to reset session
@gp :- "set multiplot layout 3,3; set key off;
unset ytics; unset xtics; unset border" :-
colormaps = [:magma, :viridis, :plasma, :inferno, :berlin,
:leonardo, :devon, :spring, :ice]
for i in 1:9
@gp :- i title = "$(colormaps[i])" "set size square" :-
@gp(:-, x, y, t, "w l lw 3 dt 1 lc palette",
custom_palette(colormaps[i]),"set cbtics out nomirror", :-)
end
@gp
save(term="pngcairo size 900,800", output="plt_ex9.png") # hide

View File

@ -0,0 +1,7 @@
# This file was generated, do not modify it. # hide
using Gnuplot
x=[0,1,2]
y=[0,1,2]
Z=[10 10 10; 10 3 10; 10 2 10]
@gsp x y Z "w l lc 'red'"
save(term="png", output="plt3d_ex1.png")

View File

@ -0,0 +1,9 @@
# This file was generated, do not modify it. # hide
using Gnuplot
@gsp "unset key" "set multi layout 2,2 title 'Multiplot title'" :-
@gsp :- 1 x y Z "w linespoints pt 4 ps 2" "set view 55, 65" :-
@gsp :- 2 x y Z "w points pt 3 ps 3" "set view 55, 65" :-
@gsp :- 3 x y Z "w l palette" "set view 55, 65" :-
@gsp :- 4 x y Z "w pm3d" "set view 55, 65" "set key off" :-
@gsp :- x y Z "w l lc 'white'"
save(term="png size 1600,1200", output="plt3d_ex2.png")

View File

@ -0,0 +1,10 @@
# This file was generated, do not modify it. # hide
using Gnuplot
@gsp " " :- # reset session
@gsp "unset key" "set multi layout 2,2 title 'Multiplot title'" :-
@gsp :- 1 x y Z "w linespoints pt 4 ps 2" :-
@gsp :- 2 x y Z "w points pt 3 ps 3" :-
@gsp :- 3 x y Z "w l palette" "set view 55, 65" :-
@gsp :- 4 x y Z "w pm3d" "set view 55, 65" "set key off" :-
@gsp :- x y Z "w l lc 'white'"
save(term="pngcairo size 1200,800", output="plt3d_ex2.png")

View File

@ -0,0 +1,8 @@
# This file was generated, do not modify it. # hide
using Gnuplot
@gsp " " :- # reset session
@gsp "unset key" "set multi layout 1,2 title 'Multiplot title'" :-
@gsp :- 1 x y Z "w l palette" "set view 55, 65" :-
@gsp :- 2 x y Z "w pm3d" "set view 55, 65" "set key off" :-
@gsp :- x y Z "w l lc 'white'"
save(term="pngcairo size 800,400", output="plt3d_ex2_2.png")

View File

@ -0,0 +1,8 @@
# This file was generated, do not modify it. # hide
using Gnuplot
x = y = -15:0.33:15
fz(x,y) = sin.(sqrt.(x.^2 + y.^2))./sqrt.(x.^2+y.^2)
fxy = [fz(x,y) for x in x, y in y]
@gsp " " :- # reset session
@gsp :- x y fxy "w l lc 'orange'"
save(term="pngcairo size 800,800", output="plt3d_ex3.png")

View File

@ -0,0 +1,9 @@
# This file was generated, do not modify it. # hide
using Gnuplot
x = y = -15:0.33:15
fz(x,y) = sin.(sqrt.(x.^2 + y.^2))./sqrt.(x.^2+y.^2)
fxy = [fz(x,y) for x in x, y in y]
@gsp " " :- # reset session
@gsp(:-,x, y, fxy, "w pm3d", "set ylabel 'y' textcolor rgb 'red'",
"set xlabel 'x' textcolor rgb 'blue'")
save(term="pngcairo size 800,800", output="plt3d_ex3_1.png")

View File

@ -0,0 +1,11 @@
# This file was generated, do not modify it. # hide
using Gnuplot
x = y = -15:0.33:15
fz(x,y) = sin.(sqrt.(x.^2 + y.^2))./sqrt.(x.^2+y.^2)
fxy = [fz(x,y) for x in x, y in y]
@gsp " " :- # reset session
@gsp(x, y, fxy, "w l lc palette", "set view map",
"set contour base;set key off","set auto fix",
"set cntrparam levels 15", "unset surface",
xlab = "x", ylab = "y")
save(term="pngcairo size 800,800", output="plt3d_ex4.png")

View File

@ -0,0 +1,7 @@
# This file was generated, do not modify it. # hide
using Gnuplot, Random
Random.seed!(1234)
matrix = randn(50,60)
@gsp " " :- # reset session
@gsp matrix "w image" "set view map" "set auto fix"
save(term="pngcairo size 800,800", output="plt3d_ex5.png")

View File

@ -0,0 +1,13 @@
# This file was generated, do not modify it. # hide
using Gnuplot, ColorSchemes, RDatasets, Colors
function gp_palette(colormap=:viridis)
cmap = get(colorschemes[colormap], LinRange(0,1,256))
ctmp = "0 '#$(hex(cmap[1]))',"
for i in 2:256; ctmp = ctmp*"$(i-1) '#$(hex(cmap[i]))'," end;
"set palette defined("*ctmp[1:end-1]*")"
end
volcano = Matrix{Float64}(dataset("datasets", "volcano"))
@gsp(volcano, "w image", "set view map", "set auto fix",
gp_palette(:inferno), title = "Auckland s Maunga Whau Volcano")
save(term="pngcairo size 900,600", output="plt3d_ex6.png")