Bugfix and update
This commit is contained in:
parent
4c4b8ea661
commit
69f34a4777
@ -1,5 +1,7 @@
|
|||||||
# Gnuplot
|
# Gnuplot
|
||||||
|
|
||||||
|
Work in progress...
|
||||||
|
|
||||||
[](https://travis-ci.org/gcalderone/Gnuplot.jl)
|
[](https://travis-ci.org/gcalderone/Gnuplot.jl)
|
||||||
|
|
||||||
[](https://coveralls.io/github/gcalderone/Gnuplot.jl?branch=master)
|
[](https://coveralls.io/github/gcalderone/Gnuplot.jl?branch=master)
|
||||||
|
|||||||
124
src/Gnuplot.jl
124
src/Gnuplot.jl
@ -196,8 +196,8 @@ end
|
|||||||
"""
|
"""
|
||||||
Return a unique data block name
|
Return a unique data block name
|
||||||
"""
|
"""
|
||||||
function gp_mkBlockName(prefix="")
|
@AbbrvKW function gp_mkBlockName(;prefix::Union{Void,String}=nothing)
|
||||||
if prefix == ""
|
if prefix == nothing
|
||||||
prefix = string("d", gp_current())
|
prefix = string("d", gp_current())
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -251,24 +251,21 @@ Example:
|
|||||||
gp_setOption(cmd="/path/to/gnuplot", verb=2, startup="set term wxt")
|
gp_setOption(cmd="/path/to/gnuplot", verb=2, startup="set term wxt")
|
||||||
```
|
```
|
||||||
"""
|
"""
|
||||||
function gp_setOption(;kw...)
|
@AbbrvKW function gp_setOption(;cmd::Union{Void,String}=nothing,
|
||||||
@AbbrvKW_check(kw,
|
startup::Union{Void,String}=nothing,
|
||||||
cmd::Nullable{String}=nothing,
|
verbose::Union{Void,Int}=nothing)
|
||||||
startup::Nullable{String}=nothing,
|
if startup != nothing
|
||||||
verbose::Nullable{Int}=nothing)
|
main.startup = startup
|
||||||
|
|
||||||
if !isnull(startup)
|
|
||||||
main.startup = get(startup)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
if !isnull(cmd)
|
if cmd != nothing
|
||||||
main.gnuplotCmd = get(cmd)
|
main.gnuplotCmd = cmd
|
||||||
checkGnuplotVersion()
|
checkGnuplotVersion()
|
||||||
end
|
end
|
||||||
|
|
||||||
if !isnull(verbose)
|
if verbose != nothing
|
||||||
@assert (0 <= get(verbose) <= 4)
|
@assert (0 <= verbose <= 4)
|
||||||
main.verboseLev = get(verbose)
|
main.verboseLev = verbose
|
||||||
end
|
end
|
||||||
|
|
||||||
return nothing
|
return nothing
|
||||||
@ -517,24 +514,24 @@ gp_cmd("set key left", xrange=(1,3))
|
|||||||
gp_cmd(title="My title", xlab="X label", xla="Y label")
|
gp_cmd(title="My title", xlab="X label", xla="Y label")
|
||||||
```
|
```
|
||||||
"""
|
"""
|
||||||
function gp_cmd(v::String=""; kw...)
|
@AbbrvKW function gp_cmd(v::String="";
|
||||||
#@show kw
|
splot::Union{Void,Bool}=nothing,
|
||||||
@AbbrvKW_check(kw,
|
multiID::Union{Void,Int}=nothing,
|
||||||
multiID::Nullable{Int}=nothing,
|
xrange::Union{Void,NTuple{2, Number}}=nothing,
|
||||||
xrange::Nullable{NTuple{2, Float64}}=nothing,
|
yrange::Union{Void,NTuple{2, Number}}=nothing,
|
||||||
yrange::Nullable{NTuple{2, Float64}}=nothing,
|
zrange::Union{Void,NTuple{2, Number}}=nothing,
|
||||||
zrange::Nullable{NTuple{2, Float64}}=nothing,
|
title::Union{Void,String}=nothing,
|
||||||
title::Nullable{String}=nothing,
|
xlabel::Union{Void,String}=nothing,
|
||||||
xlabel::Nullable{String}=nothing,
|
ylabel::Union{Void,String}=nothing,
|
||||||
ylabel::Nullable{String}=nothing,
|
zlabel::Union{Void,String}=nothing,
|
||||||
zlabel::Nullable{String}=nothing,
|
xlog::Union{Void,Bool}=nothing,
|
||||||
xlog::Nullable{Bool}=nothing,
|
ylog::Union{Void,Bool}=nothing,
|
||||||
ylog::Nullable{Bool}=nothing,
|
zlog::Union{Void,Bool}=nothing)
|
||||||
zlog::Nullable{Bool}=nothing)
|
|
||||||
|
|
||||||
gp_getProcOrStartIt()
|
gp_getProcOrStartIt()
|
||||||
cur = main.states[main.curPos]
|
cur = main.states[main.curPos]
|
||||||
mID = isnull(multiID) ? cur.multiID : get(multiID)
|
splot == nothing || (cur.splot = splot)
|
||||||
|
mID = multiID == nothing ? cur.multiID : multiID
|
||||||
|
|
||||||
if v != ""
|
if v != ""
|
||||||
push!(cur.cmds, MultiCmd(v, mID))
|
push!(cur.cmds, MultiCmd(v, mID))
|
||||||
@ -543,18 +540,18 @@ function gp_cmd(v::String=""; kw...)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
isnull(xrange) || gp_cmd(multiID=mID, "set xrange [" * join(get(xrange), ":") * "]")
|
xrange == nothing || gp_cmd(multiID=mID, "set xrange [" * join(xrange, ":") * "]")
|
||||||
isnull(yrange) || gp_cmd(multiID=mID, "set yrange [" * join(get(yrange), ":") * "]")
|
yrange == nothing || gp_cmd(multiID=mID, "set yrange [" * join(yrange, ":") * "]")
|
||||||
isnull(zrange) || gp_cmd(multiID=mID, "set zrange [" * join(get(zrange), ":") * "]")
|
zrange == nothing || gp_cmd(multiID=mID, "set zrange [" * join(zrange, ":") * "]")
|
||||||
|
|
||||||
isnull(title) || gp_cmd(multiID=mID, "set title '" * get(title ) * "'")
|
title == nothing || gp_cmd(multiID=mID, "set title '" * title * "'")
|
||||||
isnull(xlabel) || gp_cmd(multiID=mID, "set xlabel '" * get(xlabel) * "'")
|
xlabel == nothing || gp_cmd(multiID=mID, "set xlabel '" * xlabel * "'")
|
||||||
isnull(ylabel) || gp_cmd(multiID=mID, "set ylabel '" * get(ylabel) * "'")
|
ylabel == nothing || gp_cmd(multiID=mID, "set ylabel '" * ylabel * "'")
|
||||||
isnull(zlabel) || gp_cmd(multiID=mID, "set zlabel '" * get(zlabel) * "'")
|
zlabel == nothing || gp_cmd(multiID=mID, "set zlabel '" * zlabel * "'")
|
||||||
|
|
||||||
isnull(xlog) || gp_cmd(multiID=mID, (get(xlog) ? "" : "un") * "set logscale x")
|
xlog == nothing || gp_cmd(multiID=mID, (xlog ? "" : "un") * "set logscale x")
|
||||||
isnull(ylog) || gp_cmd(multiID=mID, (get(ylog) ? "" : "un") * "set logscale y")
|
ylog == nothing || gp_cmd(multiID=mID, (ylog ? "" : "un") * "set logscale y")
|
||||||
isnull(zlog) || gp_cmd(multiID=mID, (get(zlog) ? "" : "un") * "set logscale z")
|
zlog == nothing || gp_cmd(multiID=mID, (zlog ? "" : "un") * "set logscale z")
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
@ -593,14 +590,14 @@ name = gp_data(x, y, name="MyChosenName")
|
|||||||
|
|
||||||
The returned name can be used as input to `gp_plot`.
|
The returned name can be used as input to `gp_plot`.
|
||||||
"""
|
"""
|
||||||
function gp_data(data::Vararg{AbstractArray{T,1},N}; kw...) where {T,N}
|
@AbbrvKW function gp_data(data::Vararg{AbstractArray{T,1},N};
|
||||||
@AbbrvKW_check(kw, name::String="", prefix::String="")
|
name::Union{Void,String}=nothing,
|
||||||
|
prefix::Union{Void,String}=nothing) where {T,N}
|
||||||
gp_getProcOrStartIt()
|
gp_getProcOrStartIt()
|
||||||
cur = main.states[main.curPos]
|
cur = main.states[main.curPos]
|
||||||
|
|
||||||
if name == ""
|
if name == nothing
|
||||||
name = gp_mkBlockName(prefix)
|
name = gp_mkBlockName(pre=prefix)
|
||||||
end
|
end
|
||||||
name = "\$$name"
|
name = "\$$name"
|
||||||
|
|
||||||
@ -674,23 +671,20 @@ gp_plot("\$src u 1:(\\\$2+10) w l tit 'Pow 2.2, offset=10'")
|
|||||||
gp_dump() # Do the plot
|
gp_dump() # Do the plot
|
||||||
```
|
```
|
||||||
"""
|
"""
|
||||||
function gp_plot(spec::String; kw...)
|
@AbbrvKW function gp_plot(spec::String;
|
||||||
@AbbrvKW_check(kw,
|
lastData::Bool=false,
|
||||||
lastData::Bool=false,
|
file::Union{Void,String}=nothing,
|
||||||
file::Nullable{String}=nothing,
|
multiID::Union{Void,Int}=nothing)
|
||||||
multiID::Nullable{Int}=nothing,
|
|
||||||
splot::Nullable{Bool}=nothing)
|
|
||||||
|
|
||||||
gp_getProcOrStartIt()
|
gp_getProcOrStartIt()
|
||||||
cur = main.states[main.curPos]
|
cur = main.states[main.curPos]
|
||||||
mID = isnull(multiID) ? cur.multiID : get(multiID)
|
mID = multiID == nothing ? cur.multiID : multiID
|
||||||
isnull(splot) || (cur.splot = splot)
|
|
||||||
|
|
||||||
src = ""
|
src = ""
|
||||||
if lastData
|
if lastData
|
||||||
src = cur.lastDataName
|
src = cur.lastDataName
|
||||||
elseif !isnull(file)
|
elseif file != nothing
|
||||||
src = "'" * get(file) * "'"
|
src = "'" * file * "'"
|
||||||
end
|
end
|
||||||
push!(cur.plot, MultiCmd("$src $spec", mID))
|
push!(cur.plot, MultiCmd("$src $spec", mID))
|
||||||
end
|
end
|
||||||
@ -698,7 +692,7 @@ end
|
|||||||
|
|
||||||
#---------------------------------------------------------------------
|
#---------------------------------------------------------------------
|
||||||
"""
|
"""
|
||||||
Similar to `@gp`, but do not adds the calls to `gp_reset()` at the
|
Similar to `@gp`, but do not add calls to `gp_reset()` at the
|
||||||
beginning and `gp_dump()` at the end.
|
beginning and `gp_dump()` at the end.
|
||||||
"""
|
"""
|
||||||
macro gp_(args...)
|
macro gp_(args...)
|
||||||
@ -848,18 +842,16 @@ end
|
|||||||
Print all data and commands stored in the current session on STDOUT or
|
Print all data and commands stored in the current session on STDOUT or
|
||||||
on a file.
|
on a file.
|
||||||
"""
|
"""
|
||||||
function gp_dump(;kw...)
|
@AbbrvKW function gp_dump(; all::Bool=false,
|
||||||
@AbbrvKW_check(kw,
|
dry::Bool=false,
|
||||||
all::Bool=false,
|
data::Bool=false,
|
||||||
dry::Bool=false,
|
file::Union{Void,String}=nothing)
|
||||||
data::Bool=false,
|
|
||||||
file::Nullable{String}=nothing)
|
|
||||||
|
|
||||||
if main.curPos == 0
|
if main.curPos == 0
|
||||||
return ""
|
return ""
|
||||||
end
|
end
|
||||||
|
|
||||||
if !isnull(file)
|
if file != nothing
|
||||||
all = true
|
all = true
|
||||||
dry = true
|
dry = true
|
||||||
end
|
end
|
||||||
@ -901,8 +893,8 @@ function gp_dump(;kw...)
|
|||||||
push!(out, "unset multiplot")
|
push!(out, "unset multiplot")
|
||||||
end
|
end
|
||||||
|
|
||||||
if !isnull(file)
|
if file != nothing
|
||||||
sOut = open(get(file), "w")
|
sOut = open(file, "w")
|
||||||
for s in out; println(sOut, s); end
|
for s in out; println(sOut, s); end
|
||||||
close(sOut)
|
close(sOut)
|
||||||
end
|
end
|
||||||
|
|||||||
@ -77,8 +77,7 @@ function gp_test(terminal="unknown")
|
|||||||
terminal == "unknown" || pressEnter()
|
terminal == "unknown" || pressEnter()
|
||||||
|
|
||||||
#-----------------------------------------------------------------
|
#-----------------------------------------------------------------
|
||||||
@gp(
|
@gp("set format y \"%.1f\"",
|
||||||
"set format y \"%.1f\"",
|
|
||||||
"set key box opaque",
|
"set key box opaque",
|
||||||
xr=(-2pi,2pi),
|
xr=(-2pi,2pi),
|
||||||
:multi, "layout 2,2 columnsfirst title \"Multiplot title\"",
|
:multi, "layout 2,2 columnsfirst title \"Multiplot title\"",
|
||||||
@ -123,6 +122,70 @@ function gp_test(terminal="unknown")
|
|||||||
)
|
)
|
||||||
terminal == "unknown" || pressEnter()
|
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()
|
gp_exitAll()
|
||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user