improve axis decorations (#3756)
* improve handling of LaTeXStrings in tick labels * respect guidefonthalign
This commit is contained in:
parent
25a36bab85
commit
ea686c331b
@ -1232,6 +1232,8 @@ function pgfx_axis!(opt::PGFPlotsX.Options, sp::Subplot, letter)
|
|||||||
opt,
|
opt,
|
||||||
string(letter, "label style") => PGFPlotsX.Options(
|
string(letter, "label style") => PGFPlotsX.Options(
|
||||||
labelpos => nothing,
|
labelpos => nothing,
|
||||||
|
"at" => string("{(ticklabel cs:", get((left = 0, right = 1), axis[:guidefonthalign], 0.5),")}"),
|
||||||
|
"anchor" => "near ticklabel",
|
||||||
"font" => pgfx_font(axis[:guidefontsize], pgfx_thickness_scaling(sp)),
|
"font" => pgfx_font(axis[:guidefontsize], pgfx_thickness_scaling(sp)),
|
||||||
"color" => cstr,
|
"color" => cstr,
|
||||||
"draw opacity" => α,
|
"draw opacity" => α,
|
||||||
@ -1279,21 +1281,28 @@ function pgfx_axis!(opt::PGFPlotsX.Options, sp::Subplot, letter)
|
|||||||
push!(opt, string(letter, "tick") => string("{", join(tick_values, ","), "}"))
|
push!(opt, string(letter, "tick") => string("{", join(tick_values, ","), "}"))
|
||||||
if axis[:showaxis] && axis[:scale] in (:ln, :log2, :log10) && axis[:ticks] == :auto
|
if axis[:showaxis] && axis[:scale] in (:ln, :log2, :log10) && axis[:ticks] == :auto
|
||||||
# wrap the power part of label with }
|
# wrap the power part of label with }
|
||||||
tick_labels = Vector{String}(undef, length(ticks[2]))
|
tick_labels = similar(ticks[2])
|
||||||
for (i, label) in enumerate(ticks[2])
|
for (i, label) in enumerate(ticks[2])
|
||||||
base, power = split(label, "^")
|
base, power = split(label, "^")
|
||||||
power = string("{", power, "}")
|
power = string("{", power, "}")
|
||||||
tick_labels[i] = string(base, "^", power)
|
tick_labels[i] = string(base, "^", power)
|
||||||
end
|
end
|
||||||
|
if tick_labels isa Vector{String}
|
||||||
push!(
|
push!(
|
||||||
opt,
|
opt,
|
||||||
string(letter, "ticklabels") =>
|
string(letter, "ticklabels") =>
|
||||||
string("{\$", join(tick_labels, "\$,\$"), "\$}"),
|
string("{\$", join(tick_labels, "\$,\$"), "\$}"),
|
||||||
)
|
)
|
||||||
|
elseif tick_labels isa Vector{LaTeXString}
|
||||||
|
push!(
|
||||||
|
opt,
|
||||||
|
string(letter, "ticklabels") => join(tick_labels)
|
||||||
|
)
|
||||||
|
end
|
||||||
elseif axis[:showaxis]
|
elseif axis[:showaxis]
|
||||||
tick_labels =
|
tick_labels =
|
||||||
ispolar(sp) && letter == :x ? [ticks[2][3:end]..., "0", "45"] : ticks[2]
|
ispolar(sp) && letter == :x ? [ticks[2][3:end]..., "0", "45"] : ticks[2]
|
||||||
if axis[:formatter] in (:scientific, :auto)
|
if axis[:formatter] in (:scientific, :auto) && tick_labels isa Vector{String}
|
||||||
tick_labels = string.("\$", convert_sci_unicode.(tick_labels), "\$")
|
tick_labels = string.("\$", convert_sci_unicode.(tick_labels), "\$")
|
||||||
tick_labels = replace.(tick_labels, Ref("×" => "\\times"))
|
tick_labels = replace.(tick_labels, Ref("×" => "\\times"))
|
||||||
end
|
end
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user