Merge pull request #2700 from daschw/pgfx-colorbar
pgfplotsx colorbar improvements
This commit is contained in:
commit
9ae7d2dd9d
@ -206,41 +206,50 @@ function (pgfx_plot::PGFPlotsXPlot)(plt::Plot{PGFPlotsXBackend})
|
|||||||
# As it is likely that all series within the same axis use the same
|
# As it is likely that all series within the same axis use the same
|
||||||
# colormap this should not cause any problem.
|
# colormap this should not cause any problem.
|
||||||
for series in series_list(sp)
|
for series in series_list(sp)
|
||||||
if hascolorbar(series)
|
if hascolorbar(series)
|
||||||
cg = get_colorgradient(series)
|
cg = get_colorgradient(series)
|
||||||
cm = pgfx_colormap(get_colorgradient(series))
|
cm = pgfx_colormap(get_colorgradient(series))
|
||||||
PGFPlotsX.push_preamble!(
|
PGFPlotsX.push_preamble!(
|
||||||
pgfx_plot.the_plot,
|
pgfx_plot.the_plot,
|
||||||
"""\\pgfplotsset{
|
"""\\pgfplotsset{
|
||||||
colormap={plots$(sp.attr[:subplot_index])}{$cm},
|
colormap={plots$(sp.attr[:subplot_index])}{$cm},
|
||||||
}""",
|
}""",
|
||||||
)
|
)
|
||||||
|
push!(axis_opt, "colormap name" => "plots$(sp.attr[:subplot_index])")
|
||||||
|
if cg isa PlotUtils.CategoricalColorGradient
|
||||||
push!(
|
push!(
|
||||||
axis_opt,
|
axis_opt,
|
||||||
"colorbar" => nothing,
|
"colormap access" => "piecewise const",
|
||||||
"colormap name" => "plots$(sp.attr[:subplot_index])",
|
"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
|
end
|
||||||
|
# goto is needed to break out of col and series for
|
||||||
|
@goto colorbar_end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
@label colorbar_end
|
@label colorbar_end
|
||||||
|
|
||||||
push!(
|
if hascolorbar(sp)
|
||||||
axis_opt,
|
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]),
|
||||||
"point meta max" => get_clims(sp)[2],
|
"yticklabel style" => pgfx_get_ticklabel_style(sp, sp[:yaxis]),
|
||||||
"point meta min" => get_clims(sp)[1],
|
)
|
||||||
)
|
if sp[:colorbar] === :top
|
||||||
|
push!(colorbar_style,
|
||||||
|
"at" => string((0.5, 1.05)),
|
||||||
|
"anchor" => "south",
|
||||||
|
"xticklabel pos" => "upper",
|
||||||
|
)
|
||||||
|
end
|
||||||
|
push!(
|
||||||
|
axis_opt,
|
||||||
|
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],
|
||||||
|
)
|
||||||
|
end
|
||||||
if RecipesPipeline.is3d(sp)
|
if RecipesPipeline.is3d(sp)
|
||||||
azim, elev = sp[:camera]
|
azim, elev = sp[:camera]
|
||||||
push!(axis_opt, "view" => (azim, elev))
|
push!(axis_opt, "view" => (azim, elev))
|
||||||
@ -669,6 +678,22 @@ pgfx_get_legend_pos(k) = get(
|
|||||||
("at" => string((1.02, 1)), "anchor" => "north west"),
|
("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
|
# Generates a colormap for pgfplots based on a ColorGradient
|
||||||
pgfx_arrow(::Nothing) = "every arrow/.append style={-}"
|
pgfx_arrow(::Nothing) = "every arrow/.append style={-}"
|
||||||
@ -1105,17 +1130,8 @@ function pgfx_axis!(opt::PGFPlotsX.Options, sp::Subplot, letter)
|
|||||||
string(letter, "tick align") =>
|
string(letter, "tick align") =>
|
||||||
(axis[:tick_direction] == :out ? "outside" : "inside"),
|
(axis[:tick_direction] == :out ? "outside" : "inside"),
|
||||||
)
|
)
|
||||||
cstr = plot_color(axis[:tickfontcolor])
|
|
||||||
α = alpha(cstr)
|
|
||||||
push!(
|
push!(
|
||||||
opt,
|
opt, string(letter, "ticklabel style") => pgfx_get_ticklabel_style(sp, axis)
|
||||||
string(letter, "ticklabel style") => PGFPlotsX.Options(
|
|
||||||
"font" =>
|
|
||||||
pgfx_font(axis[:tickfontsize], pgfx_thickness_scaling(sp)),
|
|
||||||
"color" => cstr,
|
|
||||||
"draw opacity" => α,
|
|
||||||
"rotate" => axis[:tickfontrotation],
|
|
||||||
),
|
|
||||||
)
|
)
|
||||||
push!(
|
push!(
|
||||||
opt,
|
opt,
|
||||||
@ -1203,6 +1219,7 @@ function pgfx_axis!(opt::PGFPlotsX.Options, sp::Subplot, letter)
|
|||||||
)
|
)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
# --------------------------------------------------------------------------------------
|
# --------------------------------------------------------------------------------------
|
||||||
# display calls this and then _display, its called 3 times for plot(1:5)
|
# 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
|
# Set the (left, top, right, bottom) minimum padding around the plot area
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user