heatmaps, colorscales, and spy... oh my
This commit is contained in:
parent
6db06857ba
commit
f568803af2
@ -124,8 +124,8 @@ export
|
||||
# recipes
|
||||
PlotRecipe,
|
||||
# EllipseRecipe,
|
||||
# spy,
|
||||
corrplot
|
||||
spy
|
||||
# corrplot
|
||||
|
||||
|
||||
# ---------------------------------------------------------
|
||||
|
||||
@ -249,10 +249,10 @@ function get_plot_json(plt::Plot{PlotlyPackage})
|
||||
end
|
||||
|
||||
|
||||
function plotly_colorscale(grad::ColorGradient)
|
||||
[[grad.values[i], webcolor(grad.colors[i])] for i in 1:length(grad.colors)]
|
||||
function plotly_colorscale(grad::ColorGradient, alpha = nothing)
|
||||
[[grad.values[i], webcolor(grad.colors[i], alpha)] for i in 1:length(grad.colors)]
|
||||
end
|
||||
plotly_colorscale(c) = plotly_colorscale(ColorGradient(:bluesreds))
|
||||
plotly_colorscale(c, alpha = nothing) = plotly_colorscale(ColorGradient(:bluesreds), alpha)
|
||||
|
||||
const _plotly_markers = Dict{Symbol,Any}(
|
||||
:rect => "square",
|
||||
@ -316,16 +316,26 @@ function plotly_series(d::Dict; plot_index = nothing)
|
||||
d_out[:histnorm] = "probability density"
|
||||
end
|
||||
|
||||
elseif lt in (:contour, :surface, :wireframe)
|
||||
d_out[:type] = lt == :wireframe ? :surface : string(lt)
|
||||
elseif lt == :heatmap
|
||||
d_out[:type] = "heatmap"
|
||||
d_out[:x], d_out[:y] = x, y
|
||||
d_out[:z] = d[:z].surf
|
||||
# d_out[:showscale] = d[:legend]
|
||||
if lt == :contour
|
||||
d_out[:ncontours] = d[:levels]
|
||||
d_out[:contours] = Dict{Symbol,Any}(:coloring => d[:fillrange] != nothing ? "fill" : "lines")
|
||||
end
|
||||
d_out[:colorscale] = plotly_colorscale(d[lt == :contour ? :linecolor : :fillcolor])
|
||||
d_out[:colorscale] = plotly_colorscale(d[:fillcolor], d[:fillalpha])
|
||||
|
||||
elseif lt == :contour
|
||||
d_out[:type] = "contour"
|
||||
d_out[:x], d_out[:y] = x, y
|
||||
d_out[:z] = d[:z].surf
|
||||
# d_out[:showscale] = d[:colorbar] != :none
|
||||
d_out[:ncontours] = d[:levels]
|
||||
d_out[:contours] = Dict{Symbol,Any}(:coloring => d[:fillrange] != nothing ? "fill" : "lines")
|
||||
d_out[:colorscale] = plotly_colorscale(d[:linecolor], d[:linealpha])
|
||||
|
||||
elseif lt in (:surface, :wireframe)
|
||||
d_out[:type] = "surface"
|
||||
d_out[:x], d_out[:y] = x, y
|
||||
d_out[:z] = d[:z].surf
|
||||
d_out[:colorscale] = plotly_colorscale(d[:fillcolor], d[:fillalpha])
|
||||
|
||||
elseif lt == :pie
|
||||
d_out[:type] = "pie"
|
||||
@ -360,11 +370,19 @@ function plotly_series(d::Dict; plot_index = nothing)
|
||||
:width => d[:markerstrokewidth],
|
||||
),
|
||||
)
|
||||
|
||||
# gotta hack this (for now?) since plotly can't handle rgba values inside the gradient
|
||||
if d[:zcolor] != nothing
|
||||
d_out[:marker][:color] = d[:zcolor]
|
||||
d_out[:marker][:colorscale] = plotly_colorscale(d[:markercolor])
|
||||
# d_out[:marker][:color] = d[:zcolor]
|
||||
# d_out[:marker][:colorscale] = plotly_colorscale(d[:markercolor], d[:markeralpha])
|
||||
# d_out[:showscale] = true
|
||||
grad = ColorGradient(d[:markercolor], alpha=d[:markeralpha])
|
||||
zmin, zmax = extrema(d[:zcolor])
|
||||
d_out[:marker][:color] = [webcolor(getColorZ(grad, (zi - zmin) / (zmax - zmin))) for zi in d[:zcolor]]
|
||||
end
|
||||
|
||||
end
|
||||
dumpdict(d_out, "", true)
|
||||
|
||||
# add "line"
|
||||
if hasline
|
||||
|
||||
@ -563,7 +563,7 @@ supportedArgs(::PlotlyPackage) = [
|
||||
supportedAxes(::PlotlyPackage) = [:auto, :left]
|
||||
supportedTypes(::PlotlyPackage) = [:none, :line, :path, :scatter, :steppre, :steppost,
|
||||
:hist2d, :hist, :density, :bar, :contour, :surface, :path3d, :scatter3d,
|
||||
:pie] #,, :sticks, :hexbin, :hline, :vline]
|
||||
:pie, :heatmap] #,, :sticks, :hexbin, :hline, :vline]
|
||||
supportedStyles(::PlotlyPackage) = [:auto, :solid, :dash, :dot, :dashdot]
|
||||
supportedMarkers(::PlotlyPackage) = [:none, :auto, :ellipse, :rect, :diamond, :utriangle, :dtriangle, :cross, :xcross,
|
||||
:pentagon, :hexagon, :octagon, :vline, :hline] #vcat(_allMarkers, Shape)
|
||||
@ -633,7 +633,7 @@ supportedArgs(::PlotlyJSPackage) = [
|
||||
supportedAxes(::PlotlyJSPackage) = [:auto, :left]
|
||||
supportedTypes(::PlotlyJSPackage) = [:none, :line, :path, :scatter, :steppre, :steppost,
|
||||
:hist2d, :hist, :density, :bar, :contour, :surface, :path3d, :scatter3d,
|
||||
:pie] #,, :sticks, :hexbin, :hline, :vline]
|
||||
:pie, :heatmap] #,, :sticks, :hexbin, :hline, :vline]
|
||||
supportedStyles(::PlotlyJSPackage) = [:auto, :solid, :dash, :dot, :dashdot]
|
||||
supportedMarkers(::PlotlyJSPackage) = [:none, :auto, :ellipse, :rect, :diamond, :utriangle, :dtriangle, :cross, :xcross,
|
||||
:pentagon, :hexagon, :octagon, :vline, :hline] #vcat(_allMarkers, Shape)
|
||||
|
||||
@ -107,6 +107,10 @@ function ColorGradient{T<:Real}(cs::AVec{Symbol}, vals::AVec{T} = linspace(0, 1,
|
||||
ColorGradient(map(convertColor, cs), vals; kw...)
|
||||
end
|
||||
|
||||
function ColorGradient(grad::ColorGradient; alpha = nothing)
|
||||
ColorGradient(convertColor(grad.colors, alpha), grad.values)
|
||||
end
|
||||
|
||||
getColor(gradient::ColorGradient, idx::Int) = gradient.colors[mod1(idx, length(gradient.colors))]
|
||||
|
||||
function getColorZ(gradient::ColorGradient, z::Real)
|
||||
|
||||
10
src/plot.jl
10
src/plot.jl
@ -228,7 +228,7 @@ end
|
||||
|
||||
typealias FuncOrFuncs @compat(Union{Function, AVec{Function}})
|
||||
|
||||
all3D(d::Dict) = trueOrAllTrue(lt -> lt in (:contour, :surface, :wireframe, :image), get(d, :linetype, :none))
|
||||
all3D(d::Dict) = trueOrAllTrue(lt -> lt in (:contour, :heatmap, :surface, :wireframe), get(d, :linetype, :none))
|
||||
|
||||
# missing
|
||||
convertToAnyVector(v::@compat(Void), d::Dict) = Any[nothing], nothing
|
||||
@ -328,10 +328,10 @@ function createKWargsList(plt::PlottingObject, x, y; kw...)
|
||||
|
||||
lt = d[:linetype]
|
||||
if isa(d[:y], Surface)
|
||||
if lt in (:contour, :surface, :wireframe, :image)
|
||||
if lt in (:contour, :heatmap, :surface, :wireframe)
|
||||
z = d[:y]
|
||||
d[:y] = 1:size(z,2)
|
||||
d[lt == :image ? :zcolor : :z] = z
|
||||
d[:z] = z
|
||||
end
|
||||
end
|
||||
|
||||
@ -429,7 +429,7 @@ function createKWargsList{T<:Real}(plt::PlottingObject, x::AVec, y::AVec, zmat::
|
||||
# surf[1,1] = convert(Matrix{Float64}, zmat)
|
||||
d = Dict(kw)
|
||||
d[:z] = Surface(convert(Matrix{Float64}, zmat))
|
||||
if !(get(d, :linetype, :none) in (:contour, :surface, :wireframe))
|
||||
if !(get(d, :linetype, :none) in (:contour, :heatmap, :surface, :wireframe))
|
||||
d[:linetype] = :contour
|
||||
end
|
||||
createKWargsList(plt, x, y; d...) #, z = surf)
|
||||
@ -443,7 +443,7 @@ function createKWargsList{T<:Real}(plt::PlottingObject, x::AMat{T}, y::AMat{T},
|
||||
# surf[1,1] = convert(Matrix{Float64}, zmat)
|
||||
d = Dict(kw)
|
||||
d[:z] = Surface(convert(Matrix{Float64}, zmat))
|
||||
if !(get(d, :linetype, :none) in (:contour, :surface, :wireframe))
|
||||
if !(get(d, :linetype, :none) in (:contour, :heatmap, :surface, :wireframe))
|
||||
d[:linetype] = :contour
|
||||
end
|
||||
createKWargsList(plt, Any[x], Any[y]; d...) #kw..., z = surf, linetype = :contour)
|
||||
|
||||
@ -125,9 +125,10 @@ end
|
||||
|
||||
|
||||
"Sparsity plot... heatmap of non-zero values of a matrix"
|
||||
function spy{T<:Real}(y::AMat{T}; kw...)
|
||||
I,J,V = findnz(y)
|
||||
heatmap(J, I; leg=false, yflip=true, kw...)
|
||||
function spy{T<:Real}(z::AMat{T}; kw...)
|
||||
# I,J,V = findnz(z)
|
||||
# heatmap(J, I; leg=false, yflip=true, kw...)
|
||||
heatmap(map(zi->float(zi!=0), z); leg=false, yflip=true, kw...)
|
||||
end
|
||||
|
||||
"Adds a+bx... straight line over the current plot"
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user