From 0a6e691222344995cc46fde847b8f243e82d1ca8 Mon Sep 17 00:00:00 2001 From: Daniel Schwabeneder Date: Wed, 13 May 2020 15:15:42 +0200 Subject: [PATCH 1/5] allow disabling the colorbar in pgfplotsx --- src/backends/pgfplotsx.jl | 57 ++++++++++++++++++++------------------- 1 file changed, 29 insertions(+), 28 deletions(-) diff --git a/src/backends/pgfplotsx.jl b/src/backends/pgfplotsx.jl index 2f2e2d1e..5bb60754 100644 --- a/src/backends/pgfplotsx.jl +++ b/src/backends/pgfplotsx.jl @@ -206,41 +206,42 @@ function (pgfx_plot::PGFPlotsXPlot)(plt::Plot{PGFPlotsXBackend}) # As it is likely that all series within the same axis use the same # colormap this should not cause any problem. for series in series_list(sp) - if hascolorbar(series) - cg = get_colorgradient(series) - cm = pgfx_colormap(get_colorgradient(series)) - PGFPlotsX.push_preamble!( - pgfx_plot.the_plot, - """\\pgfplotsset{ - colormap={plots$(sp.attr[:subplot_index])}{$cm}, - }""", - ) + if hascolorbar(series) + cg = get_colorgradient(series) + cm = pgfx_colormap(get_colorgradient(series)) + PGFPlotsX.push_preamble!( + pgfx_plot.the_plot, + """\\pgfplotsset{ + colormap={plots$(sp.attr[:subplot_index])}{$cm}, + }""", + ) + if sp[:colorbar] == true + push!(axis_opt, "colorbar" => nothing) + end + push!(axis_opt, "colormap name" => "plots$(sp.attr[:subplot_index])") + if cg isa PlotUtils.CategoricalColorGradient push!( axis_opt, - "colorbar" => nothing, - "colormap name" => "plots$(sp.attr[:subplot_index])", + "colormap access" => "piecewise const", + "colorbar sampled" => nothing, ) - if cg isa PlotUtils.CategoricalColorGradient - push!( - axis_opt, - "colormap access" => "piecewise const", - "colorbar sampled" => nothing, - ) - end - # goto is needed to break out of col and series for - @goto colorbar_end end + # goto is needed to break out of col and series for + @goto colorbar_end + end end @label colorbar_end - push!( - axis_opt, - "colorbar style" => PGFPlotsX.Options( - "title" => sp[:colorbar_title], - ), - "point meta max" => get_clims(sp)[2], - "point meta min" => get_clims(sp)[1], - ) + if sp[:colorbar] == true + push!( + axis_opt, + "colorbar style" => PGFPlotsX.Options( + "title" => sp[:colorbar_title], + ), + "point meta max" => get_clims(sp)[2], + "point meta min" => get_clims(sp)[1], + ) + end if RecipesPipeline.is3d(sp) azim, elev = sp[:camera] push!(axis_opt, "view" => (azim, elev)) From 7eb8f2452c8ba550306051cfe5eaea75a7622fbf Mon Sep 17 00:00:00 2001 From: Daniel Schwabeneder Date: Wed, 13 May 2020 16:45:16 +0200 Subject: [PATCH 2/5] colorbar positions :top, :bottom and :left and colorbar tickfont fixes --- src/backends/pgfplotsx.jl | 52 ++++++++++++++++++++++++++------------- 1 file changed, 35 insertions(+), 17 deletions(-) diff --git a/src/backends/pgfplotsx.jl b/src/backends/pgfplotsx.jl index 5bb60754..1527b2c5 100644 --- a/src/backends/pgfplotsx.jl +++ b/src/backends/pgfplotsx.jl @@ -215,9 +215,6 @@ function (pgfx_plot::PGFPlotsXPlot)(plt::Plot{PGFPlotsXBackend}) colormap={plots$(sp.attr[:subplot_index])}{$cm}, }""", ) - if sp[:colorbar] == true - push!(axis_opt, "colorbar" => nothing) - end push!(axis_opt, "colormap name" => "plots$(sp.attr[:subplot_index])") if cg isa PlotUtils.CategoricalColorGradient push!( @@ -232,12 +229,25 @@ function (pgfx_plot::PGFPlotsXPlot)(plt::Plot{PGFPlotsXBackend}) end @label colorbar_end - if sp[:colorbar] == true + if hascolorbar(sp) + xcstr = plot_color(sp[:xaxis][:tickfontcolor]) + ycstr = plot_color(sp[:yaxis][:tickfontcolor]) + colorbar_style = PGFPlotsX.Options( + "title" => sp[:colorbar_title], + "xticklabel style" => pgfx_get_ticklabel_style(sp, sp[:xaxis]), + "yticklabel style" => pgfx_get_ticklabel_style(sp, sp[:yaxis]), + ) + if sp[:colorbar] === :top + push!(colorbar_style, + "at" => string((0.5, 1.05)), + "anchor" => "south", + "xticklabel pos" => "upper", + ) + end push!( axis_opt, - "colorbar style" => PGFPlotsX.Options( - "title" => sp[:colorbar_title], - ), + string("colorbar", pgfx_get_colorbar_pos(sp[:colorbar])) => nothing, + "colorbar style" => colorbar_style, "point meta max" => get_clims(sp)[2], "point meta min" => get_clims(sp)[1], ) @@ -670,6 +680,22 @@ pgfx_get_legend_pos(k) = get( ("at" => string((1.02, 1)), "anchor" => "north west"), ) +pgfx_get_colorbar_pos(s) = + get((left = " left", bottom = " horizontal", top = " horizontal"), s, "") +pgfx_get_colorbar_pos(b::Bool) = "" + +function pgfx_get_ticklabel_style(sp, axis) + cstr = plot_color(axis[:tickfontcolor]) + return PGFPlotsX.Options( + "font" => pgfx_font( + axis[:tickfontsize], pgfx_thickness_scaling(sp) + ), + "color" => cstr, + "draw opacity" => alpha(cstr), + "rotate" => axis[:tickfontrotation], + ) +end + ## -------------------------------------------------------------------------------------- # Generates a colormap for pgfplots based on a ColorGradient pgfx_arrow(::Nothing) = "every arrow/.append style={-}" @@ -1106,17 +1132,8 @@ function pgfx_axis!(opt::PGFPlotsX.Options, sp::Subplot, letter) string(letter, "tick align") => (axis[:tick_direction] == :out ? "outside" : "inside"), ) - cstr = plot_color(axis[:tickfontcolor]) - α = alpha(cstr) push!( - opt, - string(letter, "ticklabel style") => PGFPlotsX.Options( - "font" => - pgfx_font(axis[:tickfontsize], pgfx_thickness_scaling(sp)), - "color" => cstr, - "draw opacity" => α, - "rotate" => axis[:tickfontrotation], - ), + opt, string(letter, "ticklabel style") => pgfx_get_ticklabel_style(sp, axis) ) push!( opt, @@ -1204,6 +1221,7 @@ function pgfx_axis!(opt::PGFPlotsX.Options, sp::Subplot, letter) ) end end + # -------------------------------------------------------------------------------------- # display calls this and then _display, its called 3 times for plot(1:5) # Set the (left, top, right, bottom) minimum padding around the plot area From 9d1ede016bf0f7e9451bba2c82dd90620605e4fb Mon Sep 17 00:00:00 2001 From: Daniel Schwabeneder Date: Wed, 13 May 2020 16:45:30 +0200 Subject: [PATCH 3/5] make colorbars thinner --- src/backends/pgfplotsx.jl | 1 + 1 file changed, 1 insertion(+) diff --git a/src/backends/pgfplotsx.jl b/src/backends/pgfplotsx.jl index 1527b2c5..2370707f 100644 --- a/src/backends/pgfplotsx.jl +++ b/src/backends/pgfplotsx.jl @@ -247,6 +247,7 @@ function (pgfx_plot::PGFPlotsXPlot)(plt::Plot{PGFPlotsXBackend}) push!( axis_opt, string("colorbar", pgfx_get_colorbar_pos(sp[:colorbar])) => nothing, + "colorbar/width" => "2mm", "colorbar style" => colorbar_style, "point meta max" => get_clims(sp)[2], "point meta min" => get_clims(sp)[1], From c97255fc08187539338d01c82a6ebbe04bf80640 Mon Sep 17 00:00:00 2001 From: Daniel Schwabeneder Date: Wed, 13 May 2020 16:54:00 +0200 Subject: [PATCH 4/5] don't make colorbars thinner --- src/backends/pgfplotsx.jl | 1 - 1 file changed, 1 deletion(-) diff --git a/src/backends/pgfplotsx.jl b/src/backends/pgfplotsx.jl index 2370707f..1527b2c5 100644 --- a/src/backends/pgfplotsx.jl +++ b/src/backends/pgfplotsx.jl @@ -247,7 +247,6 @@ function (pgfx_plot::PGFPlotsXPlot)(plt::Plot{PGFPlotsXBackend}) push!( axis_opt, string("colorbar", pgfx_get_colorbar_pos(sp[:colorbar])) => nothing, - "colorbar/width" => "2mm", "colorbar style" => colorbar_style, "point meta max" => get_clims(sp)[2], "point meta min" => get_clims(sp)[1], From f26ebdc2f19fd84ab019ef1f5139ea1c29ebefba Mon Sep 17 00:00:00 2001 From: Daniel Schwabeneder Date: Wed, 13 May 2020 17:21:18 +0200 Subject: [PATCH 5/5] remove unused color strings --- src/backends/pgfplotsx.jl | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/backends/pgfplotsx.jl b/src/backends/pgfplotsx.jl index 1527b2c5..3b71f697 100644 --- a/src/backends/pgfplotsx.jl +++ b/src/backends/pgfplotsx.jl @@ -230,8 +230,6 @@ function (pgfx_plot::PGFPlotsXPlot)(plt::Plot{PGFPlotsXBackend}) @label colorbar_end if hascolorbar(sp) - xcstr = plot_color(sp[:xaxis][:tickfontcolor]) - ycstr = plot_color(sp[:yaxis][:tickfontcolor]) colorbar_style = PGFPlotsX.Options( "title" => sp[:colorbar_title], "xticklabel style" => pgfx_get_ticklabel_style(sp, sp[:xaxis]),