implement fillrange, vector arguments, line_z and fill_z for pgfplots
This commit is contained in:
parent
c34e1d3c19
commit
55e9c8c9eb
@ -1530,7 +1530,7 @@ function _add_defaults!(d::KW, plt::Plot, sp::Subplot, commandIndex::Int)
|
|||||||
d[:markerstrokecolor] = if d[:markerstrokecolor] == :match
|
d[:markerstrokecolor] = if d[:markerstrokecolor] == :match
|
||||||
plot_color(sp[:foreground_color_subplot], d[:markerstrokealpha])
|
plot_color(sp[:foreground_color_subplot], d[:markerstrokealpha])
|
||||||
else
|
else
|
||||||
getSeriesRGBColor(d[:markerstrokecolor], d[:markerstrokealpha], sp, plotIndex)
|
getSeriesRGBColor(plot_color(d[:markerstrokecolor], d[:markerstrokealpha]), sp, plotIndex)
|
||||||
end
|
end
|
||||||
|
|
||||||
# if marker_z, fill_z or line_z are set, ensure we have a gradient
|
# if marker_z, fill_z or line_z are set, ensure we have a gradient
|
||||||
|
|||||||
@ -148,33 +148,47 @@ function pgf_colormap(grad::ColorGradient)
|
|||||||
end,", ")
|
end,", ")
|
||||||
end
|
end
|
||||||
|
|
||||||
function pgf_fillstyle(d::KW)
|
function pgf_fillstyle(d, i = 1)
|
||||||
cstr,a = pgf_color(d[:fillcolor])
|
cstr,a = pgf_color(get_fillcolor(d, i))
|
||||||
|
fa = get_fillalpha(d, i)
|
||||||
|
if fa != nothing
|
||||||
|
a = fa
|
||||||
|
end
|
||||||
"fill = $cstr, fill opacity=$a"
|
"fill = $cstr, fill opacity=$a"
|
||||||
end
|
end
|
||||||
|
|
||||||
function pgf_linestyle(d::KW)
|
function pgf_linestyle(d, i = 1)
|
||||||
cstr,a = pgf_color(d[:linecolor])
|
cstr,a = pgf_color(get_linecolor(d, i))
|
||||||
|
la = get_linealpha(d, i)
|
||||||
|
if la != nothing
|
||||||
|
a = la
|
||||||
|
end
|
||||||
"""
|
"""
|
||||||
color = $cstr,
|
color = $cstr,
|
||||||
draw opacity=$a,
|
draw opacity=$a,
|
||||||
line width=$(d[:linewidth]),
|
line width=$(get_linewidth(d, i)),
|
||||||
$(get(_pgfplots_linestyles, d[:linestyle], "solid"))"""
|
$(get(_pgfplots_linestyles, get_linestyle(d, i), "solid"))"""
|
||||||
end
|
end
|
||||||
|
|
||||||
function pgf_marker(d::KW)
|
function pgf_marker(d, i = 1)
|
||||||
shape = d[:markershape]
|
shape = _cycle(d[:markershape], i)
|
||||||
cstr, a = pgf_color(d[:markercolor])
|
cstr, a = pgf_color(_cycle(d[:markercolor], i))
|
||||||
cstr_stroke, a_stroke = pgf_color(d[:markerstrokecolor])
|
if d[:markeralpha] != nothing
|
||||||
|
a = _cycle(d[:markeralpha], i)
|
||||||
|
end
|
||||||
|
cstr_stroke, a_stroke = pgf_color(_cycle(d[:markerstrokecolor], i))
|
||||||
|
if d[:markerstrokealpha] != nothing
|
||||||
|
a_stroke = _cycle(d[:markerstrokealpha], i)
|
||||||
|
end
|
||||||
"""
|
"""
|
||||||
mark = $(get(_pgfplots_markers, shape, "*")),
|
mark = $(get(_pgfplots_markers, shape, "*")),
|
||||||
mark size = $(0.5 * d[:markersize]),
|
mark size = $(0.5 * _cycle(d[:markersize], i)),
|
||||||
mark options = {
|
mark options = {
|
||||||
color = $cstr_stroke, draw opacity = $a_stroke,
|
color = $cstr_stroke, draw opacity = $a_stroke,
|
||||||
fill = $cstr, fill opacity = $a,
|
fill = $cstr, fill opacity = $a,
|
||||||
line width = $(d[:markerstrokewidth]),
|
line width = $(_cycle(d[:markerstrokewidth], i)),
|
||||||
rotate = $(shape == :dtriangle ? 180 : 0),
|
rotate = $(shape == :dtriangle ? 180 : 0),
|
||||||
$(get(_pgfplots_linestyles, d[:markerstrokestyle], "solid"))
|
$(get(_pgfplots_linestyles, _cycle(d[:markerstrokestyle], i), "solid"))
|
||||||
}"""
|
}"""
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -196,27 +210,10 @@ end
|
|||||||
function pgf_series(sp::Subplot, series::Series)
|
function pgf_series(sp::Subplot, series::Series)
|
||||||
d = series.d
|
d = series.d
|
||||||
st = d[:seriestype]
|
st = d[:seriestype]
|
||||||
style = []
|
series_collection = PGFPlots.Plot[]
|
||||||
kw = KW()
|
|
||||||
push!(style, pgf_linestyle(d))
|
|
||||||
push!(style, pgf_marker(d))
|
|
||||||
|
|
||||||
if d[:fillrange] != nothing || st in (:shape,)
|
|
||||||
push!(style, pgf_fillstyle(d))
|
|
||||||
end
|
|
||||||
|
|
||||||
# add to legend?
|
|
||||||
if sp[:legend] != :none && should_add_to_legend(series)
|
|
||||||
kw[:legendentry] = d[:label]
|
|
||||||
if st == :shape || d[:fillrange] != nothing
|
|
||||||
push!(style, "area legend")
|
|
||||||
end
|
|
||||||
else
|
|
||||||
push!(style, "forget plot")
|
|
||||||
end
|
|
||||||
|
|
||||||
# function args
|
# function args
|
||||||
args = if st == :contour
|
args = if st == :contour
|
||||||
d[:z].surf, d[:x], d[:y]
|
d[:z].surf, d[:x], d[:y]
|
||||||
elseif is3d(st)
|
elseif is3d(st)
|
||||||
d[:x], d[:y], d[:z]
|
d[:x], d[:y], d[:z]
|
||||||
@ -241,31 +238,102 @@ function pgf_series(sp::Subplot, series::Series)
|
|||||||
else
|
else
|
||||||
a
|
a
|
||||||
end, args)
|
end, args)
|
||||||
# for (i,a) in enumerate(args)
|
|
||||||
# if typeof(a) <: AbstractVector && typeof(a) != Vector
|
|
||||||
# args[i] = collect(a)
|
|
||||||
# end
|
|
||||||
# end
|
|
||||||
|
|
||||||
# include additional style, then add to the kw
|
if st in (:contour, :histogram2d)
|
||||||
|
style = []
|
||||||
|
kw = KW()
|
||||||
|
push!(style, pgf_linestyle(d))
|
||||||
|
push!(style, pgf_marker(d))
|
||||||
|
push!(style, "forget plot")
|
||||||
|
|
||||||
|
kw[:style] = join(style, ',')
|
||||||
|
func = if st == :histogram2d
|
||||||
|
PGFPlots.Histogram2
|
||||||
|
else
|
||||||
|
PGFPlots.Contour
|
||||||
|
end
|
||||||
|
push!(series_collection, func(args...; kw...))
|
||||||
|
|
||||||
|
else
|
||||||
|
# series segments
|
||||||
|
segments = iter_segments(series)
|
||||||
|
for (i, rng) in enumerate(segments)
|
||||||
|
style = []
|
||||||
|
kw = KW()
|
||||||
|
push!(style, pgf_linestyle(d, i))
|
||||||
|
push!(style, pgf_marker(d, i))
|
||||||
|
|
||||||
|
if st == :shape
|
||||||
|
push!(style, pgf_fillstyle(d, i))
|
||||||
|
end
|
||||||
|
|
||||||
|
# add to legend?
|
||||||
|
if i == 1 && sp[:legend] != :none && should_add_to_legend(series)
|
||||||
|
kw[:legendentry] = d[:label]
|
||||||
|
if st == :shape # || d[:fillrange] != nothing
|
||||||
|
push!(style, "area legend")
|
||||||
|
end
|
||||||
|
else
|
||||||
|
push!(style, "forget plot")
|
||||||
|
end
|
||||||
|
|
||||||
|
seg_args = (arg[rng] for arg in args)
|
||||||
|
|
||||||
|
# include additional style, then add to the kw
|
||||||
|
if haskey(_pgf_series_extrastyle, st)
|
||||||
|
push!(style, _pgf_series_extrastyle[st])
|
||||||
|
end
|
||||||
|
kw[:style] = join(style, ',')
|
||||||
|
|
||||||
|
# add fillrange
|
||||||
|
if series[:fillrange] != nothing && st != :shape
|
||||||
|
push!(series_collection, pgf_fillrange_series(series, i, _cycle(series[:fillrange], rng), seg_args...))
|
||||||
|
end
|
||||||
|
|
||||||
|
# build/return the series object
|
||||||
|
func = if st == :path3d
|
||||||
|
PGFPlots.Linear3
|
||||||
|
elseif st == :scatter
|
||||||
|
PGFPlots.Scatter
|
||||||
|
else
|
||||||
|
PGFPlots.Linear
|
||||||
|
end
|
||||||
|
push!(series_collection, func(seg_args...; kw...))
|
||||||
|
end
|
||||||
|
end
|
||||||
|
series_collection
|
||||||
|
end
|
||||||
|
|
||||||
|
function pgf_fillrange_series(series, i, fillrange, args...)
|
||||||
|
st = series[:seriestype]
|
||||||
|
style = []
|
||||||
|
kw = KW()
|
||||||
|
push!(style, "line width = 0")
|
||||||
|
push!(style, "draw opacity = 0")
|
||||||
|
push!(style, pgf_fillstyle(series, i))
|
||||||
|
push!(style, pgf_marker(series, i))
|
||||||
|
push!(style, "forget plot")
|
||||||
if haskey(_pgf_series_extrastyle, st)
|
if haskey(_pgf_series_extrastyle, st)
|
||||||
push!(style, _pgf_series_extrastyle[st])
|
push!(style, _pgf_series_extrastyle[st])
|
||||||
end
|
end
|
||||||
kw[:style] = join(style, ',')
|
kw[:style] = join(style, ',')
|
||||||
|
func = is3d(series) ? PGFPlots.Linear3 : PGFPlots.Linear
|
||||||
|
return func(pgf_fillrange_args(fillrange, args...)...; kw...)
|
||||||
|
end
|
||||||
|
|
||||||
# build/return the series object
|
function pgf_fillrange_args(fillrange, x, y)
|
||||||
func = if st == :path3d
|
n = length(x)
|
||||||
PGFPlots.Linear3
|
x_fill = [x; x[n:-1:1]; x[1]]
|
||||||
elseif st == :scatter
|
y_fill = [y; _cycle(fillrange, n:-1:1); y[1]]
|
||||||
PGFPlots.Scatter
|
return x_fill, y_fill
|
||||||
elseif st == :histogram2d
|
end
|
||||||
PGFPlots.Histogram2
|
|
||||||
elseif st == :contour
|
function pgf_fillrange_args(fillrange, x, y, z)
|
||||||
PGFPlots.Contour
|
n = length(x)
|
||||||
else
|
x_fill = [x; x[n:-1:1]; x[1]]
|
||||||
PGFPlots.Linear
|
y_fill = [y; y[n:-1:1]; x[1]]
|
||||||
end
|
z_fill = [z; _cycle(fillrange, n:-1:1); z[1]]
|
||||||
func(args...; kw...)
|
return x_fill, y_fill, z_fill
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
@ -438,7 +506,7 @@ function _update_plot_object(plt::Plot{PGFPlotsBackend})
|
|||||||
# As it is likely that all series within the same axis use the same
|
# As it is likely that all series within the same axis use the same
|
||||||
# colormap this should not cause any problem.
|
# colormap this should not cause any problem.
|
||||||
for series in series_list(sp)
|
for series in series_list(sp)
|
||||||
for col in (:markercolor, :fillcolor)
|
for col in (:markercolor, :fillcolor, :linecolor)
|
||||||
if typeof(series.d[col]) == ColorGradient
|
if typeof(series.d[col]) == ColorGradient
|
||||||
push!(style,"colormap={plots}{$(pgf_colormap(series.d[col]))}")
|
push!(style,"colormap={plots}{$(pgf_colormap(series.d[col]))}")
|
||||||
|
|
||||||
@ -458,7 +526,7 @@ function _update_plot_object(plt::Plot{PGFPlotsBackend})
|
|||||||
|
|
||||||
# add the series object to the PGFPlots.Axis
|
# add the series object to the PGFPlots.Axis
|
||||||
for series in series_list(sp)
|
for series in series_list(sp)
|
||||||
push!(o, pgf_series(sp, series))
|
push!.(o, pgf_series(sp, series))
|
||||||
|
|
||||||
# add series annotations
|
# add series annotations
|
||||||
anns = series[:series_annotations]
|
anns = series[:series_annotations]
|
||||||
|
|||||||
12
src/utils.jl
12
src/utils.jl
@ -616,7 +616,7 @@ function hascolorbar(sp::Subplot)
|
|||||||
hascbar
|
hascbar
|
||||||
end
|
end
|
||||||
|
|
||||||
function get_linecolor(series::Series, i::Int = 1)
|
function get_linecolor(series, i::Int = 1)
|
||||||
lc = series[:linecolor]
|
lc = series[:linecolor]
|
||||||
lz = series[:line_z]
|
lz = series[:line_z]
|
||||||
if lz == nothing
|
if lz == nothing
|
||||||
@ -628,19 +628,19 @@ function get_linecolor(series::Series, i::Int = 1)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
function get_linealpha(series::Series, i::Int = 1)
|
function get_linealpha(series, i::Int = 1)
|
||||||
_cycle(series[:linealpha], i)
|
_cycle(series[:linealpha], i)
|
||||||
end
|
end
|
||||||
|
|
||||||
function get_linewidth(series::Series, i::Int = 1)
|
function get_linewidth(series, i::Int = 1)
|
||||||
_cycle(series[:linewidth], i)
|
_cycle(series[:linewidth], i)
|
||||||
end
|
end
|
||||||
|
|
||||||
function get_linestyle(series::Series, i::Int = 1)
|
function get_linestyle(series, i::Int = 1)
|
||||||
_cycle(series[:linestyle], i)
|
_cycle(series[:linestyle], i)
|
||||||
end
|
end
|
||||||
|
|
||||||
function get_fillcolor(series::Series, i::Int = 1)
|
function get_fillcolor(series, i::Int = 1)
|
||||||
fc = series[:fillcolor]
|
fc = series[:fillcolor]
|
||||||
fz = series[:fill_z]
|
fz = series[:fill_z]
|
||||||
lz = series[:line_z]
|
lz = series[:line_z]
|
||||||
@ -657,7 +657,7 @@ function get_fillcolor(series::Series, i::Int = 1)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
function get_fillalpha(series::Series, i::Int = 1)
|
function get_fillalpha(series, i::Int = 1)
|
||||||
_cycle(series[:fillalpha], i)
|
_cycle(series[:fillalpha], i)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user