Merge pull request #940 from daschw/ds-heatmap-logscale

Avoid non-positive heatmap edges for log axis on GR and PyPlot
This commit is contained in:
Josef Heinen 2017-07-18 01:22:26 -05:00 committed by GitHub
commit dbc7bc4253
3 changed files with 18 additions and 5 deletions

View File

@ -586,7 +586,7 @@ function gr_display(sp::Subplot{GRBackend}, w, h, viewport_canvas)
end end
if st == :heatmap if st == :heatmap
outside_ticks = true outside_ticks = true
x, y = heatmap_edges(series[:x]), heatmap_edges(series[:y]) x, y = heatmap_edges(series[:x], sp[:xaxis][:scale]), heatmap_edges(series[:y], sp[:yaxis][:scale])
xy_lims = x[1], x[end], y[1], y[end] xy_lims = x[1], x[end], y[1], y[end]
expand_extrema!(sp[:xaxis], x) expand_extrema!(sp[:xaxis], x)
expand_extrema!(sp[:yaxis], y) expand_extrema!(sp[:yaxis], y)

View File

@ -768,7 +768,7 @@ function py_add_series(plt::Plot{PyPlotBackend}, series::Series)
end end
if st == :heatmap if st == :heatmap
x, y, z = heatmap_edges(x), heatmap_edges(y), transpose_z(series, z.surf) x, y, z = heatmap_edges(x, sp[:xaxis][:scale]), heatmap_edges(y, sp[:yaxis][:scale]), transpose_z(series, z.surf)
expand_extrema!(sp[:xaxis], x) expand_extrema!(sp[:xaxis], x)
expand_extrema!(sp[:yaxis], y) expand_extrema!(sp[:yaxis], y)

View File

@ -332,11 +332,24 @@ Base.first(x::Symbol) = x
sortedkeys(d::Dict) = sort(collect(keys(d))) sortedkeys(d::Dict) = sort(collect(keys(d)))
const _scale_base = Dict{Symbol, Real}(
:log10 => 10,
:log2 => 2,
:ln => e,
)
"create an (n+1) list of the outsides of heatmap rectangles" "create an (n+1) list of the outsides of heatmap rectangles"
function heatmap_edges(v::AVec) function heatmap_edges(v::AVec, scale::Symbol = :identity)
vmin, vmax = ignorenan_extrema(v) vmin, vmax = ignorenan_extrema(v)
extra = 0.5 * (vmax-vmin) / (length(v)-1) extra_min = extra_max = 0.5 * (vmax-vmin) / (length(v)-1)
vcat(vmin-extra, 0.5 * (v[1:end-1] + v[2:end]), vmax+extra) if scale in _logScales
vmin > 0 || error("The axis values must be positive for a $scale scale")
while vmin - extra_min <= 0
extra_min /= _scale_base[scale]
end
end
vcat(vmin-extra_min, 0.5 * (v[1:end-1] + v[2:end]), vmax+extra_max)
end end