Gaston: Unset set size for subplots - Follow Plots.DPI - Cleanup
This commit is contained in:
parent
434656def6
commit
914ea027d0
@ -2,8 +2,6 @@
|
|||||||
const G = Gaston
|
const G = Gaston
|
||||||
const GastonSubplot = G.Plot
|
const GastonSubplot = G.Plot
|
||||||
const GASTON_MARKER_SCALING = 1.3 / 5.0
|
const GASTON_MARKER_SCALING = 1.3 / 5.0
|
||||||
const GNUPLOT_DPI = 72 # Compensate for DPI with increased resolution
|
|
||||||
|
|
||||||
|
|
||||||
# --------------------------------------------
|
# --------------------------------------------
|
||||||
# These functions are called by Plots
|
# These functions are called by Plots
|
||||||
@ -12,7 +10,7 @@ const GNUPLOT_DPI = 72 # Compensate for DPI with increased resolution
|
|||||||
# Create the window/figure for this backend.
|
# Create the window/figure for this backend.
|
||||||
function _create_backend_figure(plt::Plot{GastonBackend})
|
function _create_backend_figure(plt::Plot{GastonBackend})
|
||||||
xsize, ysize = plt.attr[:size]
|
xsize, ysize = plt.attr[:size]
|
||||||
# G.set(termopts="size $xsize,$ysize")
|
G.set(termopts="size $xsize,$ysize")
|
||||||
|
|
||||||
state_handle = G.nexthandle() # for now all the figures will be kept
|
state_handle = G.nexthandle() # for now all the figures will be kept
|
||||||
plt.o = G.newfigure(state_handle)
|
plt.o = G.newfigure(state_handle)
|
||||||
@ -67,15 +65,11 @@ for (mime, term) in (
|
|||||||
"text/plain" => "dumb", # NEED fixing TODO
|
"text/plain" => "dumb", # NEED fixing TODO
|
||||||
)
|
)
|
||||||
@eval function _show(io::IO, ::MIME{Symbol($mime)}, plt::Plot{GastonBackend})
|
@eval function _show(io::IO, ::MIME{Symbol($mime)}, plt::Plot{GastonBackend})
|
||||||
xsize, ysize = plt.attr[:size]
|
|
||||||
termopts = """size $xsize,$ysize"""
|
|
||||||
|
|
||||||
tmpfile = G.tempname() * "." * $term
|
tmpfile = G.tempname() * "." * $term
|
||||||
G.save(
|
G.save(
|
||||||
term=$term,
|
term=$term,
|
||||||
output=tmpfile,
|
output=tmpfile,
|
||||||
handle=plt.o.handle,
|
handle=plt.o.handle,
|
||||||
saveopts=termopts
|
|
||||||
)
|
)
|
||||||
while !isfile(tmpfile) end # avoid race condition with read in next line
|
while !isfile(tmpfile) end # avoid race condition with read in next line
|
||||||
write(io, read(tmpfile))
|
write(io, read(tmpfile))
|
||||||
@ -85,18 +79,17 @@ for (mime, term) in (
|
|||||||
end
|
end
|
||||||
|
|
||||||
function _show(io::IO, mime::MIME{Symbol("image/png")}, plt::Plot{GastonBackend})
|
function _show(io::IO, mime::MIME{Symbol("image/png")}, plt::Plot{GastonBackend})
|
||||||
scaling = plt.attr[:dpi] / GNUPLOT_DPI
|
scaling = plt.attr[:dpi] / Plots.DPI
|
||||||
xsize, ysize = plt.attr[:size] .* scaling
|
|
||||||
|
|
||||||
# Scale all plot elements to match Plots.jl DPI standard
|
# Scale all plot elements to match Plots.jl DPI standard
|
||||||
termopts = "size $xsize,$ysize fontscale $scaling lw $scaling dl $scaling ps $scaling"
|
saveopts = "fontscale $scaling lw $scaling dl $scaling ps $scaling"
|
||||||
|
|
||||||
tmpfile = G.tempname()
|
tmpfile = G.tempname()
|
||||||
G.save(
|
G.save(
|
||||||
term="pngcairo",
|
term="pngcairo",
|
||||||
output=tmpfile,
|
output=tmpfile,
|
||||||
handle=plt.o.handle,
|
handle=plt.o.handle,
|
||||||
# saveopts=termopts
|
saveopts=saveopts
|
||||||
)
|
)
|
||||||
while !isfile(tmpfile) end # avoid race condition with read in next line
|
while !isfile(tmpfile) end # avoid race condition with read in next line
|
||||||
write(io, read(tmpfile))
|
write(io, read(tmpfile))
|
||||||
@ -186,47 +179,47 @@ function gaston_seriesconf!(sp, series::Series)
|
|||||||
clims = get_clims(sp, series)
|
clims = get_clims(sp, series)
|
||||||
if st ∈ (:scatter, :scatter3d)
|
if st ∈ (:scatter, :scatter3d)
|
||||||
pt, ps, lc = gaston_mk_ms_mc(series)
|
pt, ps, lc = gaston_mk_ms_mc(series)
|
||||||
push!(curveconf, """with points pt $pt ps $ps lc $lc""")
|
push!(curveconf, "with points pt $pt ps $ps lc $lc")
|
||||||
elseif st ∈ (:path, :straightline, :path3d)
|
elseif st ∈ (:path, :straightline, :path3d)
|
||||||
lc, dt, lw = gaston_lc_ls_lw(series)
|
lc, dt, lw = gaston_lc_ls_lw(series)
|
||||||
if series[:markershape] == :none # simplepath
|
if series[:markershape] == :none # simplepath
|
||||||
push!(curveconf, """with lines lc $lc dt $dt lw $lw""")
|
push!(curveconf, "with lines lc $lc dt $dt lw $lw")
|
||||||
else
|
else
|
||||||
pt, ps = gaston_mk_ms_mc(series)
|
pt, ps = gaston_mk_ms_mc(series)
|
||||||
push!(curveconf, """with lp lc $lc dt $dt lw $lw pt $pt ps $ps""")
|
push!(curveconf, "with lp lc $lc dt $dt lw $lw pt $pt ps $ps")
|
||||||
end
|
end
|
||||||
elseif st == :shape
|
elseif st == :shape
|
||||||
fc = gaston_color(series[:fillcolor], series[:fillalpha])
|
fc = gaston_color(series[:fillcolor], series[:fillalpha])
|
||||||
fs = "solid"
|
fs = "solid"
|
||||||
lc, _ = gaston_lc_ls_lw(series)
|
lc, _ = gaston_lc_ls_lw(series)
|
||||||
push!(curveconf, """with filledcurves fc $fc fs $fs border lc $lc""")
|
push!(curveconf, "with filledcurves fc $fc fs $fs border lc $lc")
|
||||||
elseif st == :steppre
|
elseif st == :steppre
|
||||||
push!(curveconf, """with steps""")
|
push!(curveconf, "with steps")
|
||||||
elseif st == :steppost
|
elseif st == :steppost
|
||||||
push!(curveconf, """with fsteps""") # Not sure if not the other way
|
push!(curveconf, "with fsteps") # Not sure if not the other way
|
||||||
elseif st ∈ (:contour, :contour3d)
|
elseif st ∈ (:contour, :contour3d)
|
||||||
push!(curveconf, """with lines""")
|
push!(curveconf, "with lines")
|
||||||
if st == :contour
|
if st == :contour
|
||||||
gsp.axesconf *= """\nset view map\nunset surface"""
|
gsp.axesconf *= "\nset view map\nunset surface"
|
||||||
end
|
end
|
||||||
levels = join(map(string, collect(contour_levels(series, clims))), ", ")
|
levels = join(map(string, collect(contour_levels(series, clims))), ", ")
|
||||||
gsp.axesconf *= """\nset contour base\nset cntrparam levels discrete $levels """
|
gsp.axesconf *= "\nset contour base\nset cntrparam levels discrete $levels"
|
||||||
elseif st ∈ (:surface, :heatmap)
|
elseif st ∈ (:surface, :heatmap)
|
||||||
palette = gaston_palette(series[:seriescolor])
|
palette = gaston_palette(series[:seriescolor])
|
||||||
gsp.axesconf *= """\nset palette model RGB defined $palette"""
|
gsp.axesconf *= "\nset palette model RGB defined $palette"
|
||||||
if st == :heatmap
|
if st == :heatmap
|
||||||
gsp.axesconf *= """\nset view map"""
|
gsp.axesconf *= "\nset view map"
|
||||||
end
|
end
|
||||||
push!(curveconf, """with pm3d""")
|
push!(curveconf, "with pm3d")
|
||||||
elseif st == :wireframe
|
elseif st == :wireframe
|
||||||
lc, dt, lw = gaston_lc_ls_lw(series)
|
lc, dt, lw = gaston_lc_ls_lw(series)
|
||||||
push!(curveconf, """with lines lc $lc dt $dt lw $lw""")
|
push!(curveconf, "with lines lc $lc dt $dt lw $lw")
|
||||||
else
|
else
|
||||||
@warn "Gaston: $st is not implemented yet"
|
@warn "Gaston: $st is not implemented yet"
|
||||||
end
|
end
|
||||||
|
|
||||||
# label
|
# label
|
||||||
push!(curveconf, """title "$(series[:label])" """)
|
push!(curveconf, "title \"$(series[:label])\"")
|
||||||
return join(curveconf, " ")
|
return join(curveconf, " ")
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -240,30 +233,30 @@ function gaston_parse_axes_args(plt::Plot{GastonBackend}, sp::Subplot{GastonBack
|
|||||||
for letter in (:x, :y, :z)
|
for letter in (:x, :y, :z)
|
||||||
axis_attr = sp.attr[Symbol(letter, :axis)]
|
axis_attr = sp.attr[Symbol(letter, :axis)]
|
||||||
# label names
|
# label names
|
||||||
push!(axesconf, """set $(letter)label "$(axis_attr[:guide])" """)
|
push!(axesconf, "set $(letter)label \"$(axis_attr[:guide])\" ")
|
||||||
push!(axesconf, """set $(letter)label font "$(axis_attr[:guidefontfamily]), $(axis_attr[:guidefontsize])" """)
|
push!(axesconf, "set $(letter)label font \"$(axis_attr[:guidefontfamily]), $(axis_attr[:guidefontsize])\"")
|
||||||
|
|
||||||
# Handle ticks
|
# Handle ticks
|
||||||
# ticksyle
|
# ticksyle
|
||||||
push!(axesconf, """set $(letter)tics font "$(axis_attr[:tickfontfamily]), $(axis_attr[:tickfontsize])" """)
|
push!(axesconf, "set $(letter)tics font \"$(axis_attr[:tickfontfamily]), $(axis_attr[:tickfontsize])\"")
|
||||||
push!(axesconf, """set $(letter)tics textcolor rgb "#$(hex(axis_attr[:tickfontcolor], :rrggbb))" """)
|
push!(axesconf, "set $(letter)tics textcolor rgb \"#$(hex(axis_attr[:tickfontcolor], :rrggbb))\"")
|
||||||
push!(axesconf, """set $(letter)tics $(axis_attr[:tick_direction])""")
|
push!(axesconf, "set $(letter)tics $(axis_attr[:tick_direction])")
|
||||||
|
|
||||||
mirror = axis_attr[:mirror] ? "mirror" : "nomirror"
|
mirror = axis_attr[:mirror] ? "mirror" : "nomirror"
|
||||||
push!(axesconf, """set $(letter)tics $(mirror) """)
|
push!(axesconf, "set $(letter)tics $(mirror)")
|
||||||
|
|
||||||
logscale = if axis_attr[:scale] == :identity
|
logscale = if axis_attr[:scale] == :identity
|
||||||
"nologscale"
|
"nologscale"
|
||||||
elseif axis_attr[:scale] == :log10
|
elseif axis_attr[:scale] == :log10
|
||||||
"logscale"
|
"logscale"
|
||||||
end
|
end
|
||||||
push!(axesconf, """set $logscale $(letter)""")
|
push!(axesconf, "set $logscale $(letter)")
|
||||||
|
|
||||||
# tick locations
|
# tick locations
|
||||||
if axis_attr[:ticks] != :native
|
if axis_attr[:ticks] != :native
|
||||||
# axis limits
|
# axis limits
|
||||||
from, to = axis_limits(sp, letter)
|
from, to = axis_limits(sp, letter)
|
||||||
push!(axesconf, """set $(letter)range [$from:$to]""")
|
push!(axesconf, "set $(letter)range [$from:$to]")
|
||||||
|
|
||||||
ticks = get_ticks(sp, axis_attr)
|
ticks = get_ticks(sp, axis_attr)
|
||||||
gaston_set_ticks!(axesconf, ticks, letter)
|
gaston_set_ticks!(axesconf, ticks, letter)
|
||||||
@ -274,14 +267,14 @@ function gaston_parse_axes_args(plt::Plot{GastonBackend}, sp::Subplot{GastonBack
|
|||||||
if ratio == :equal
|
if ratio == :equal
|
||||||
ratio = -1
|
ratio = -1
|
||||||
end
|
end
|
||||||
push!(axesconf, """set size ratio $ratio""")
|
push!(axesconf, "set size ratio $ratio")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
gaston_set_legend!(axesconf, sp) # Set legend params
|
gaston_set_legend!(axesconf, sp) # Set legend params
|
||||||
|
|
||||||
if sp[:title] != nothing
|
if sp[:title] != nothing
|
||||||
push!(axesconf, """set title '$(sp[:title])' """)
|
push!(axesconf, "set title '$(sp[:title])'")
|
||||||
push!(axesconf, """set title font '$(sp[:titlefontfamily]), $(sp[:titlefontsize])' """)
|
push!(axesconf, "set title font '$(sp[:titlefontfamily]), $(sp[:titlefontsize])'")
|
||||||
end
|
end
|
||||||
|
|
||||||
return join(axesconf, "\n")
|
return join(axesconf, "\n")
|
||||||
@ -290,7 +283,7 @@ end
|
|||||||
function gaston_set_ticks!(axesconf, ticks, letter)
|
function gaston_set_ticks!(axesconf, ticks, letter)
|
||||||
ticks == :auto && return
|
ticks == :auto && return
|
||||||
if ticks ∈ (:none, nothing, false)
|
if ticks ∈ (:none, nothing, false)
|
||||||
push!(axesconf, """unset $(letter)tics """)
|
push!(axesconf, "unset $(letter)tics")
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -350,7 +343,7 @@ function gaston_set_legend!(axesconf, sp)
|
|||||||
push!(axesconf, "set key opaque")
|
push!(axesconf, "set key opaque")
|
||||||
|
|
||||||
push!(axesconf, "set border back")
|
push!(axesconf, "set border back")
|
||||||
push!(axesconf, """set key font "$(sp[:legendfontfamily]), $(sp[:legendfontsize])" """)
|
push!(axesconf, "set key font \"$(sp[:legendfontfamily]), $(sp[:legendfontsize])\"")
|
||||||
else
|
else
|
||||||
push!(axesconf, "set key off")
|
push!(axesconf, "set key off")
|
||||||
|
|
||||||
@ -403,7 +396,7 @@ end
|
|||||||
function gaston_color(color, alpha=0.)
|
function gaston_color(color, alpha=0.)
|
||||||
col = single_color(color) # in case of gradients
|
col = single_color(color) # in case of gradients
|
||||||
col = alphacolor(col, alpha == nothing ? 0. : alpha) # add a default alpha if non existent
|
col = alphacolor(col, alpha == nothing ? 0. : alpha) # add a default alpha if non existent
|
||||||
return """rgb "#$(hex(col, :aarrggbb))" """
|
return "rgb \"#$(hex(col, :aarrggbb))\""
|
||||||
end
|
end
|
||||||
|
|
||||||
function gaston_linestyle(style)
|
function gaston_linestyle(style)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user