From 781fea7431cb29ed6f3f94a0136708af6e332d10 Mon Sep 17 00:00:00 2001 From: yharel Date: Thu, 14 Jun 2018 02:59:04 +0300 Subject: [PATCH 1/4] 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) From dc31cd71037fc080878ba8a915a630880f9d5978 Mon Sep 17 00:00:00 2001 From: yha Date: Sat, 16 Jun 2018 03:10:48 +0300 Subject: [PATCH 2/4] A better heuristic for outer heatmap edges --- src/utils.jl | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/utils.jl b/src/utils.jl index 3a805733..2334d96a 100644 --- a/src/utils.jl +++ b/src/utils.jl @@ -360,7 +360,8 @@ const _scale_base = Dict{Symbol, Real}( function _heatmap_edges(v::AVec) vmin, vmax = ignorenan_extrema(v) - extra_min = extra_max = 0.5 * (vmax-vmin) / (length(v)-1) + extra_min = (v[2] - v[1]) / 2 + extra_max = (v[end] - v[end - 1]) / 2 vcat(vmin-extra_min, 0.5 * (v[1:end-1] + v[2:end]), vmax+extra_max) end From 1e3d10ad318780b3ca9f2432c701efe743d22fa4 Mon Sep 17 00:00:00 2001 From: yha Date: Sat, 16 Jun 2018 03:13:13 +0300 Subject: [PATCH 3/4] GR heatmap: warning for non-equal spacing --- src/backends/gr.jl | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/backends/gr.jl b/src/backends/gr.jl index eae244a9..6c913183 100644 --- a/src/backends/gr.jl +++ b/src/backends/gr.jl @@ -719,7 +719,10 @@ function gr_display(sp::Subplot{GRBackend}, w, h, viewport_canvas) 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.") + v = series[ax[:letter]] + if diff(collect(extrema(diff(v)))) > 1e-6*std(v) + warn("GR: heatmap only supported with equally spaced data.") + end 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] From 00483d4c0d8adea96570b56e192978b3c79e8442 Mon Sep 17 00:00:00 2001 From: yha Date: Sat, 16 Jun 2018 03:13:13 +0300 Subject: [PATCH 4/4] GR heatmap: warning for non-equal spacing --- src/backends/gr.jl | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/backends/gr.jl b/src/backends/gr.jl index eae244a9..65f79042 100644 --- a/src/backends/gr.jl +++ b/src/backends/gr.jl @@ -719,7 +719,10 @@ function gr_display(sp::Subplot{GRBackend}, w, h, viewport_canvas) 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.") + v = series[ax[:letter]] + if diff(collect(extrema(diff(v))))[1] > 1e-6*std(v) + warn("GR: heatmap only supported with equally spaced data.") + end 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]