From 781fea7431cb29ed6f3f94a0136708af6e332d10 Mon Sep 17 00:00:00 2001 From: yharel Date: Thu, 14 Jun 2018 02:59:04 +0300 Subject: [PATCH] Heatmap log scale fix --- src/backends/gr.jl | 3 +++ src/backends/plotly.jl | 2 ++ src/utils.jl | 14 ++++++-------- 3 files changed, 11 insertions(+), 8 deletions(-) diff --git a/src/backends/gr.jl b/src/backends/gr.jl index ad235940..eae244a9 100644 --- a/src/backends/gr.jl +++ b/src/backends/gr.jl @@ -718,6 +718,9 @@ function gr_display(sp::Subplot{GRBackend}, w, h, viewport_canvas) end if st == :heatmap outside_ticks = true + for ax in (sp[:xaxis], sp[:yaxis]) + ax[:scale] != :identity && warn("GR: heatmap with $(ax[:scale]) scale not supported.") + end 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] expand_extrema!(sp[:xaxis], x) diff --git a/src/backends/plotly.jl b/src/backends/plotly.jl index 933b78b3..125f8182 100644 --- a/src/backends/plotly.jl +++ b/src/backends/plotly.jl @@ -587,6 +587,8 @@ function plotly_series(plt::Plot, series::Series) return plotly_series_segments(series, d_out, x, y, z) elseif st == :heatmap + x = heatmap_edges(x, sp[:xaxis][:scale]) + y = heatmap_edges(y, sp[:yaxis][:scale]) d_out[:type] = "heatmap" d_out[:x], d_out[:y], d_out[:z] = x, y, z d_out[:colorscale] = plotly_colorscale(series[:fillcolor], series[:fillalpha]) diff --git a/src/utils.jl b/src/utils.jl index 9c085f50..3a805733 100644 --- a/src/utils.jl +++ b/src/utils.jl @@ -358,19 +358,17 @@ const _scale_base = Dict{Symbol, Real}( :ln => e, ) -"create an (n+1) list of the outsides of heatmap rectangles" -function heatmap_edges(v::AVec, scale::Symbol = :identity) +function _heatmap_edges(v::AVec) vmin, vmax = ignorenan_extrema(v) extra_min = extra_max = 0.5 * (vmax-vmin) / (length(v)-1) - 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 +"create an (n+1) list of the outsides of heatmap rectangles" +function heatmap_edges(v::AVec, scale::Symbol = :identity) + f, invf = scalefunc(scale), invscalefunc(scale) + map(invf, _heatmap_edges(map(f,v))) +end function calc_r_extrema(x, y) xmin, xmax = ignorenan_extrema(x)