From 7b31e5f9b83e9f5e4a2fe0032fc355c2f5bce2f0 Mon Sep 17 00:00:00 2001 From: Simon Christ Date: Fri, 6 Dec 2019 15:04:22 +0100 Subject: [PATCH] fix ribbon legend --- src/backends/pgfplotsx.jl | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/src/backends/pgfplotsx.jl b/src/backends/pgfplotsx.jl index 48ea317a..a1f5d506 100644 --- a/src/backends/pgfplotsx.jl +++ b/src/backends/pgfplotsx.jl @@ -240,17 +240,12 @@ function (pgfx_plot::PGFPlotsXPlot)(plt::Plot{PGFPlotsXBackend}) # add fillrange if series[:fillrange] !== nothing && !isfilledcontour(series) && series[:ribbon] === nothing pgfx_fillrange_series!( axis, series, series_func, i, _cycle(series[:fillrange], rng), rng) - # add to legend? if i == 1 && opt[:label] != "" && sp[:legend] != :none && should_add_to_legend(series) - io = IOBuffer() - PGFPlotsX.print_tex(io, pgfx_fillstyle(opt, i)) - style = strip(String(take!(io)),['[',']', ' ']) - push!( segment_opt, "legend image code/.code" => """{ - \\draw[$style] (0cm,-0.1cm) rectangle (0.6cm,0.1cm); - }""" ) + pgfx_filllegend!(series_opt, opt) end end # series + # coordinates = pgfx_series_coordinates!( sp, series, segment_opt, opt, rng ) segment_plot = series_func( merge(series_opt, segment_opt), @@ -264,7 +259,11 @@ function (pgfx_plot::PGFPlotsXPlot)(plt::Plot{PGFPlotsXBackend}) end # add to legend? if i == 1 && opt[:label] != "" && sp[:legend] != :none && should_add_to_legend(series) - legend = PGFPlotsX.LegendEntry(PGFPlotsX.Options(), opt[:label], true) + leg_opt = PGFPlotsX.Options() + if ribbon !== nothing + pgfx_filllegend!(axis.contents[end-3].options, opt) + end + legend = PGFPlotsX.LegendEntry(leg_opt, opt[:label], false) push!( axis, legend ) end # add series annotations @@ -499,6 +498,15 @@ function pgfx_arrow( arr::Arrow ) return "every arrow/.append style={$(components)}" end +function pgfx_filllegend!( series_opt, opt ) + io = IOBuffer() + PGFPlotsX.print_tex(io, pgfx_fillstyle(opt)) + style = strip(String(take!(io)),['[',']', ' ']) + push!( series_opt, "legend image code/.code" => """{ + \\draw[$style] (0cm,-0.1cm) rectangle (0.6cm,0.1cm); + }""" ) +end + function pgfx_colormap(grad::ColorGradient) join(map(grad.colors) do c @sprintf("rgb=(%.8f,%.8f,%.8f)", red(c), green(c), blue(c))