Gnuplot.jl/test/runtests.jl
2017-08-26 00:14:37 +02:00

194 lines
5.8 KiB
Julia

using Base.Test
using Gnuplot
function pressEnter()
println("Press enter...")
readline(STDIN)
end
function gp_test(terminal="unknown")
gp_setOption(verb=1)
gp_setOption(startup="set term $terminal")
gp_reset()
x = collect(1.:100)
#-----------------------------------------------------------------
gp_send("plot sin(x)")
terminal == "unknown" || pressEnter()
#-----------------------------------------------------------------
id1 = gp_current()
id2 = gp_new()
id3 = gp_new()
for i in 1:10
gp_setCurrent(id1)
gp_send("plot sin($i*x)")
gp_setCurrent(id2)
gp_send("plot sin($i*x)")
gp_setCurrent(id3)
gp_send("plot sin($i*x)")
sleep(0.3)
end
terminal == "unknown" || pressEnter()
gp_exitAll()
#-----------------------------------------------------------------
gp_reset()
name = gp_data([1,2,3,5,8,13])
gp_plot("$name w points ps 3")
gp_dump()
terminal == "unknown" || pressEnter()
gp_plot(last=true, "w l lw 3")
gp_dump()
terminal == "unknown" || pressEnter()
#-----------------------------------------------------------------
gp_reset()
gp_cmd("set format y \"%.1f\"")
gp_cmd("set key box opaque")
gp_cmd("set xrange [-2*pi:2*pi]")
gp_multi("layout 2,2 columnsfirst title \"Multiplot title\"")
gp_cmd(ylab="Y label")
gp_plot("sin(x) lt 1")
gp_next()
gp_cmd(xlab="X label")
gp_plot("cos(x) lt 2")
gp_next()
gp_cmd("unset ylabel")
gp_cmd("unset ytics")
gp_cmd("unset xlabel")
gp_plot("sin(2*x) lt 3")
gp_next()
gp_cmd(xlab="X label")
gp_plot("cos(2*x) lt 4")
gp_dump()
terminal == "unknown" || pressEnter()
#-----------------------------------------------------------------
@gp("set format y \"%.1f\"",
"set key box opaque",
xr=(-2pi,2pi),
:multi, "layout 2,2 columnsfirst title \"Multiplot title\"",
ylab="Y label",
:plot, "sin(x) lt 1",
:next,
xlab="X label",
:plot, "cos(x) lt 2",
:next,
"unset ylabel",
"unset ytics",
"unset xlabel",
:plot, "sin(2*x) lt 3",
:next,
xlab="X label",
:plot, "cos(2*x) lt 4"
)
terminal == "unknown" || pressEnter()
#-----------------------------------------------------------------
gp_reset()
@gp_("set key off",
xr=(1,10), yr=(1,100), xlog=true, ylog=true,
:multi, "layout 2,2 columnsfirst title \"Multiplot title\"")
for i in 1:4
@gp_(x, x.^i, "w l lw 3 lt $i")
@gp_(:next)
end
gp_dump()
terminal == "unknown" || pressEnter()
#-----------------------------------------------------------------
lw = 5
@gp "set title 'My title'" x x.^2. "w l tit '{/Symbol L}_{/Symbol a}' lw $lw dt 2 lc rgb 'red'"
terminal == "unknown" || pressEnter()
#-----------------------------------------------------------------
@gp("set title 'My title'",
x, x.^2 , "w l tit '{/Symbol L}_{/Symbol a}' lw $lw dt 2 lc rgb 'red'",
x, x.^2.2, "w l tit 'bbb'"
)
terminal == "unknown" || pressEnter()
#-----------------------------------------------------------------
@gp("""
approx_1(x) = x - x**3/6
approx_2(x) = x - x**3/6 + x**5/120
approx_3(x) = x - x**3/6 + x**5/120 - x**7/5040
label1 = "x - {x^3}/3!"
label2 = "x - {x^3}/3! + {x^5}/5!"
label3 = "x - {x^3}/3! + {x^5}/5! - {x^7}/7!"
#
set termoption enhanced
save_encoding = GPVAL_ENCODING
set encoding utf8
#
set title "Polynomial approximation of sin(x)"
set key Left center top reverse
set xrange [ -3.2 : 3.2 ]
set xtics ("" -pi, "-π/2" -pi/2, 0, "π/2" pi/2, "π" pi)
set format y "%.1f"
set samples 500
set style fill solid 0.4 noborder""",
:plot, "'+' using 1:(sin(\$1)):(approx_1(\$1)) with filledcurve title label1 lt 3",
:plot, "'+' using 1:(sin(\$1)):(approx_2(\$1)) with filledcurve title label2 lt 2",
:plot, "'+' using 1:(sin(\$1)):(approx_3(\$1)) with filledcurve title label3 lt 1",
:plot, "sin(x) with lines lw 1 lc rgb 'black'")
#-----------------------------------------------------------------
@gp("""
set zrange [-1:1]
unset label
unset arrow
sinc(u,v) = sin(sqrt(u**2+v**2)) / sqrt(u**2+v**2)
set xrange [-5:5]; set yrange [-5:5]
set arrow from 5,-5,-1.2 to 5,5,-1.2 lt -1
set label 1 "increasing v" at 6,0,-1
set arrow from 5,6,-1 to 5,5,-1 lt -1
set label 2 "u=0" at 5,6.5,-1
set arrow from 5,6,sinc(5,5) to 5,5,sinc(5,5) lt -1
set label 3 "u=1" at 5,6.5,sinc(5,5)
set parametric
set hidden3d offset 0 # front/back coloring makes no sense for fenceplot #
set isosamples 2,33
xx=-5; dx=(4.99-(-4.99))/9
x0=xx; xx=xx+dx
x1=xx; xx=xx+dx
x2=xx; xx=xx+dx
x3=xx; xx=xx+dx
x4=xx; xx=xx+dx
x5=xx; xx=xx+dx
x6=xx; xx=xx+dx
x7=xx; xx=xx+dx
x8=xx; xx=xx+dx
x9=xx; xx=xx+dx""",
splot=true,
:plot, "[u=0:1][v=-4.99:4.99]x0, v, (u<0.5) ? -1 : sinc(x0,v) notitle",
:plot, "x1, v, (u<0.5) ? -1 : sinc(x1,v) notitle",
:plot, "x2, v, (u<0.5) ? -1 : sinc(x2,v) notitle",
:plot, "x3, v, (u<0.5) ? -1 : sinc(x3,v) notitle",
:plot, "x4, v, (u<0.5) ? -1 : sinc(x4,v) notitle",
:plot, "x5, v, (u<0.5) ? -1 : sinc(x5,v) notitle",
:plot, "x6, v, (u<0.5) ? -1 : sinc(x6,v) notitle",
:plot, "x7, v, (u<0.5) ? -1 : sinc(x7,v) notitle",
:plot, "x8, v, (u<0.5) ? -1 : sinc(x8,v) notitle",
:plot, "x9, v, (u<0.5) ? -1 : sinc(x9,v) notitle")
gp_exitAll()
return true
end
@test gp_test()