diff --git a/src/Plots.jl b/src/Plots.jl index 8cf0f564..ea7ff92d 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/backends/plotly.jl b/src/backends/plotly.jl index 8578b32e..60168e31 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 75075d02..2393f6a8 100644 --- a/src/recipes.jl +++ b/src/recipes.jl @@ -389,6 +389,33 @@ end end @deps bar shape +# --------------------------------------------------------------------------- +# 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) + 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 + line_z := fz + x := x_pts + y := y_pts + z := nothing + seriestype := :shape + label := "" + () +end +@deps plots_heatmap shape # --------------------------------------------------------------------------- # Histograms diff --git a/src/series.jl b/src/series.jl index 1a502cc5..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), 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))") 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