From 685e2eaff7c3645c5ba5ae724e47fd0cac086e49 Mon Sep 17 00:00:00 2001 From: Daniel Schwabeneder Date: Fri, 6 Apr 2018 10:32:45 +0200 Subject: [PATCH 1/4] implement heatmapr recipe --- src/recipes.jl | 28 ++++++++++++++++++++++++++++ src/series.jl | 2 +- 2 files changed, 29 insertions(+), 1 deletion(-) diff --git a/src/recipes.jl b/src/recipes.jl index 099d9b38..3ece3f9c 100644 --- a/src/recipes.jl +++ b/src/recipes.jl @@ -389,6 +389,34 @@ end end @deps bar shape +# --------------------------------------------------------------------------- +# Heatmap +@recipe function f(::Type{Val{:heatmapr}}, x, y, z) + xe, ye = heatmap_edges(x), heatmap_edges(y) + m, n = size(z.surf) + x_pts, y_pts = fill(NaN, 6 * m * n), fill(NaN, 6 * m * n) + fz = zeros(m * n) + for i in 1:m # y + for j in 1:n # x + k = (j - 1) * m + i + inds = (6 * (k - 1) + 1):(6 * k - 1) + x_pts[inds] .= [xe[j], xe[j + 1], xe[j + 1], xe[j], xe[j]] + y_pts[inds] .= [ye[i], ye[i], ye[i + 1], ye[i + 1], ye[i]] + fz[k] = z.surf[i, j] + end + end + ensure_gradient!(plotattributes, :fillcolor, :fillalpha) + fill_z := fz + linewidth := 0 + linecolor := invisible() + x := x_pts + y := y_pts + z := nothing + seriestype := :shape + label := "" + () +end +@deps heatmapr shape # --------------------------------------------------------------------------- # Histograms diff --git a/src/series.jl b/src/series.jl index 1a502cc5..4c8607fd 100644 --- a/src/series.jl +++ b/src/series.jl @@ -8,7 +8,7 @@ const FuncOrFuncs{F} = Union{F, Vector{F}, Matrix{F}} -all3D(d::KW) = trueOrAllTrue(st -> st in (:contour, :contourf, :heatmap, :surface, :wireframe, :contour3d, :image), get(d, :seriestype, :none)) +all3D(d::KW) = trueOrAllTrue(st -> st in (:contour, :contourf, :heatmap, :surface, :wireframe, :contour3d, :image, :heatmapr), get(d, :seriestype, :none)) # unknown convertToAnyVector(x, d::KW) = error("No user recipe defined for $(typeof(x))") From 8e3bd07c9111348126a5640751882594a71f7c86 Mon Sep 17 00:00:00 2001 From: Daniel Schwabeneder Date: Sat, 7 Apr 2018 14:37:15 +0200 Subject: [PATCH 2/4] set line_z --- src/recipes.jl | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/recipes.jl b/src/recipes.jl index 3ece3f9c..82efc3fa 100644 --- a/src/recipes.jl +++ b/src/recipes.jl @@ -407,8 +407,7 @@ end end ensure_gradient!(plotattributes, :fillcolor, :fillalpha) fill_z := fz - linewidth := 0 - linecolor := invisible() + line_z --> fz x := x_pts y := y_pts z := nothing From 7a702489d03b6b1345450682c8758cafbd783e1d Mon Sep 17 00:00:00 2001 From: Daniel Schwabeneder Date: Sat, 7 Apr 2018 15:54:06 +0200 Subject: [PATCH 3/4] fixes for plotly --- src/backends/plotly.jl | 2 ++ src/recipes.jl | 2 +- src/utils.jl | 9 ++------- 3 files changed, 5 insertions(+), 8 deletions(-) diff --git a/src/backends/plotly.jl b/src/backends/plotly.jl index 9d7126b0..eda984c9 100644 --- a/src/backends/plotly.jl +++ b/src/backends/plotly.jl @@ -669,6 +669,8 @@ function plotly_series_shapes(plt::Plot, series::Series) d_outs[i] = d_out end if series[:fill_z] != nothing + push!(d_outs, plotly_colorbar_hack(series, base_d, :fill)) + elseif series[:line_z] != nothing push!(d_outs, plotly_colorbar_hack(series, base_d, :line)) end d_outs diff --git a/src/recipes.jl b/src/recipes.jl index 82efc3fa..611c8407 100644 --- a/src/recipes.jl +++ b/src/recipes.jl @@ -407,7 +407,7 @@ end end ensure_gradient!(plotattributes, :fillcolor, :fillalpha) fill_z := fz - line_z --> fz + line_z := fz x := x_pts y := y_pts z := nothing diff --git a/src/utils.jl b/src/utils.jl index 80d5487f..b9ab6705 100644 --- a/src/utils.jl +++ b/src/utils.jl @@ -643,17 +643,12 @@ end function get_fillcolor(series, i::Int = 1) fc = series[:fillcolor] fz = series[:fill_z] - lz = series[:line_z] - if fz == nothing && lz == nothing + if fz == nothing isa(fc, ColorGradient) ? fc : _cycle(fc, i) else cmin, cmax = get_clims(series[:subplot]) grad = isa(fc, ColorGradient) ? fc : cgrad() - if fz != nothing - grad[clamp((_cycle(fz, i) - cmin) / (cmax - cmin), 0, 1)] - elseif lz != nothing - grad[clamp((_cycle(lz, i) - cmin) / (cmax - cmin), 0, 1)] - end + grad[clamp((_cycle(fz, i) - cmin) / (cmax - cmin), 0, 1)] end end From af60d03060722772512d190ef2a7ad142d92a841 Mon Sep 17 00:00:00 2001 From: Daniel Schwabeneder Date: Fri, 13 Apr 2018 16:14:03 +0200 Subject: [PATCH 4/4] make alternative plots_heatmap seriestype --- src/Plots.jl | 1 + src/recipes.jl | 6 +++--- src/series.jl | 2 +- 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/src/Plots.jl b/src/Plots.jl index f1026810..aec4ef17 100644 --- a/src/Plots.jl +++ b/src/Plots.jl @@ -183,6 +183,7 @@ include("output.jl") @shorthands histogram2d @shorthands density @shorthands heatmap +@shorthands plots_heatmap @shorthands hexbin @shorthands sticks @shorthands hline diff --git a/src/recipes.jl b/src/recipes.jl index 611c8407..7b389d29 100644 --- a/src/recipes.jl +++ b/src/recipes.jl @@ -390,8 +390,8 @@ end @deps bar shape # --------------------------------------------------------------------------- -# Heatmap -@recipe function f(::Type{Val{:heatmapr}}, x, y, z) +# Plots Heatmap +@recipe function f(::Type{Val{:plots_heatmap}}, x, y, z) xe, ye = heatmap_edges(x), heatmap_edges(y) m, n = size(z.surf) x_pts, y_pts = fill(NaN, 6 * m * n), fill(NaN, 6 * m * n) @@ -415,7 +415,7 @@ end label := "" () end -@deps heatmapr shape +@deps plots_heatmap shape # --------------------------------------------------------------------------- # Histograms diff --git a/src/series.jl b/src/series.jl index 4c8607fd..8b3f19bb 100644 --- a/src/series.jl +++ b/src/series.jl @@ -8,7 +8,7 @@ const FuncOrFuncs{F} = Union{F, Vector{F}, Matrix{F}} -all3D(d::KW) = trueOrAllTrue(st -> st in (:contour, :contourf, :heatmap, :surface, :wireframe, :contour3d, :image, :heatmapr), get(d, :seriestype, :none)) +all3D(d::KW) = trueOrAllTrue(st -> st in (:contour, :contourf, :heatmap, :surface, :wireframe, :contour3d, :image, :plots_heatmap), get(d, :seriestype, :none)) # unknown convertToAnyVector(x, d::KW) = error("No user recipe defined for $(typeof(x))")