From f53b070d79d295c42929ec3e2f174c10d7cbf81c Mon Sep 17 00:00:00 2001 From: Simon Christ Date: Mon, 25 Nov 2019 12:38:54 +0100 Subject: [PATCH] add background_color_outside --- src/backends/pgfplotsx.jl | 32 +++++++++++++++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-) diff --git a/src/backends/pgfplotsx.jl b/src/backends/pgfplotsx.jl index 52fbe121..fd276505 100644 --- a/src/backends/pgfplotsx.jl +++ b/src/backends/pgfplotsx.jl @@ -5,7 +5,26 @@ Base.@kwdef mutable struct PGFPlotsXPlot the_plot::PGFPlotsX.TikzDocument = PGFPlotsX.TikzDocument() function PGFPlotsXPlot(is_created, was_shown, the_plot) pgfx_plot = new(is_created, was_shown, the_plot) + # tikz libraries PGFPlotsX.push_preamble!(pgfx_plot.the_plot, "\\usetikzlibrary{arrows.meta}") + PGFPlotsX.push_preamble!(pgfx_plot.the_plot, "\\usetikzlibrary{backgrounds}") + PGFPlotsX.push_preamble!(pgfx_plot.the_plot, + """ + \\pgfkeys{/tikz/.cd, + background color/.initial=white, + background color/.get=\\backcol, + background color/.store in=\\backcol, + } + \\tikzset{background rectangle/.style={ + fill=\\backcol, + }, + use background/.style={ + show background rectangle + } + } + """ + ) + # pgfplots libraries PGFPlotsX.push_preamble!(pgfx_plot.the_plot, "\\usepgfplotslibrary{patchplots}") pgfx_plot end @@ -41,8 +60,19 @@ end function (pgfx_plot::PGFPlotsXPlot)(plt::Plot{PGFPlotsXBackend}) if !pgfx_plot.is_created + the_plot = PGFPlotsX.TikzPicture(PGFPlotsX.Options()) cols, rows = size(plt.layout.grid) - the_plot = PGFPlotsX.TikzPicture() + bgc = plt.attr[:background_color_outside] + if bgc isa Colors.Colorant + cstr = plot_color(bgc) + a = alpha(cstr) + push!(the_plot.options, + "draw opacity" => a, + "background color" => cstr, + "use background" => nothing, + ) + end + # the combination of groupplot and polaraxis is broken in pgfplots if !any( sp -> ispolar(sp), plt.subplots ) pl_height, pl_width = plt.attr[:size]