colorbar improvements for pgfplotsx (#3441)
* incorporate colorbar ticks and ticklabel styles * fix colorbar showing
This commit is contained in:
parent
8cf268a390
commit
02437562a7
1
.gitignore
vendored
1
.gitignore
vendored
@ -12,3 +12,4 @@ dev/
|
|||||||
test/tmpplotsave.hdf5
|
test/tmpplotsave.hdf5
|
||||||
/.benchmarkci
|
/.benchmarkci
|
||||||
/benchmark/*.json
|
/benchmark/*.json
|
||||||
|
.vscode/
|
||||||
|
|||||||
@ -225,16 +225,22 @@ function (pgfx_plot::PGFPlotsXPlot)(plt::Plot{PGFPlotsXBackend})
|
|||||||
@label colorbar_end
|
@label colorbar_end
|
||||||
|
|
||||||
if hascolorbar(sp)
|
if hascolorbar(sp)
|
||||||
|
cticks = get_colorbar_ticks(sp)[2]
|
||||||
colorbar_style = PGFPlotsX.Options(
|
colorbar_style = PGFPlotsX.Options(
|
||||||
"title" => sp[:colorbar_title],
|
"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
|
if sp[:colorbar] === :top
|
||||||
push!(colorbar_style,
|
push!(colorbar_style,
|
||||||
"at" => string((0.5, 1.05)),
|
"at" => string((0.5, 1.05)),
|
||||||
"anchor" => "south",
|
"anchor" => "south",
|
||||||
|
"xtick" => string("{", join(cticks, ","), "}"),
|
||||||
"xticklabel pos" => "upper",
|
"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
|
end
|
||||||
push!(
|
push!(
|
||||||
@ -242,6 +248,8 @@ function (pgfx_plot::PGFPlotsXPlot)(plt::Plot{PGFPlotsXBackend})
|
|||||||
string("colorbar", pgfx_get_colorbar_pos(sp[:colorbar])) => nothing,
|
string("colorbar", pgfx_get_colorbar_pos(sp[:colorbar])) => nothing,
|
||||||
"colorbar style" => colorbar_style,
|
"colorbar style" => colorbar_style,
|
||||||
)
|
)
|
||||||
|
else
|
||||||
|
push!(axis_opt, "colorbar" => "false")
|
||||||
end
|
end
|
||||||
if RecipesPipeline.is3d(sp)
|
if RecipesPipeline.is3d(sp)
|
||||||
azim, elev = sp[:camera]
|
azim, elev = sp[:camera]
|
||||||
@ -809,15 +817,23 @@ function pgfx_get_ticklabel_style(sp, axis)
|
|||||||
return PGFPlotsX.Options(
|
return PGFPlotsX.Options(
|
||||||
"font" => pgfx_font(
|
"font" => pgfx_font(
|
||||||
axis[:tickfontsize], pgfx_thickness_scaling(sp)
|
axis[:tickfontsize], pgfx_thickness_scaling(sp)
|
||||||
),
|
), "color" => cstr,
|
||||||
"color" => cstr,
|
|
||||||
"draw opacity" => alpha(cstr),
|
"draw opacity" => alpha(cstr),
|
||||||
"rotate" => axis[:tickfontrotation],
|
"rotate" => axis[:tickfontrotation],
|
||||||
)
|
)
|
||||||
end
|
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={-}"
|
pgfx_arrow(::Nothing) = "every arrow/.append style={-}"
|
||||||
function pgfx_arrow(arr::Arrow, side = arr.side)
|
function pgfx_arrow(arr::Arrow, side = arr.side)
|
||||||
components = String[]
|
components = String[]
|
||||||
@ -848,6 +864,7 @@ function pgfx_filllegend!(series_opt, opt)
|
|||||||
}""")
|
}""")
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# Generates a colormap for pgfplots based on a ColorGradient
|
||||||
pgfx_colormap(cl::PlotUtils.AbstractColorList) = pgfx_colormap(color_list(cl))
|
pgfx_colormap(cl::PlotUtils.AbstractColorList) = pgfx_colormap(color_list(cl))
|
||||||
function pgfx_colormap(v::Vector{<:Colorant})
|
function pgfx_colormap(v::Vector{<:Colorant})
|
||||||
join(map(v) do c
|
join(map(v) do c
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user