labelfunc for pyplot

This commit is contained in:
Thomas Breloff 2016-07-19 10:32:23 -04:00
parent 6a97dc8825
commit c1c97a5fc1
3 changed files with 21 additions and 6 deletions

View File

@ -133,14 +133,12 @@ const _label_func = Dict{Symbol,Function}(
:log10 => x -> "10^$x",
:log2 => x -> "2^$x",
:ln => x -> "e^$x",
# :log2 => exp2,
# :ln => exp,
)
scalefunc(scale::Symbol) = x -> get(_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)
lims = axis_limits(axis)
@ -155,7 +153,7 @@ function optimal_ticks_and_labels(axis::Axis, ticks = nothing)
optimize_ticks(scaled_lims...,
k_min = 5, # minimum 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]
else
ticks
@ -166,7 +164,11 @@ function optimal_ticks_and_labels(axis::Axis, ticks = nothing)
# rescale and return values and labels
# @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)
# @show tickvals ticklabels

View File

@ -191,7 +191,7 @@ function plotly_axis(axis::Axis, sp::Subplot)
# ticks
ticks = get_ticks(axis)
if ticks != :auto
if ticks != :auto && ax[:type] != "-"
ttype = ticksType(ticks)
if ttype == :ticks
ax[:tickmode] = "array"

View File

@ -54,6 +54,7 @@ function _initialize_backend(::PyPlotBackend)
# solution: hack from @stevengj: https://github.com/stevengj/PyPlot.jl/pull/223#issuecomment-229747768
otherdisplays = splice!(Base.Multimedia.displays, 2:length(Base.Multimedia.displays))
import PyPlot
import LaTeXStrings: latexstring
append!(Base.Multimedia.displays, otherdisplays)
export PyPlot
@ -221,6 +222,18 @@ function add_pyfixedformatter(cbar, vals::AVec)
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)