pyplot heatmaps working; ColorGradient fix
This commit is contained in:
parent
581fdfdfe0
commit
2e6b8a067d
@ -176,7 +176,7 @@ function getPyPlotFunction(plt::Plot, axis::Symbol, linetype::Symbol)
|
||||
:scatter3d => :scatter,
|
||||
:surface => :plot_surface,
|
||||
:wireframe => :plot_wireframe,
|
||||
:heatmap => :imshow,
|
||||
:heatmap => :pcolor,
|
||||
# :surface => pycolors.pymember("LinearSegmentedColormap")[:from_list]
|
||||
)
|
||||
return ax[get(fmap, linetype, :plot)]
|
||||
@ -373,9 +373,6 @@ function _add_series(pkg::PyPlotPackage, plt::Plot; kw...)
|
||||
|
||||
elseif lt == :heatmap
|
||||
extra_kwargs[:cmap] = getPyPlotColorMap(d[:fillcolor], d[:fillalpha])
|
||||
left, right = extrema(d[:x])
|
||||
bottom, top = extrema(d[:y])
|
||||
extra_kwargs[:extent] = left, right, bottom, top
|
||||
|
||||
else
|
||||
|
||||
@ -425,7 +422,7 @@ function _add_series(pkg::PyPlotPackage, plt::Plot; kw...)
|
||||
# end
|
||||
|
||||
# set these for all types
|
||||
if !(lt in (:contour,:surface,:wireframe))
|
||||
if !(lt in (:contour,:surface,:wireframe,:heatmap))
|
||||
if !(lt in (:scatter, :scatter3d))
|
||||
extra_kwargs[:color] = color
|
||||
extra_kwargs[:linewidth] = d[:linewidth]
|
||||
@ -474,7 +471,8 @@ function _add_series(pkg::PyPlotPackage, plt::Plot; kw...)
|
||||
plotfunc(d[:x], d[:y]; extra_kwargs...)
|
||||
|
||||
elseif lt == :heatmap
|
||||
plotfunc(d[:z]; extra_kwargs...)
|
||||
x, y, z = d[:x], d[:y], d[:z].surf'
|
||||
plotfunc(heatmap_edges(x), heatmap_edges(y), z; extra_kwargs...)
|
||||
|
||||
else # plot
|
||||
plotfunc(d[:x], d[:y]; extra_kwargs...)[1]
|
||||
@ -798,7 +796,7 @@ function addPyPlotLegend(plt::Plot, ax)
|
||||
leg = plt.plotargs[:legend]
|
||||
if leg != :none
|
||||
# gotta do this to ensure both axes are included
|
||||
args = filter(x -> !(x[:linetype] in (:hist,:density,:hexbin,:hist2d,:hline,:vline,:contour, :surface, :wireframe, :path3d, :scatter3d)), plt.seriesargs)
|
||||
args = filter(x -> !(x[:linetype] in (:hist,:density,:hexbin,:hist2d,:hline,:vline,:contour,:surface,:wireframe,:heatmap,:path3d,:scatter3d)), plt.seriesargs)
|
||||
args = filter(x -> x[:label] != "", args)
|
||||
if length(args) > 0
|
||||
leg = ax[:legend]([d[:serieshandle] for d in args],
|
||||
|
||||
@ -72,10 +72,10 @@ const _testColors = [colorant"darkblue", colorant"blueviolet", colorant"darkcya
|
||||
|
||||
"Continuous gradient between values. Wraps a list of bounding colors and the values they represent."
|
||||
immutable ColorGradient <: ColorScheme
|
||||
colors::Vector{Colorant}
|
||||
values::Vector{Float64}
|
||||
colors::Vector
|
||||
values::Vector
|
||||
|
||||
function ColorGradient{T<:Colorant,S<:Real}(cs::AVec{T}, vals::AVec{S} = linspace(0, 1, length(cs)); alpha = nothing)
|
||||
function ColorGradient{S<:Real}(cs::AVec, vals::AVec{S} = linspace(0, 1, length(cs)); alpha = nothing)
|
||||
if length(cs) == length(vals)
|
||||
return new(convertColor(cs,alpha), collect(vals))
|
||||
end
|
||||
@ -103,13 +103,13 @@ function ColorGradient{T<:Real}(s::Symbol, vals::AVec{T} = 0:0; kw...)
|
||||
ColorGradient(cs, vals; kw...)
|
||||
end
|
||||
|
||||
function ColorGradient{T<:Real}(cs::AVec, vals::AVec{T} = linspace(0, 1, length(cs)); kw...)
|
||||
ColorGradient(map(convertColor, cs), vals; kw...)
|
||||
end
|
||||
# function ColorGradient{T<:Real}(cs::AVec, vals::AVec{T} = linspace(0, 1, length(cs)); kw...)
|
||||
# ColorGradient(map(convertColor, cs), vals; kw...)
|
||||
# end
|
||||
|
||||
function ColorGradient(grad::ColorGradient; alpha = nothing)
|
||||
ColorGradient(convertColor(grad.colors, alpha), grad.values)
|
||||
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))]
|
||||
|
||||
|
||||
@ -181,6 +181,13 @@ Base.first(x::Symbol) = x
|
||||
|
||||
sortedkeys(d::Dict) = sort(collect(keys(d)))
|
||||
|
||||
"create an (n+1) list of the outsides of heatmap rectangles"
|
||||
function heatmap_edges(v::AVec)
|
||||
vmin, vmax = extrema(v)
|
||||
extra = 0.5 * (vmax-vmin) / (length(v)-1)
|
||||
vcat(vmin-extra, 0.5 * (v[1:end-1] + v[2:end]), vmax+extra)
|
||||
end
|
||||
|
||||
|
||||
function fakedata(sz...)
|
||||
y = zeros(sz...)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user