using Base.Test using Gnuplot const gp = Gnuplot function pressEnter() println("Press enter...") readline(STDIN) end function gp_test(terminal="wxt") 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.session() id3 = gp.session() 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() #----------------------------------------------------------------- @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(""" 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()