From 02437562a76c6f9d6e5d1464f5a811cdd5c4e411 Mon Sep 17 00:00:00 2001 From: Simon Christ Date: Tue, 27 Apr 2021 09:50:49 +0200 Subject: [PATCH] colorbar improvements for pgfplotsx (#3441) * incorporate colorbar ticks and ticklabel styles * fix colorbar showing --- .gitignore | 1 + src/backends/pgfplotsx.jl | 27 ++++++++++++++++++++++----- 2 files changed, 23 insertions(+), 5 deletions(-) diff --git a/.gitignore b/.gitignore index 544fc7cb..48ae0045 100644 --- a/.gitignore +++ b/.gitignore @@ -12,3 +12,4 @@ dev/ test/tmpplotsave.hdf5 /.benchmarkci /benchmark/*.json +.vscode/ diff --git a/src/backends/pgfplotsx.jl b/src/backends/pgfplotsx.jl index 8967c855..6273108c 100644 --- a/src/backends/pgfplotsx.jl +++ b/src/backends/pgfplotsx.jl @@ -225,16 +225,22 @@ function (pgfx_plot::PGFPlotsXPlot)(plt::Plot{PGFPlotsXBackend}) @label colorbar_end if hascolorbar(sp) + cticks = get_colorbar_ticks(sp)[2] 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", + "xtick" => string("{", join(cticks, ","), "}"), "xticklabel pos" => "upper", + "xticklabel style" => pgfx_get_colorbar_ticklabel_style(sp), + ) + else + push!(colorbar_style, + "ytick" => string("{", join(cticks, ","), "}"), + "yticklabel style" => pgfx_get_colorbar_ticklabel_style(sp), ) end push!( @@ -242,6 +248,8 @@ function (pgfx_plot::PGFPlotsXPlot)(plt::Plot{PGFPlotsXBackend}) string("colorbar", pgfx_get_colorbar_pos(sp[:colorbar])) => nothing, "colorbar style" => colorbar_style, ) + else + push!(axis_opt, "colorbar" => "false") end if RecipesPipeline.is3d(sp) azim, elev = sp[:camera] @@ -809,15 +817,23 @@ function pgfx_get_ticklabel_style(sp, axis) return PGFPlotsX.Options( "font" => pgfx_font( axis[:tickfontsize], pgfx_thickness_scaling(sp) - ), - "color" => cstr, + ), "color" => cstr, "draw opacity" => alpha(cstr), "rotate" => axis[:tickfontrotation], ) end +function pgfx_get_colorbar_ticklabel_style(sp) + cstr = plot_color(sp[:colorbar_tickfontcolor]) + return PGFPlotsX.Options( + "font" => pgfx_font( + sp[:colorbar_tickfontsize], pgfx_thickness_scaling(sp) + ), "color" => cstr, + "draw opacity" => alpha(cstr), + "rotate" => sp[:colorbar_tickfontrotation], + ) +end ## -------------------------------------------------------------------------------------- -# Generates a colormap for pgfplots based on a ColorGradient pgfx_arrow(::Nothing) = "every arrow/.append style={-}" function pgfx_arrow(arr::Arrow, side = arr.side) components = String[] @@ -848,6 +864,7 @@ function pgfx_filllegend!(series_opt, opt) }""") end +# Generates a colormap for pgfplots based on a ColorGradient pgfx_colormap(cl::PlotUtils.AbstractColorList) = pgfx_colormap(color_list(cl)) function pgfx_colormap(v::Vector{<:Colorant}) join(map(v) do c