fix plotly ColorSchemes integration

This commit is contained in:
Daniel Schwabeneder 2020-04-11 18:18:17 +02:00
parent 3152d4b4fe
commit ec5fa44f2a
2 changed files with 14 additions and 8 deletions

View File

@ -350,11 +350,9 @@ function plotly_layout_json(plt::Plot)
end end
function plotly_colorscale(grad::ColorGradient, α) plotly_colorscale(grad::PlotUtils.AbstractColorList, α = nothing) = plotly_colorscale(PlotUtils.color_list(grad), α)
[[grad.values[i], rgba_string(plot_color(grad.colors[i], α))] for i in eachindex(grad.colors)] plotly_colorscale(c::Colorant,α) = plotly_colorscale(_as_gradient(c), α = nothing)
end function plotly_colorscale(c::AbstractVector{<:Colorant}, α = nothing)
plotly_colorscale(c::Colorant,α) = plotly_colorscale(_as_gradient(c),α)
function plotly_colorscale(c::AbstractVector{<:RGBA}, α)
if length(c) == 1 if length(c) == 1
return [[0.0, rgba_string(plot_color(c[1], α))], [1.0, rgba_string(plot_color(c[1], α))]] return [[0.0, rgba_string(plot_color(c[1], α))], [1.0, rgba_string(plot_color(c[1], α))]]
else else

View File

@ -1,8 +1,8 @@
function replace_image_with_heatmap(z::Array{T}) where T<:Colorant function replace_image_with_heatmap(z::Array{T}) where T<:Colorant
n, m = size(z) n, m = size(z)
colors = ColorGradient(vec(z)) colors = palette(vec(z))
newz = reshape(range(0, stop=1, length=n*m), n, m) newz = reshape(1:n*m, n, m)
newz, colors newz, colors
end end
@ -548,7 +548,15 @@ get_gradient(c) = cgrad()
get_gradient(cg::ColorGradient) = cg get_gradient(cg::ColorGradient) = cg
get_gradient(cp::ColorPalette) = cp get_gradient(cp::ColorPalette) = cp
nan_get(cs, x, range) = isfinite(x) ? plot_color(get(cs, x, range)) : invisible() function nan_get(cs, x, range)
if !isfinite(x)
return invisible()
elseif range isa Tuple && range[1] == range[2]
return plot_color(cs[1])
else
plot_color(get(cs, x, range))
end
end
function nan_get(cs, v::AbstractVector, range) function nan_get(cs, v::AbstractVector, range)
colors = fill(invisible(), length(v)) colors = fill(invisible(), length(v))
for (i, x) in enumerate(v) for (i, x) in enumerate(v)