Tick label formatting fixes
This commit is contained in:
parent
1b70fb18e4
commit
449d35ebf2
@ -123,6 +123,14 @@ const _label_func = Dict{Symbol,Function}(
|
|||||||
)
|
)
|
||||||
labelfunc(scale::Symbol, backend::AbstractBackend) = get(_label_func, scale, string)
|
labelfunc(scale::Symbol, backend::AbstractBackend) = get(_label_func, scale, string)
|
||||||
|
|
||||||
|
const _label_func_tex = Dict{Symbol,Function}(
|
||||||
|
:log10 => x -> "10^{$x}",
|
||||||
|
:log2 => x -> "2^{$x}",
|
||||||
|
:ln => x -> "e^{$x}",
|
||||||
|
)
|
||||||
|
labelfunc_tex(scale::Symbol) = get(_label_func_tex, scale, convert_sci_unicode)
|
||||||
|
|
||||||
|
|
||||||
function optimal_ticks_and_labels(sp::Subplot, axis::Axis, ticks = nothing)
|
function optimal_ticks_and_labels(sp::Subplot, axis::Axis, ticks = nothing)
|
||||||
amin, amax = axis_limits(sp, axis[:letter])
|
amin, amax = axis_limits(sp, axis[:letter])
|
||||||
|
|
||||||
|
|||||||
@ -216,7 +216,6 @@ function gr_polaraxes(rmin::Real, rmax::Real, sp::Subplot)
|
|||||||
sinf = sind.(a)
|
sinf = sind.(a)
|
||||||
cosf = cosd.(a)
|
cosf = cosd.(a)
|
||||||
rtick_values, rtick_labels = get_ticks(sp, yaxis)
|
rtick_values, rtick_labels = get_ticks(sp, yaxis)
|
||||||
rtick_labels = gr_tick_label.((yaxis,), rtick_labels)
|
|
||||||
|
|
||||||
#draw angular grid
|
#draw angular grid
|
||||||
if xaxis[:grid]
|
if xaxis[:grid]
|
||||||
@ -746,20 +745,10 @@ function gr_get_ticks_size(ticks, rot)
|
|||||||
return w, h
|
return w, h
|
||||||
end
|
end
|
||||||
|
|
||||||
gr_tick_label(axis, label) =
|
function labelfunc(scale::Symbol, backend::GRBackend)
|
||||||
(axis[:formatter] in (:scientific, :auto)) ? gr_convert_sci_tick_label(string(label)) :
|
texfunc = labelfunc_tex(scale)
|
||||||
string(label)
|
# replace dash with \minus (U+2212)
|
||||||
|
label -> replace(texfunc(label), "-" => "−")
|
||||||
function gr_convert_sci_tick_label(label)
|
|
||||||
caret_split = split(label,'^')
|
|
||||||
if length(caret_split) == 2
|
|
||||||
base, exponent = caret_split
|
|
||||||
label = "$base^{$exponent}"
|
|
||||||
end
|
|
||||||
if occursin("×10", label)
|
|
||||||
label = string(replace(label, "×10" => "×10^{"), "}")
|
|
||||||
end
|
|
||||||
label
|
|
||||||
end
|
end
|
||||||
|
|
||||||
function gr_axis_height(sp, axis)
|
function gr_axis_height(sp, axis)
|
||||||
@ -1288,7 +1277,7 @@ function gr_display(sp::Subplot{GRBackend}, w, h, viewport_canvas)
|
|||||||
xi, yi = gr_w3tondc(cv, yt, zt)
|
xi, yi = gr_w3tondc(cv, yt, zt)
|
||||||
xi += (yaxis[:mirror] ? 1 : -1) * 1e-2 * (xaxis[:tick_direction] == :out ? 1.5 : 1.0)
|
xi += (yaxis[:mirror] ? 1 : -1) * 1e-2 * (xaxis[:tick_direction] == :out ? 1.5 : 1.0)
|
||||||
yi += (xaxis[:mirror] ? 1 : -1) * 5e-3 * (xaxis[:tick_direction] == :out ? 1.5 : 1.0)
|
yi += (xaxis[:mirror] ? 1 : -1) * 5e-3 * (xaxis[:tick_direction] == :out ? 1.5 : 1.0)
|
||||||
gr_text(xi, yi, gr_tick_label(xaxis, dv))
|
gr_text(xi, yi, dv)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -1320,7 +1309,7 @@ function gr_display(sp::Subplot{GRBackend}, w, h, viewport_canvas)
|
|||||||
xi, yi = gr_w3tondc(xt, cv, zt)
|
xi, yi = gr_w3tondc(xt, cv, zt)
|
||||||
gr_text(xi + (yaxis[:mirror] ? -1 : 1) * 1e-2 * (yaxis[:tick_direction] == :out ? 1.5 : 1.0),
|
gr_text(xi + (yaxis[:mirror] ? -1 : 1) * 1e-2 * (yaxis[:tick_direction] == :out ? 1.5 : 1.0),
|
||||||
yi + (yaxis[:mirror] ? 1 : -1) * 5e-3 * (yaxis[:tick_direction] == :out ? 1.5 : 1.0),
|
yi + (yaxis[:mirror] ? 1 : -1) * 5e-3 * (yaxis[:tick_direction] == :out ? 1.5 : 1.0),
|
||||||
gr_tick_label(yaxis, dv))
|
dv)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -1351,7 +1340,7 @@ function gr_display(sp::Subplot{GRBackend}, w, h, viewport_canvas)
|
|||||||
for (cv, dv) in zip(zticks...)
|
for (cv, dv) in zip(zticks...)
|
||||||
xi, yi = gr_w3tondc(xt, yt, cv)
|
xi, yi = gr_w3tondc(xt, yt, cv)
|
||||||
gr_text(xi + (zaxis[:mirror] ? 1 : -1) * 1e-2 * (zaxis[:tick_direction] == :out ? 1.5 : 1.0),
|
gr_text(xi + (zaxis[:mirror] ? 1 : -1) * 1e-2 * (zaxis[:tick_direction] == :out ? 1.5 : 1.0),
|
||||||
yi, gr_tick_label(zaxis, dv))
|
yi, dv)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
#
|
#
|
||||||
@ -1471,8 +1460,7 @@ function gr_display(sp::Subplot{GRBackend}, w, h, viewport_canvas)
|
|||||||
flip, mirror = gr_set_xticks_font(sp)
|
flip, mirror = gr_set_xticks_font(sp)
|
||||||
for (cv, dv) in zip(xticks...)
|
for (cv, dv) in zip(xticks...)
|
||||||
xi, yi = GR.wctondc(cv, sp[:framestyle] == :origin ? 0 : xor(flip, mirror) ? ymax : ymin)
|
xi, yi = GR.wctondc(cv, sp[:framestyle] == :origin ? 0 : xor(flip, mirror) ? ymax : ymin)
|
||||||
gr_text(xi, yi + (mirror ? 1 : -1) * 5e-3 * (xaxis[:tick_direction] == :out ? 1.5 : 1.0),
|
gr_text(xi, yi + (mirror ? 1 : -1) * 5e-3 * (xaxis[:tick_direction] == :out ? 1.5 : 1.0), dv)
|
||||||
gr_tick_label(xaxis, dv))
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -1482,8 +1470,8 @@ function gr_display(sp::Subplot{GRBackend}, w, h, viewport_canvas)
|
|||||||
for (cv, dv) in zip(yticks...)
|
for (cv, dv) in zip(yticks...)
|
||||||
xi, yi = GR.wctondc(sp[:framestyle] == :origin ? 0 : xor(flip, mirror) ? xmax : xmin, cv)
|
xi, yi = GR.wctondc(sp[:framestyle] == :origin ? 0 : xor(flip, mirror) ? xmax : xmin, cv)
|
||||||
gr_text(xi + (mirror ? 1 : -1) * 1e-2 * (yaxis[:tick_direction] == :out ? 1.5 : 1.0),
|
gr_text(xi + (mirror ? 1 : -1) * 1e-2 * (yaxis[:tick_direction] == :out ? 1.5 : 1.0),
|
||||||
yi,
|
yi, dv)
|
||||||
gr_tick_label(yaxis, dv))
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@ -19,6 +19,12 @@ using UUIDs
|
|||||||
|
|
||||||
# ----------------------------------------------------------------
|
# ----------------------------------------------------------------
|
||||||
|
|
||||||
|
function labelfunc(scale::Symbol, backend::PlotlyBackend)
|
||||||
|
f = scale == :log10 ? x->"10<sup>$x</sup>" : identity
|
||||||
|
# replace dash with \minus (U+2212)
|
||||||
|
x -> replace(f(x), "-" => "−")
|
||||||
|
end
|
||||||
|
|
||||||
function plotly_font(font::Font, color = font.color)
|
function plotly_font(font::Font, color = font.color)
|
||||||
KW(
|
KW(
|
||||||
:family => font.family,
|
:family => font.family,
|
||||||
|
|||||||
@ -176,15 +176,7 @@ function add_pyfixedformatter(cbar, vals::AVec)
|
|||||||
end
|
end
|
||||||
|
|
||||||
function labelfunc(scale::Symbol, backend::PyPlotBackend)
|
function labelfunc(scale::Symbol, backend::PyPlotBackend)
|
||||||
if scale == :log10
|
PyPlot.LaTeXStrings.latexstring ∘ labelfunc_tex(scale)
|
||||||
x -> PyPlot.LaTeXStrings.latexstring("10^{$x}")
|
|
||||||
elseif scale == :log2
|
|
||||||
x -> PyPlot.LaTeXStrings.latexstring("2^{$x}")
|
|
||||||
elseif scale == :ln
|
|
||||||
x -> PyPlot.LaTeXStrings.latexstring("e^{$x}")
|
|
||||||
else
|
|
||||||
x -> PyPlot.LaTeXStrings.latexstring(convert_sci_unicode(x))
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
function py_mask_nans(z)
|
function py_mask_nans(z)
|
||||||
|
|||||||
@ -1068,8 +1068,8 @@ guidefont(ax::Axis) = font(
|
|||||||
)
|
)
|
||||||
|
|
||||||
# ---------------------------------------------------------------
|
# ---------------------------------------------------------------
|
||||||
# converts unicode scientific notation unsupported by pgfplots and gr
|
# converts unicode scientific notation, as returned by Showoff,
|
||||||
# into a format that works
|
# to a tex-like format (supported by gr, pyplot, and gpfplot).
|
||||||
|
|
||||||
function convert_sci_unicode(label::AbstractString)
|
function convert_sci_unicode(label::AbstractString)
|
||||||
unicode_dict = Dict(
|
unicode_dict = Dict(
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user