Format .jl files [skip ci]

This commit is contained in:
t-bltg 2021-10-24 00:10:37 +00:00 committed by GitHub
parent 2e67e84361
commit 3c156301d9
10 changed files with 125 additions and 84 deletions

View File

@ -108,22 +108,22 @@ const _arg_desc = KW(
:legend_title_font_color => "Color Type. Font color of the legend title",
:colorbar => "Bool (show the colorbar?) or Symbol (colorbar position). Symbol values: `:none`, `:best`, `:right`, `:left`, `:top`, `:bottom`, `:legend` (matches legend value) (note: only some may be supported in each backend)",
:clims => "`:auto`, NTuple{2,Number}, or a function that takes series data in and returns NTuple{2,Number}. Fixes the limits of the colorbar.",
:colorbar_fontfamily => "String or Symbol. Font family of colobar entries.",
:colorbar_ticks => "Vector of numbers (set the tick values), Tuple of (tickvalues, ticklabels), or `:auto`",
:colorbar_tickfontfamily => "String or Symbol. Font family of colorbar tick labels.",
:colorbar_tickfontsize => "Integer. Font pointsize of colorbar tick entries.",
:colorbar_tickfontcolor => "Color Type. Font color of colorbar tick entries",
:colorbar_scale => "Symbol. Scale of the colorbar axis: `:none`, `:ln`, `:log2`, `:log10`",
:colorbar_formatter => "Function, :scientific, :plain or :auto. A method which converts a number to a string for tick labeling.",
:colorbar_fontfamily => "String or Symbol. Font family of colobar entries.",
:colorbar_ticks => "Vector of numbers (set the tick values), Tuple of (tickvalues, ticklabels), or `:auto`",
:colorbar_tickfontfamily => "String or Symbol. Font family of colorbar tick labels.",
:colorbar_tickfontsize => "Integer. Font pointsize of colorbar tick entries.",
:colorbar_tickfontcolor => "Color Type. Font color of colorbar tick entries",
:colorbar_scale => "Symbol. Scale of the colorbar axis: `:none`, `:ln`, `:log2`, `:log10`",
:colorbar_formatter => "Function, :scientific, :plain or :auto. A method which converts a number to a string for tick labeling.",
:legendfont => "Font. Font of legend items.",
:legend_titlefont => "Font. Font of the legend title.",
:annotations => "(x,y,text) tuple(s). Can be a single tuple or a list of them. Text can be String, PlotText (created with `text(args...)`), or a tuple of arguments to `text` (e.g., `(\"Label\", 8, :red, :top)`). Add one-off text annotations at the x,y coordinates.",
:annotationfontfamily => "String or Symbol. Font family of annotations.",
:annotationfontsize => "Integer. Font pointsize of annotations.",
:annotationhalign => "Symbol. horizontal alignment of annotations, :hcenter, :left, :right or :center.",
:annotationvalign => "Symbol. Vertical alignment of annotations, :vcenter, :top, :bottom or :center.",
:annotationrotation => "Float. Rotation of annotations in degrees.",
:annotationcolor => "Colorant or :match. Color of annotations.",
:annotationfontfamily => "String or Symbol. Font family of annotations.",
:annotationfontsize => "Integer. Font pointsize of annotations.",
:annotationhalign => "Symbol. horizontal alignment of annotations, :hcenter, :left, :right or :center.",
:annotationvalign => "Symbol. Vertical alignment of annotations, :vcenter, :top, :bottom or :center.",
:annotationrotation => "Float. Rotation of annotations in degrees.",
:annotationcolor => "Colorant or :match. Color of annotations.",
:projection => "Symbol or String. '3d' or 'polar'",
:aspect_ratio => "Symbol (:equal or :none) or Number. Plot area is resized so that 1 y-unit is the same size as `aspect_ratio` x-units. With `:none`, images inherit aspect ratio of the plot area.",
:margin => "Measure (multiply by `mm`, `px`, etc). Base for individual margins... not directly used. Specifies the extra padding around subplots.",

View File

@ -597,15 +597,25 @@ function _update_plot_object(plt::Plot{PGFPlotsBackend})
cstr, bg_alpha = pgf_color(plot_color(sp[:legend_background_color]))
fg_alpha = alpha(plot_color(sp[:legend_foreground_color]))
push!(style, string(
"legend style = {",
pgf_linestyle(pgf_thickness_scaling(sp), sp[:legend_foreground_color], fg_alpha, "solid", ), ",",
push!(
style,
string(
"legend style = {",
pgf_linestyle(
pgf_thickness_scaling(sp),
sp[:legend_foreground_color],
fg_alpha,
"solid",
),
",",
"fill = $cstr,",
"fill opacity = $bg_alpha,",
"text opacity = $(alpha(plot_color(sp[:legend_font_color]))),",
"font = ", pgf_font(sp[:legend_font_pointsize], pgf_thickness_scaling(sp)),
"}",
))
"font = ",
pgf_font(sp[:legend_font_pointsize], pgf_thickness_scaling(sp)),
"}",
),
)
if any(s[:seriestype] == :contour for s in series_list(sp))
kw[:view] = "{0}{90}"

View File

@ -1024,7 +1024,7 @@ end
## Legend
function gr_add_legend(sp, leg, viewport_plotarea)
if !(sp[:legend_position] in(:none, :inline))
if !(sp[:legend_position] in (:none, :inline))
GR.savestate()
GR.selntran(0)
GR.setscale(0)
@ -1100,7 +1100,8 @@ function gr_add_legend(sp, leg, viewport_plotarea)
ms = first(series[:markersize])
msw = first(series[:markerstrokewidth])
s, sw = if ms > 0
0.8 * sp[:legend_font_pointsize], 0.8 * sp[:legend_font_pointsize] * msw / ms
0.8 * sp[:legend_font_pointsize],
0.8 * sp[:legend_font_pointsize] * msw / ms
else
0, 0.8 * sp[:legend_font_pointsize] * msw / 8
end
@ -1302,7 +1303,7 @@ function gr_update_viewport_legend!(viewport_plotarea, sp, leg)
if s isa Tuple{<:Real,Symbol}
if s[2] === :outer
(x,y) = gr_legend_pos(sp, leg, viewport_plotarea) # Dry run, to figure out
(x, y) = gr_legend_pos(sp, leg, viewport_plotarea) # Dry run, to figure out
if x < viewport_plotarea[1]
viewport_plotarea[1] +=
leg.leftw +

View File

@ -390,33 +390,37 @@ function _inspectdr_setupsubplot(sp::Subplot{InspectDRBackend})
#Modify base layout of new object:
l = plot.layout.defaults = deepcopy(InspectDR.defaults.plotlayout)
#IMPORTANT: Must deepcopy to ensure we don't change layouts of other plots.
#Works because plot uses defaults (not user-overwritten `layout.values`)
l.frame_canvas.fillcolor = _inspectdr_mapcolor(sp[:background_color_subplot])
l.frame_data.fillcolor = _inspectdr_mapcolor(sp[:background_color_inside])
l.frame_data.line.color = _inspectdr_mapcolor(xaxis[:foreground_color_axis])
l.font_title = InspectDR.Font(sp[:titlefontfamily],
_inspectdr_mapptsize(sp[:titlefontsize]),
color = _inspectdr_mapcolor(sp[:titlefontcolor])
)
#Cannot independently control fonts of axes with InspectDR:
l.font_axislabel = InspectDR.Font(xaxis[:guidefontfamily],
_inspectdr_mapptsize(xaxis[:guidefontsize]),
color = _inspectdr_mapcolor(xaxis[:guidefontcolor])
)
l.font_ticklabel = InspectDR.Font(xaxis[:tickfontfamily],
_inspectdr_mapptsize(xaxis[:tickfontsize]),
color = _inspectdr_mapcolor(xaxis[:tickfontcolor])
)
l.enable_legend = (sp[:legend_position] != :none)
#l.halloc_legend = 150 #TODO: compute???
l.font_legend = InspectDR.Font(sp[:legend_font_family],
_inspectdr_mapptsize(sp[:legend_font_pointsize]),
color = _inspectdr_mapcolor(sp[:legend_font_color])
)
l.frame_legend.fillcolor = _inspectdr_mapcolor(sp[:legend_background_color])
#_round!() ensures values use integer spacings (looks better on screen):
InspectDR._round!(InspectDR.autofit2font!(l, legend_width=10.0)) #10 "em"s wide
#IMPORTANT: Must deepcopy to ensure we don't change layouts of other plots.
#Works because plot uses defaults (not user-overwritten `layout.values`)
l.frame_canvas.fillcolor = _inspectdr_mapcolor(sp[:background_color_subplot])
l.frame_data.fillcolor = _inspectdr_mapcolor(sp[:background_color_inside])
l.frame_data.line.color = _inspectdr_mapcolor(xaxis[:foreground_color_axis])
l.font_title = InspectDR.Font(
sp[:titlefontfamily],
_inspectdr_mapptsize(sp[:titlefontsize]),
color = _inspectdr_mapcolor(sp[:titlefontcolor]),
)
#Cannot independently control fonts of axes with InspectDR:
l.font_axislabel = InspectDR.Font(
xaxis[:guidefontfamily],
_inspectdr_mapptsize(xaxis[:guidefontsize]),
color = _inspectdr_mapcolor(xaxis[:guidefontcolor]),
)
l.font_ticklabel = InspectDR.Font(
xaxis[:tickfontfamily],
_inspectdr_mapptsize(xaxis[:tickfontsize]),
color = _inspectdr_mapcolor(xaxis[:tickfontcolor]),
)
l.enable_legend = (sp[:legend_position] != :none)
#l.halloc_legend = 150 #TODO: compute???
l.font_legend = InspectDR.Font(
sp[:legend_font_family],
_inspectdr_mapptsize(sp[:legend_font_pointsize]),
color = _inspectdr_mapcolor(sp[:legend_font_color]),
)
l.frame_legend.fillcolor = _inspectdr_mapcolor(sp[:legend_background_color])
#_round!() ensures values use integer spacings (looks better on screen):
InspectDR._round!(InspectDR.autofit2font!(l, legend_width = 10.0)) #10 "em"s wide
return
end

View File

@ -166,9 +166,8 @@ function (pgfx_plot::PGFPlotsXPlot)(plt::Plot{PGFPlotsXBackend})
sp_width > 0 * mm ? push!(axis_opt, "width" => string(axis_width)) : nothing
sp_height > 0 * mm ? push!(axis_opt, "height" => string(axis_height)) : nothing
for letter in (:x, :y, :z)
if letter != :z ||
RecipesPipeline.is3d(sp)
pgfx_axis!(axis_opt, sp, letter)
if letter != :z || RecipesPipeline.is3d(sp)
pgfx_axis!(axis_opt, sp, letter)
end
end
# Search series for any gradient. In case one series uses a gradient set
@ -256,11 +255,9 @@ function (pgfx_plot::PGFPlotsXPlot)(plt::Plot{PGFPlotsXBackend})
axis,
PGFPlotsX.LegendEntry(
PGFPlotsX.Options(
"font" => pgfx_font(
legtfont.pointsize,
pgfx_thickness_scaling(sp),
),
"text" => legtfont.color
"font" =>
pgfx_font(legtfont.pointsize, pgfx_thickness_scaling(sp)),
"text" => legtfont.color,
),
string("\\hspace{-.6cm}{\\textbf{", sp[:legend_title], "}}"),
false,
@ -388,7 +385,8 @@ function pgfx_add_series!(::Val{:path}, axis, series_opt, series, series_func, o
end
end
if i == 1 &&
series[:subplot][:legend_position] != :none && pgfx_should_add_to_legend(series)
series[:subplot][:legend_position] != :none &&
pgfx_should_add_to_legend(series)
pgfx_filllegend!(series_opt, opt)
end
end
@ -822,12 +820,15 @@ function pgfx_get_legend_style(sp)
"fill" => cstr,
"fill opacity" => a,
"text opacity" => alpha(plot_color(sp[:legend_font_color])),
"font" => pgfx_font(
sp[:legend_font_pointsize],
pgfx_thickness_scaling(sp),
),
"font" => pgfx_font(sp[:legend_font_pointsize], pgfx_thickness_scaling(sp)),
"text" => plot_color(sp[:legend_font_color]),
"cells" => PGFPlotsX.Options("anchor" => get((left = "west", right = "east", hcenter = "center"), legfont.halign, "west")),
"cells" => PGFPlotsX.Options(
"anchor" => get(
(left = "west", right = "east", hcenter = "center"),
legfont.halign,
"west",
),
),
pgfx_get_legend_pos(sp[:legend_position])...,
)
end
@ -957,7 +958,6 @@ end
pgfx_legend_col(s::Symbol) = s == :horizontal ? -1 : 1
pgfx_legend_col(n) = n
function pgfx_linestyle(plotattributes, i = 1)
lw = pgfx_thickness_scaling(plotattributes) * get_linewidth(plotattributes, i)
lc = single_color(get_linecolor(plotattributes, i))
@ -1454,7 +1454,8 @@ end
# to fit ticks, tick labels, guides, colorbars, etc.
function _update_min_padding!(sp::Subplot{PGFPlotsXBackend})
leg = sp[:legend_position]
if leg in (:best, :outertopright, :outerright, :outerbottomright) || (leg isa Tuple && leg[1] >= 1)
if leg in (:best, :outertopright, :outerright, :outerbottomright) ||
(leg isa Tuple && leg[1] >= 1)
sp.minpad = (0mm, 0mm, 5mm, 0mm)
else
sp.minpad = (0mm, 0mm, 0mm, 0mm)

View File

@ -342,7 +342,7 @@ function plotly_add_legend!(plotattributes_out::KW, sp::Subplot)
legend_position = plotly_legend_pos(sp[:legend_position])
if sp[:legend_position] != :none
plotattributes_out[:legend_position] = KW(
:bgcolor => rgba_string(sp[:legend_background_color]),
:bgcolor => rgba_string(sp[:legend_background_color]),
:bordercolor => rgba_string(sp[:legend_foreground_color]),
:borderwidth => 1,
:traceorder => "normal",

View File

@ -1679,11 +1679,21 @@ function py_add_legend(plt::Plot, sp::Subplot, ax)
leg."set_zorder"(1000)
if sp[:legend_title] !== nothing
leg."set_title"(sp[:legend_title])
PyPlot.plt."setp"(leg."get_title"(), color = py_color(sp[:legend_title_font_color]), family = sp[:legend_title_font_family], fontsize = py_thickness_scale(plt, sp[:legend_title_font_pointsize]))
PyPlot.plt."setp"(
leg."get_title"(),
color = py_color(sp[:legend_title_font_color]),
family = sp[:legend_title_font_family],
fontsize = py_thickness_scale(plt, sp[:legend_title_font_pointsize]),
)
end
for txt in leg."get_texts"()
PyPlot.plt."setp"(txt, color = py_color(sp[:legend_font_color]), family = sp[:legend_font_family], fontsize = py_thickness_scale(plt, sp[:legend_font_pointsize]))
PyPlot.plt."setp"(
txt,
color = py_color(sp[:legend_font_color]),
family = sp[:legend_font_family],
fontsize = py_thickness_scale(plt, sp[:legend_font_pointsize]),
)
end
end
end

View File

@ -1239,15 +1239,30 @@ const _examples = PlotExample[
The bars' baseline may be specified as `fillto`.
Each may be scalar, or a vector spcifying one value per bar.
""",
[:(
begin
plot(bar([-1,0,2,3], [1,3,6,2],
fill_z = 4:-1:1, alpha = [1, 0.2, 0.8, 0.5], label = "", bar_width = 1:4),
bar(rand(5), bar_width=1.2, alpha=0.8,
color=[:lightsalmon, :tomato, :crimson, :firebrick, :darkred],
fillto=0:-0.1:-0.4, label="reds"))
end
)],
[
:(
begin
plot(
bar(
[-1, 0, 2, 3],
[1, 3, 6, 2],
fill_z = 4:-1:1,
alpha = [1, 0.2, 0.8, 0.5],
label = "",
bar_width = 1:4,
),
bar(
rand(5),
bar_width = 1.2,
alpha = 0.8,
color = [:lightsalmon, :tomato, :crimson, :firebrick, :darkred],
fillto = 0:-0.1:-0.4,
label = "reds",
),
)
end
),
],
),
]

View File

@ -517,7 +517,7 @@ end
end
# Each segment is 6 elements long, including the NaN separator.
# There is no trailing NaN, so the last repetition is dropped.
plotattributes[k] = @view repeat(v; inner=6)[1:end-1]
plotattributes[k] = @view repeat(v; inner = 6)[1:(end - 1)]
end
end
()

View File

@ -19,7 +19,7 @@ Plots.__init__()
@test p[1][:legend_font_halign] == :hcenter
@test p[1][:legend_font_valign] == :vcenter
@test p[1][:legend_font_rotation] == 0.0
@test p[1][:legend_font_color] == RGB{Colors.N0f8}(0.0,0.0,0.0)
@test p[1][:legend_font_color] == RGB{Colors.N0f8}(0.0, 0.0, 0.0)
@test p[1][:legend_position] == :best
@test p[1][:legend_title] == nothing
@test p[1][:legend_title_font_family] == "sans-serif"
@ -27,9 +27,9 @@ Plots.__init__()
@test p[1][:legend_title_font_halign] == :hcenter
@test p[1][:legend_title_font_valign] == :vcenter
@test p[1][:legend_title_font_rotation] == 0.0
@test p[1][:legend_title_font_color] == RGB{Colors.N0f8}(0.0,0.0,0.0)
@test p[1][:legend_background_color] == RGBA{Float64}(1.0,1.0,1.0,1.0)
@test p[1][:legend_foreground_color] == RGB{Colors.N0f8}(0.0,0.0,0.0)
@test p[1][:legend_title_font_color] == RGB{Colors.N0f8}(0.0, 0.0, 0.0)
@test p[1][:legend_background_color] == RGBA{Float64}(1.0, 1.0, 1.0, 1.0)
@test p[1][:legend_foreground_color] == RGB{Colors.N0f8}(0.0, 0.0, 0.0)
end # testset
@testset "Legend API" begin
@ -65,6 +65,6 @@ end # testset
@test p[1][:legend_title_font_valign] == :bottom
@test p[1][:legend_title_font_rotation] == -5.2
@test p[1][:legend_title_font_color] == :blue
@test p[1][:legend_background_color] == RGBA{Float64}(0.0,1.0,1.0,1.0)
@test p[1][:legend_foreground_color] == RGBA{Float64}(0.0,0.5019607843137255,0.0,1.0)
@test p[1][:legend_background_color] == RGBA{Float64}(0.0, 1.0, 1.0, 1.0)
@test p[1][:legend_foreground_color] == RGBA{Float64}(0.0, 0.5019607843137255, 0.0, 1.0)
end # testset