implement fill between functions

This commit is contained in:
Simon Christ 2020-01-03 21:04:47 +01:00
parent f20582e528
commit 7fb1a6a517

View File

@ -92,8 +92,7 @@ function (pgfx_plot::PGFPlotsXPlot)(plt::Plot{PGFPlotsXBackend})
"height" => pl_height > 0 ? string(pl_height * px) : "{}",
"width" => pl_width > 0 ? string(pl_width * px) : "{}",
)
)
)
))
end
for sp in plt.subplots
bb = bbox(sp)
@ -187,10 +186,14 @@ function (pgfx_plot::PGFPlotsXPlot)(plt::Plot{PGFPlotsXBackend})
axis_opt
)
for (series_index, series) in enumerate(series_list(sp))
# give each series a uuid for fillbetween
series_id = uuid4()
_pgfplotsx_series_ids[Symbol("$series_index")] = series_id
opt = series.plotattributes
st = series[:seriestype]
series_opt = PGFPlotsX.Options(
"color" => single_color(opt[:linecolor]),
"name path" => string(series_id)
)
if is3d(series) || st == :heatmap
series_func = PGFPlotsX.Plot3
@ -241,7 +244,9 @@ function (pgfx_plot::PGFPlotsXPlot)(plt::Plot{PGFPlotsXBackend})
end
# add fillrange
if series[:fillrange] !== nothing && !isfilledcontour(series) && series[:ribbon] === nothing
if series[:fillrange] == 0
pgfx_fillrange_series!( axis, series, series_func, i, _cycle(series[:fillrange], rng), rng)
end
if i == 1 && opt[:label] != "" && sp[:legend] != :none && should_add_to_legend(series)
pgfx_filllegend!(series_opt, opt)
end
@ -254,6 +259,13 @@ function (pgfx_plot::PGFPlotsXPlot)(plt::Plot{PGFPlotsXBackend})
coordinates,
)
push!(axis, segment_plot)
# fill between functions
if series[:fillrange] !== nothing && series[:fillrange] != 0
push!(axis, series_func(
merge(pgfx_fillstyle(opt, series_index), PGFPlotsX.Options("forget plot" => nothing)),
"fill between [of=$series_id and $(_pgfplotsx_series_ids[Symbol(string(series[:fillrange]))])]"
))
end
# add ribbons?
ribbon = series[:ribbon]
if ribbon !== nothing
@ -275,11 +287,14 @@ function (pgfx_plot::PGFPlotsXPlot)(plt::Plot{PGFPlotsXBackend})
end
end
# add subplot annotations
anns = sp.attr[:annotations]
for (xi,yi,txt) in anns
pgfx_add_annotation!(axis, xi, yi, txt, pgfx_thickness_scaling(sp))
end
for ann in sp[:annotations]
pgfx_add_annotation!(axis, locate_annotation(sp, ann...)..., pgfx_thickness_scaling(sp))
end
# anns = sp.attr[:annotations]
# for (xi,yi,txt) in anns
# pgfx_add_annotation!(axis, xi, yi, txt, pgfx_thickness_scaling(sp))
# end
end # for series
if ispolar(sp)
axes = the_plot
else
@ -291,9 +306,9 @@ function (pgfx_plot::PGFPlotsXPlot)(plt::Plot{PGFPlotsXBackend})
else
push!(plt.o, the_plot)
end
end
end # for subplots
pgfx_plot.is_created = true
end
end # if
return pgfx_plot
end
## seriestype specifics
@ -439,6 +454,8 @@ const _pgfplotsx_linestyles = KW(
:dashdotdot => "dashdotdotted",
)
const _pgfplotsx_series_ids = KW()
const _pgfplotsx_markers = KW(
:none => "none",
:cross => "+",
@ -525,7 +542,7 @@ function pgfx_framestyle(style::Symbol)
return style
else
default_style = get(_pgfx_framestyle_defaults, style, :axes)
@warn("Framestyle :$style is not (yet) supported by the PGFPlots backend. :$default_style was cosen instead.")
@warn("Framestyle :$style is not (yet) supported by the PGFPlotsX backend. :$default_style was cosen instead.")
default_style
end
end