add ribbons
This commit is contained in:
parent
f53b070d79
commit
acf4cb4e5b
@ -26,6 +26,7 @@ Base.@kwdef mutable struct PGFPlotsXPlot
|
||||
)
|
||||
# pgfplots libraries
|
||||
PGFPlotsX.push_preamble!(pgfx_plot.the_plot, "\\usepgfplotslibrary{patchplots}")
|
||||
PGFPlotsX.push_preamble!(pgfx_plot.the_plot, "\\usepgfplotslibrary{fillbetween}")
|
||||
pgfx_plot
|
||||
end
|
||||
end
|
||||
@ -218,16 +219,22 @@ function (pgfx_plot::PGFPlotsXPlot)(plt::Plot{PGFPlotsXBackend})
|
||||
segment_opt = merge( segment_opt, pgfx_marker(opt, i) )
|
||||
end
|
||||
if st == :shape ||
|
||||
(series[:fillrange] !== nothing && !isfilledcontour(series))
|
||||
(series[:fillrange] !== nothing && !isfilledcontour(series)) &&
|
||||
series[:ribbon] === nothing
|
||||
segment_opt = merge( segment_opt, pgfx_fillstyle(opt, i) )
|
||||
end
|
||||
coordinates = pgfx_series_coordinates!( sp, series, segment_opt, opt, rng )
|
||||
segment_plot = series_func(
|
||||
merge(series_opt, segment_opt),
|
||||
coordinates,
|
||||
(series[:fillrange] !== nothing && !isfilledcontour(series)) ? "\\closedcycle" : "{}"
|
||||
(series[:fillrange] !== nothing && !isfilledcontour(series) && series[:ribbon] === nothing) ? "\\closedcycle" : "{}"
|
||||
)
|
||||
push!(axis, segment_plot)
|
||||
# add ribbons?
|
||||
ribbon = series[:ribbon]
|
||||
if ribbon !== nothing
|
||||
pgfx_add_ribbons!( axis, series, segment_plot, series_func, series_index )
|
||||
end
|
||||
# add to legend?
|
||||
if i == 1 && opt[:label] != "" && sp[:legend] != :none && should_add_to_legend(series)
|
||||
push!( axis, PGFPlotsX.LegendEntry( opt[:label] )
|
||||
@ -570,6 +577,45 @@ function pgfx_add_annotation!(o, x, y, val, thickness_scaling = 1)
|
||||
"{$(val.str).};"
|
||||
])
|
||||
end
|
||||
|
||||
function pgfx_add_ribbons!( axis, series, segment_plot, series_func, series_index )
|
||||
ribbon = series[:ribbon]
|
||||
opt = series.plotattributes
|
||||
ribbon_n = length(opt[:y]) ÷ length(ribbon)
|
||||
ribbon_y = repeat(ribbon, outer = ribbon_n)
|
||||
# upper ribbon
|
||||
ribbon_name_plus = "plots_rib_p$series_index"
|
||||
ribbon_opt_plus = merge(segment_plot.options, PGFPlotsX.Options(
|
||||
"name path" => ribbon_name_plus,
|
||||
"color" => opt[:fillcolor],
|
||||
"draw opacity" => opt[:fillalpha]
|
||||
))
|
||||
coordinates_plus = PGFPlotsX.Coordinates(opt[:x], opt[:y] + ribbon_y)
|
||||
ribbon_plot_plus = series_func(
|
||||
ribbon_opt_plus,
|
||||
coordinates_plus
|
||||
)
|
||||
push!(axis, ribbon_plot_plus)
|
||||
# lower ribbon
|
||||
ribbon_name_minus = "plots_rib_m$series_index"
|
||||
ribbon_opt_minus = merge(segment_plot.options, PGFPlotsX.Options(
|
||||
"name path" => ribbon_name_minus,
|
||||
"color" => opt[:fillcolor],
|
||||
"draw opacity" => opt[:fillalpha]
|
||||
))
|
||||
coordinates_plus = PGFPlotsX.Coordinates(opt[:x], opt[:y] - ribbon_y)
|
||||
ribbon_plot_plus = series_func(
|
||||
ribbon_opt_minus,
|
||||
coordinates_plus
|
||||
)
|
||||
push!(axis, ribbon_plot_plus)
|
||||
# fill
|
||||
push!(axis, series_func(
|
||||
pgfx_fillstyle(opt, series_index),
|
||||
"fill between [of=$(ribbon_name_plus) and $(ribbon_name_minus)]"
|
||||
))
|
||||
return axis
|
||||
end
|
||||
# --------------------------------------------------------------------------------------
|
||||
function pgfx_axis!(opt::PGFPlotsX.Options, sp::Subplot, letter)
|
||||
axis = sp[Symbol(letter,:axis)]
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user