unite titlefonts (#2363)
* change default `plot_title` * add fontkwargs for colorbar_title, plot_title and window_title * add utility functions * adjust default colorbar title fontsize * remove window-title attributes and edit description * add match_map entries * remove plot_fontfamily add match for colorbar_fontfamily * add process_any_label * add tests * add magic arguments * adjust tests * fix subplot args
This commit is contained in:
parent
217e67fb7f
commit
bf85afe9d6
@ -59,7 +59,7 @@ const _arg_desc = KW(
|
||||
:foreground_color => "Color Type. Base color for all foregrounds.",
|
||||
:size => "NTuple{2,Int}. (width_px, height_px) of the whole Plot",
|
||||
:pos => "NTuple{2,Int}. (left_px, top_px) position of the GUI window (note: currently unimplemented)",
|
||||
:window_title => "String. Title of the window.",
|
||||
:window_title => "String. Title of the standalone gui-window.",
|
||||
:show => "Bool. Should this command open/refresh a GUI/display? This allows displaying in scripts or functions without explicitly calling `display`",
|
||||
:layout => "Integer (number of subplots), NTuple{2,Integer} (grid dimensions), AbstractLayout (for example `grid(2,2)`), or the return from the `@layout` macro. This builds the layout of subplots.",
|
||||
:link => "Symbol. How/whether to link axis limits between subplots. Values: `:none`, `:x` (x axes are linked by columns), `:y` (y axes are linked by rows), `:both` (x and y are linked), `:all` (every subplot is linked together regardless of layout position).",
|
||||
|
||||
28
src/args.jl
28
src/args.jl
@ -294,6 +294,13 @@ const _series_defaults = KW(
|
||||
|
||||
const _plot_defaults = KW(
|
||||
:plot_title => "",
|
||||
:plot_titlefontsize => 16,
|
||||
:plot_title_location => :center, # also :left or :right
|
||||
:plot_titlefontfamily => :match,
|
||||
:plot_titlefonthalign => :hcenter,
|
||||
:plot_titlefontvalign => :vcenter,
|
||||
:plot_titlefontrotation => 0.0,
|
||||
:plot_titlefontcolor => :match,
|
||||
:background_color => colorant"white", # default for all backgrounds,
|
||||
:background_color_outside => :match, # background outside grid,
|
||||
:foreground_color => :auto, # default for all foregrounds, and title color,
|
||||
@ -361,6 +368,14 @@ const _subplot_defaults = KW(
|
||||
:bottom_margin => :match,
|
||||
:subplot_index => -1,
|
||||
:colorbar_title => "",
|
||||
:colorbar_titlefontsize => 10,
|
||||
:colorbar_title_location => :center, # also :left or :right
|
||||
:colorbar_fontfamily => :match,
|
||||
:colorbar_titlefontfamily => :match,
|
||||
:colorbar_titlefonthalign => :hcenter,
|
||||
:colorbar_titlefontvalign => :vcenter,
|
||||
:colorbar_titlefontrotation => 0.0,
|
||||
:colorbar_titlefontcolor => :match,
|
||||
:framestyle => :axes,
|
||||
:camera => (30,30),
|
||||
:extra_kwargs => Dict()
|
||||
@ -468,7 +483,7 @@ const _subplot_args = sort(union(collect(keys(_subplot_defaults))))
|
||||
const _plot_args = sort(union(collect(keys(_plot_defaults))))
|
||||
|
||||
const _magic_axis_args = [:axis, :tickfont, :guidefont, :grid, :minorgrid]
|
||||
const _magic_subplot_args = [:titlefont, :legendfont, :legendtitlefont, ]
|
||||
const _magic_subplot_args = [:titlefont, :legendfont, :legendtitlefont, :plot_titlefont, :colorbar_titlefont]
|
||||
const _magic_series_args = [:line, :marker, :fill]
|
||||
|
||||
const _all_axis_args = sort(union([_axis_args; _magic_axis_args]))
|
||||
@ -1048,7 +1063,7 @@ function RecipesPipeline.preprocess_attributes!(plotattributes::AKW)
|
||||
end
|
||||
|
||||
# fonts
|
||||
for fontname in (:titlefont, :legendfont, :legendtitlefont)
|
||||
for fontname in (:titlefont, :legendfont, :legendtitlefont, :plot_titlefont, :colorbar_titlefont)
|
||||
args = RecipesPipeline.pop_kw!(plotattributes, fontname, ())
|
||||
for arg in wraptuple(args)
|
||||
processFontArg!(plotattributes, fontname, arg)
|
||||
@ -1285,11 +1300,16 @@ const _match_map = KW(
|
||||
:right_margin => :margin,
|
||||
:bottom_margin => :margin,
|
||||
:titlefontfamily => :fontfamily_subplot,
|
||||
:legendfontfamily => :fontfamily_subplot,
|
||||
:legendtitlefontfamily => :fontfamily_subplot,
|
||||
:titlefontcolor => :foreground_color_subplot,
|
||||
:legendfontfamily => :fontfamily_subplot,
|
||||
:legendfontcolor => :foreground_color_subplot,
|
||||
:legendtitlefontfamily => :fontfamily_subplot,
|
||||
:legendtitlefontcolor => :foreground_color_subplot,
|
||||
:colorbar_fontfamily => :fontfamily_subplot,
|
||||
:colorbar_titlefontfamily => :fontfamily_subplot,
|
||||
:colorbar_titlefontcolor => :foreground_color_subplot,
|
||||
:plot_titlefontfamily => :fontfamily,
|
||||
:plot_titlefontcolor => :foreground_color,
|
||||
:tickfontcolor => :foreground_color_text,
|
||||
:guidefontcolor => :foreground_color_guide,
|
||||
)
|
||||
|
||||
@ -640,6 +640,9 @@ function process_annotation(sp::Subplot, positions::Union{AVec{Symbol},Symbol},
|
||||
anns
|
||||
end
|
||||
|
||||
function process_any_label(lab, font=Font())
|
||||
lab isa Tuple ? text(lab...) : text( lab, font )
|
||||
end
|
||||
# Give each annotation coordinates based on specified position
|
||||
function locate_annotation(sp::Subplot, pos::Symbol, lab::PlotText)
|
||||
position_multiplier = Dict{Symbol, Tuple{Float64,Float64}}(
|
||||
|
||||
18
src/utils.jl
18
src/utils.jl
@ -1004,6 +1004,24 @@ ignorenan_extrema(plt::Plot) = (xmin(plt), xmax(plt))
|
||||
# ---------------------------------------------------------------
|
||||
# get fonts from objects:
|
||||
|
||||
plottitlefont(p::Plot) = font(
|
||||
p[:plot_titlefontfamily],
|
||||
p[:plot_titlefontsize],
|
||||
p[:plot_titlefontvalign],
|
||||
p[:plot_titlefonthalign],
|
||||
p[:plot_titlefontrotation],
|
||||
p[:plot_titlefontcolor],
|
||||
)
|
||||
|
||||
colorbartitlefont(sp::Subplot) = font(
|
||||
sp[:colorbar_titlefontfamily],
|
||||
sp[:colorbar_titlefontsize],
|
||||
sp[:colorbar_titlefontvalign],
|
||||
sp[:colorbar_titlefonthalign],
|
||||
sp[:colorbar_titlefontrotation],
|
||||
sp[:colorbar_titlefontcolor],
|
||||
)
|
||||
|
||||
titlefont(sp::Subplot) = font(
|
||||
sp[:titlefontfamily],
|
||||
sp[:titlefontsize],
|
||||
|
||||
@ -357,3 +357,22 @@ end # testset
|
||||
axes = Plots.pgfx_axes(pl.o)
|
||||
@test filter(x->x isa String, axes[1].contents)[1] == raw"\node at (0,0.5) {\huge hi};"
|
||||
end # testset
|
||||
|
||||
@testset "Titlefonts" begin
|
||||
pl = plot(1:5, title = "Test me", titlefont = (2, :left))
|
||||
@test pl[1][:title] == "Test me"
|
||||
@test pl[1][:titlefontsize] == 2
|
||||
@test pl[1][:titlefonthalign] == :left
|
||||
Plots._update_plot_object(pl)
|
||||
ax_opt = Plots.pgfx_axes(pl.o)[1].options
|
||||
@test ax_opt["title"] == "Test me"
|
||||
@test(haskey(ax_opt.dict, "title style")) isa Test.Pass
|
||||
pl = plot(1:5, plot_title = "Test me", plot_titlefont = (2, :left))
|
||||
@test pl[:plot_title] == "Test me"
|
||||
@test pl[:plot_titlefontsize] == 2
|
||||
@test pl[:plot_titlefonthalign] == :left
|
||||
pl = heatmap(rand(3,3), colorbar_title = "Test me", colorbar_titlefont = (12, :right))
|
||||
@test pl[1][:colorbar_title] == "Test me"
|
||||
@test pl[1][:colorbar_titlefontsize] == 12
|
||||
@test pl[1][:colorbar_titlefonthalign] == :right
|
||||
end # testset
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user