From 78f7db138fdbe2b423beb1276c72b759f4b93816 Mon Sep 17 00:00:00 2001 From: Simon Christ Date: Tue, 4 May 2021 20:54:11 +0200 Subject: [PATCH] add legend stylings (#3470) * add legend stylings * fix center and default case --- src/backends/pgfplotsx.jl | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/src/backends/pgfplotsx.jl b/src/backends/pgfplotsx.jl index 98dfdfc1..b6cb96c1 100644 --- a/src/backends/pgfplotsx.jl +++ b/src/backends/pgfplotsx.jl @@ -183,8 +183,11 @@ function (pgfx_plot::PGFPlotsXPlot)(plt::Plot{PGFPlotsXBackend}) nothing sp_height > 0 * mm ? push!(axis_opt, "height" => string(axis_height)) : nothing - # legend position - push!(axis_opt["legend style"], pgfx_get_legend_pos(sp[:legend])...) + # legend position / formatting + push!(axis_opt["legend style"], + pgfx_get_legend_pos(sp[:legend])... + ) + merge!(axis_opt["legend style"], pgfx_get_legend_style(sp)) for letter in (:x, :y, :z) if letter != :z || RecipesPipeline.is3d(sp) pgfx_axis!(axis_opt, sp, letter) @@ -799,6 +802,14 @@ function pgfx_get_legend_pos(v::Tuple{S,Symbol}) where S <: Real return ("at"=>"$(string(legend_pos_from_angle(v[1],rect...)))", "anchor"=>anchor) end +function pgfx_get_legend_style(sp) + legfont = legendfont(sp) + PGFPlotsX.Options( + "cells" => PGFPlotsX.Options("anchor" => get((left = "west", right = "east", hcenter = "center"), legfont.halign, "west")), + "font" => pgfx_font(legfont.pointsize, pgfx_thickness_scaling(sp)) + ) +end + pgfx_get_colorbar_pos(s) = get((left = " left", bottom = " horizontal", top = " horizontal"), s, "") pgfx_get_colorbar_pos(b::Bool) = ""