Code re-factoring
This commit is contained in:
parent
56b64fcef7
commit
6a4e95f377
1624
src/Gnuplot.jl
1624
src/Gnuplot.jl
File diff suppressed because it is too large
Load Diff
165
test/runtests.jl
165
test/runtests.jl
@ -1,123 +1,59 @@
|
|||||||
using Base.Test
|
using Base.Test
|
||||||
using Gnuplot
|
using Gnuplot
|
||||||
|
|
||||||
function pressEnter()
|
function gp_test()
|
||||||
println("Press enter...")
|
|
||||||
readline(STDIN)
|
|
||||||
end
|
|
||||||
|
|
||||||
function gp_test(terminal="unknown")
|
|
||||||
gpOptions.startup = "set term $terminal"
|
|
||||||
|
|
||||||
gpReset()
|
|
||||||
x = collect(1.:100)
|
x = collect(1.:100)
|
||||||
|
|
||||||
#-----------------------------------------------------------------
|
#-----------------------------------------------------------------
|
||||||
gpSend("plot sin(x)")
|
gp1 = GnuplotProc()
|
||||||
terminal == "unknown" || pressEnter()
|
gp2 = GnuplotProc()
|
||||||
|
gp3 = GnuplotProc()
|
||||||
#-----------------------------------------------------------------
|
|
||||||
id1 = gpCurrentID()
|
|
||||||
id2 = gpNewSession()
|
|
||||||
id3 = gpNewSession()
|
|
||||||
|
|
||||||
for i in 1:10
|
for i in 1:10
|
||||||
gpSetCurrentID(id1)
|
@gp gp1 "plot sin($i*x)"
|
||||||
gpSend("plot sin($i*x)")
|
@gp gp2 "plot sin($i*x)"
|
||||||
|
@gp gp3 "plot sin($i*x)"
|
||||||
gpSetCurrentID(id2)
|
|
||||||
gpSend("plot sin($i*x)")
|
|
||||||
|
|
||||||
gpSetCurrentID(id3)
|
|
||||||
gpSend("plot sin($i*x)")
|
|
||||||
|
|
||||||
sleep(0.3)
|
sleep(0.3)
|
||||||
end
|
end
|
||||||
terminal == "unknown" || pressEnter()
|
GnuplotQuitAll()
|
||||||
gpExitAll()
|
|
||||||
|
|
||||||
#-----------------------------------------------------------------
|
#-----------------------------------------------------------------
|
||||||
gpReset()
|
@gp "plot sin(x)"
|
||||||
name = gpData([1,2,3,5,8,13])
|
@gp "plot sin(x)" "pl cos(x)"
|
||||||
gpPlot("$name w points ps 3")
|
@gp "plo sin(x)" "s cos(x)"
|
||||||
gpDump()
|
|
||||||
terminal == "unknown" || pressEnter()
|
|
||||||
|
|
||||||
gpPlot(last=true, "w l lw 3")
|
@gpi 0 "plot sin(x)"
|
||||||
gpDump()
|
@gpi "plot cos(x)" :>
|
||||||
terminal == "unknown" || pressEnter()
|
|
||||||
|
|
||||||
#-----------------------------------------------------------------
|
|
||||||
gpReset()
|
|
||||||
|
|
||||||
gpCmd("set format y \"%.1f\"")
|
@gp "plot sin(x)" 2 xr=(-2pi,2pi) "pause 3" "plot cos(4*x)"
|
||||||
gpCmd("set key box opaque")
|
|
||||||
gpCmd("set xrange [-2*pi:2*pi]")
|
|
||||||
gpMulti("layout 2,2 columnsfirst title \"Multiplot title\"")
|
|
||||||
|
|
||||||
gpCmd(ylab="Y label")
|
x = linspace(-2pi, 2pi, 100);
|
||||||
gpPlot("sin(x) lt 1")
|
y = 1.5 * sin.(0.3 + 0.7x) ;
|
||||||
|
noise = randn(length(x))./2;
|
||||||
|
e = 0.5 * ones(x);
|
||||||
|
|
||||||
gpNext()
|
@gp x y
|
||||||
gpCmd(xlab="X label")
|
@gp x y "w l"
|
||||||
gpPlot("cos(x) lt 2")
|
@gp x y :aa "plot \$aa w l" "pl \$aa u 1:(2*\$2) w l"
|
||||||
|
|
||||||
gpNext()
|
@gp randn(Float64, 30, 50)
|
||||||
gpCmd("unset ylabel")
|
|
||||||
gpCmd("unset ytics")
|
|
||||||
gpCmd("unset xlabel")
|
|
||||||
gpPlot("sin(2*x) lt 3")
|
|
||||||
|
|
||||||
gpNext()
|
@gp("set key horizontal", "set grid",
|
||||||
gpCmd(xlab="X label")
|
xrange=(-7,7), ylabel="Y label",
|
||||||
gpPlot("cos(2*x) lt 4")
|
x, y, "w l t 'Real model' dt 2 lw 2 lc rgb 'red'",
|
||||||
|
x, y+noise, e, "w errorbars t 'Data'");
|
||||||
|
|
||||||
gpDump()
|
|
||||||
terminal == "unknown" || pressEnter()
|
|
||||||
|
|
||||||
#-----------------------------------------------------------------
|
@gpi 0 "f(x) = a * sin(b + c*x); a = 1; b = 1; c = 1;"
|
||||||
@gp("set format y \"%.1f\"",
|
@gpi x y+noise e :aa
|
||||||
"set key box opaque",
|
@gpi "fit f(x) \$aa u 1:2:3 via a, b, c;"
|
||||||
xr=(-2pi,2pi),
|
@gpi "set multiplot layout 2,1"
|
||||||
:multi, "layout 2,2 columnsfirst title \"Multiplot title\"",
|
@gpi "plot \$aa w points" ylab="Data and model"
|
||||||
ylab="Y label",
|
@gpi "plot \$aa u 1:(f(\$1)) w lines"
|
||||||
:plot, "sin(x) lt 1",
|
@gpi 2 xlab="X label" ylab="Residuals"
|
||||||
:next,
|
@gpi "plot \$aa u 1:((f(\$1)-\$2) / \$3):(1) w errorbars notit" :>
|
||||||
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()
|
|
||||||
|
|
||||||
#-----------------------------------------------------------------
|
|
||||||
@gpi(:reset, "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
|
|
||||||
@gpi(x, x.^i, "w l lw 3 lt $i", :next)
|
|
||||||
end
|
|
||||||
@gpi()
|
|
||||||
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("""
|
@gp("""
|
||||||
@ -139,12 +75,12 @@ function gp_test(terminal="unknown")
|
|||||||
set format y "%.1f"
|
set format y "%.1f"
|
||||||
set samples 500
|
set samples 500
|
||||||
set style fill solid 0.4 noborder""",
|
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_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_2(\$1)) with filledcurve title label2 lt 2",
|
||||||
:plot, "'+' using 1:(sin(\$1)):(approx_3(\$1)) with filledcurve title label3 lt 1",
|
"plot '+' using 1:(sin(\$1)):(approx_3(\$1)) with filledcurve title label3 lt 1",
|
||||||
:plot, "sin(x) with lines lw 1 lc rgb 'black'")
|
"plot sin(x) with lines lw 1 lc rgb 'black'")
|
||||||
|
|
||||||
#-----------------------------------------------------------------
|
#-----------------------------------------------------------------
|
||||||
@gp("""
|
@gp("""
|
||||||
set zrange [-1:1]
|
set zrange [-1:1]
|
||||||
unset label
|
unset label
|
||||||
@ -171,19 +107,18 @@ function gp_test(terminal="unknown")
|
|||||||
x7=xx; xx=xx+dx
|
x7=xx; xx=xx+dx
|
||||||
x8=xx; xx=xx+dx
|
x8=xx; xx=xx+dx
|
||||||
x9=xx; xx=xx+dx""",
|
x9=xx; xx=xx+dx""",
|
||||||
splot=true,
|
"splot [u=0:1][v=-4.99:4.99]x0, v, (u<0.5) ? -1 : sinc(x0,v) notitle",
|
||||||
:plot, "[u=0:1][v=-4.99:4.99]x0, v, (u<0.5) ? -1 : sinc(x0,v) notitle",
|
"splot x1, v, (u<0.5) ? -1 : sinc(x1,v) notitle",
|
||||||
:plot, "x1, v, (u<0.5) ? -1 : sinc(x1,v) notitle",
|
"splot x2, v, (u<0.5) ? -1 : sinc(x2,v) notitle",
|
||||||
:plot, "x2, v, (u<0.5) ? -1 : sinc(x2,v) notitle",
|
"splot x3, v, (u<0.5) ? -1 : sinc(x3,v) notitle",
|
||||||
:plot, "x3, v, (u<0.5) ? -1 : sinc(x3,v) notitle",
|
"splot x4, v, (u<0.5) ? -1 : sinc(x4,v) notitle",
|
||||||
:plot, "x4, v, (u<0.5) ? -1 : sinc(x4,v) notitle",
|
"splot x5, v, (u<0.5) ? -1 : sinc(x5,v) notitle",
|
||||||
:plot, "x5, v, (u<0.5) ? -1 : sinc(x5,v) notitle",
|
"splot x6, v, (u<0.5) ? -1 : sinc(x6,v) notitle",
|
||||||
:plot, "x6, v, (u<0.5) ? -1 : sinc(x6,v) notitle",
|
"splot x7, v, (u<0.5) ? -1 : sinc(x7,v) notitle",
|
||||||
:plot, "x7, v, (u<0.5) ? -1 : sinc(x7,v) notitle",
|
"splot x8, v, (u<0.5) ? -1 : sinc(x8,v) notitle",
|
||||||
:plot, "x8, v, (u<0.5) ? -1 : sinc(x8,v) notitle",
|
"splot x9, v, (u<0.5) ? -1 : sinc(x9,v) notitle")
|
||||||
:plot, "x9, v, (u<0.5) ? -1 : sinc(x9,v) notitle")
|
|
||||||
|
|
||||||
gpExitAll()
|
GnuplotQuitAll()
|
||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user