labelfunc for pyplot
This commit is contained in:
parent
6a97dc8825
commit
c1c97a5fc1
12
src/axes.jl
12
src/axes.jl
@ -133,14 +133,12 @@ const _label_func = Dict{Symbol,Function}(
|
|||||||
:log10 => x -> "10^$x",
|
:log10 => x -> "10^$x",
|
||||||
:log2 => x -> "2^$x",
|
:log2 => x -> "2^$x",
|
||||||
:ln => x -> "e^$x",
|
:ln => x -> "e^$x",
|
||||||
# :log2 => exp2,
|
|
||||||
# :ln => exp,
|
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
scalefunc(scale::Symbol) = x -> get(_scale_funcs, scale, identity)(Float64(x))
|
scalefunc(scale::Symbol) = x -> get(_scale_funcs, scale, identity)(Float64(x))
|
||||||
invscalefunc(scale::Symbol) = x -> get(_inv_scale_funcs, scale, identity)(Float64(x))
|
invscalefunc(scale::Symbol) = x -> get(_inv_scale_funcs, scale, identity)(Float64(x))
|
||||||
labelfunc(scale::Symbol) = get(_label_func, scale, string)
|
labelfunc(scale::Symbol, backend::AbstractBackend) = get(_label_func, scale, string)
|
||||||
|
|
||||||
function optimal_ticks_and_labels(axis::Axis, ticks = nothing)
|
function optimal_ticks_and_labels(axis::Axis, ticks = nothing)
|
||||||
lims = axis_limits(axis)
|
lims = axis_limits(axis)
|
||||||
@ -155,7 +153,7 @@ function optimal_ticks_and_labels(axis::Axis, ticks = nothing)
|
|||||||
optimize_ticks(scaled_lims...,
|
optimize_ticks(scaled_lims...,
|
||||||
k_min = 5, # minimum number of ticks
|
k_min = 5, # minimum number of ticks
|
||||||
k_max = 8, # maximum number of ticks
|
k_max = 8, # maximum number of ticks
|
||||||
span_buffer = 0.0 # padding buffer in case nice ticks are closeby
|
# span_buffer = 0.0 # padding buffer in case nice ticks are closeby
|
||||||
)[1]
|
)[1]
|
||||||
else
|
else
|
||||||
ticks
|
ticks
|
||||||
@ -166,7 +164,11 @@ function optimal_ticks_and_labels(axis::Axis, ticks = nothing)
|
|||||||
|
|
||||||
# rescale and return values and labels
|
# rescale and return values and labels
|
||||||
# @show cv
|
# @show cv
|
||||||
ticklabels = map(labelfunc(scale), Showoff.showoff(cv, :plain))
|
ticklabels = if any(isfinite, cv)
|
||||||
|
map(labelfunc(scale, backend()), Showoff.showoff(cv, :plain))
|
||||||
|
else
|
||||||
|
UTF8String[]
|
||||||
|
end
|
||||||
|
|
||||||
tickvals = map(invscalefunc(scale), cv)
|
tickvals = map(invscalefunc(scale), cv)
|
||||||
# @show tickvals ticklabels
|
# @show tickvals ticklabels
|
||||||
|
|||||||
@ -191,7 +191,7 @@ function plotly_axis(axis::Axis, sp::Subplot)
|
|||||||
|
|
||||||
# ticks
|
# ticks
|
||||||
ticks = get_ticks(axis)
|
ticks = get_ticks(axis)
|
||||||
if ticks != :auto
|
if ticks != :auto && ax[:type] != "-"
|
||||||
ttype = ticksType(ticks)
|
ttype = ticksType(ticks)
|
||||||
if ttype == :ticks
|
if ttype == :ticks
|
||||||
ax[:tickmode] = "array"
|
ax[:tickmode] = "array"
|
||||||
|
|||||||
@ -54,6 +54,7 @@ function _initialize_backend(::PyPlotBackend)
|
|||||||
# solution: hack from @stevengj: https://github.com/stevengj/PyPlot.jl/pull/223#issuecomment-229747768
|
# solution: hack from @stevengj: https://github.com/stevengj/PyPlot.jl/pull/223#issuecomment-229747768
|
||||||
otherdisplays = splice!(Base.Multimedia.displays, 2:length(Base.Multimedia.displays))
|
otherdisplays = splice!(Base.Multimedia.displays, 2:length(Base.Multimedia.displays))
|
||||||
import PyPlot
|
import PyPlot
|
||||||
|
import LaTeXStrings: latexstring
|
||||||
append!(Base.Multimedia.displays, otherdisplays)
|
append!(Base.Multimedia.displays, otherdisplays)
|
||||||
|
|
||||||
export PyPlot
|
export PyPlot
|
||||||
@ -221,6 +222,18 @@ function add_pyfixedformatter(cbar, vals::AVec)
|
|||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
function labelfunc(scale::Symbol, backend::PyPlotBackend)
|
||||||
|
if scale == :log10
|
||||||
|
x -> latexstring("10^{$x}")
|
||||||
|
elseif scale == :log2
|
||||||
|
x -> latexstring("2^{$x}")
|
||||||
|
elseif scale == :ln
|
||||||
|
x -> latexstring("e^{$x}")
|
||||||
|
else
|
||||||
|
string
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
# ---------------------------------------------------------------------------
|
# ---------------------------------------------------------------------------
|
||||||
|
|
||||||
function fix_xy_lengths!(plt::Plot{PyPlotBackend}, series::Series)
|
function fix_xy_lengths!(plt::Plot{PyPlotBackend}, series::Series)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user