From d5788fc1e7ebd5dc3b84fad31b4bbf692119fd51 Mon Sep 17 00:00:00 2001 From: Simon Christ Date: Fri, 6 Mar 2020 12:12:01 +0100 Subject: [PATCH] Allow legend for surfaces (#2439) * allow legends for surfaces * remove unnecessary checks * redo necessary checks --- src/backends/pgfplotsx.jl | 27 ++++++++++++++++++++++----- 1 file changed, 22 insertions(+), 5 deletions(-) diff --git a/src/backends/pgfplotsx.jl b/src/backends/pgfplotsx.jl index 47ef6f82..c3204196 100644 --- a/src/backends/pgfplotsx.jl +++ b/src/backends/pgfplotsx.jl @@ -292,7 +292,7 @@ function (pgfx_plot::PGFPlotsXPlot)(plt::Plot{PGFPlotsXBackend}) if sf isa Number || sf isa AVec pgfx_fillrange_series!( axis, series, series_func, i, _cycle(sf, rng), rng) end - if i == 1 && opt[:label] != "" && sp[:legend] != :none && should_add_to_legend(series) + if i == 1 && sp[:legend] != :none && pgfx_should_add_to_legend(series) pgfx_filllegend!(series_opt, opt) end end @@ -330,10 +330,8 @@ function (pgfx_plot::PGFPlotsXPlot)(plt::Plot{PGFPlotsXBackend}) series_index, ) end - # add to legend? - if i == 1 && - opt[:label] != "" && - sp[:legend] != :none && should_add_to_legend(series) + # add to legend? + if i == 1 && sp[:legend] != :none && pgfx_should_add_to_legend(series) leg_opt = PGFPlotsX.Options() if ribbon !== nothing pgfx_filllegend!(axis.contents[end-3].options, opt) @@ -678,6 +676,25 @@ function pgfx_font(fontsize, thickness_scaling = 1, font = "\\selectfont") return string("{\\fontsize{", fs, " pt}{", 1.3fs, " pt}", font, "}") end +function pgfx_should_add_to_legend(series::Series) + series.plotattributes[:primary] && series.plotattributes[:label] != "" && + !( + series.plotattributes[:seriestype] in ( + :hexbin, + :bins2d, + :histogram2d, + :hline, + :vline, + :contour, + :contourf, + :contour3d, + :heatmap, + :pie, + :image, + ) + ) +end + function pgfx_marker(plotattributes, i = 1) shape = _cycle(plotattributes[:markershape], i) cstr = plot_color(