Skip to content

Commit

Permalink
plot colormap fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
montyvesselinov committed Dec 11, 2024
1 parent 7d6e6ae commit a1ac797
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 23 deletions.
16 changes: 12 additions & 4 deletions src/NMFkPlot.jl
Original file line number Diff line number Diff line change
Expand Up @@ -396,7 +396,7 @@ function plotscatter(x::AbstractArray, y::AbstractArray, aw...; kw...)
plotscatter(vec(x), vec(y), aw...; kw...)
end

function plotscatter(x::AbstractVector, y::AbstractVector, color::AbstractVector=[], size::AbstractVector=[]; quiet::Bool=false, hsize::Measures.AbsoluteLength=5Gadfly.inch, vsize::Measures.AbsoluteLength=5Gadfly.inch, figuredir::AbstractString=".", filename::AbstractString="", title::AbstractString="", xtitle::AbstractString="", ytitle::AbstractString="", line::Bool=false, xmin=nothing, xmax=nothing, ymin=nothing, ymax=nothing, zmin=nothing, zmax=nothing, gm=[], point_size=2Gadfly.pt, key_position::Symbol=:none, keytitle="", polygon=nothing, point_color="red", line_color="gray", line_width::Measures.AbsoluteLength=2Gadfly.pt, dpi=imagedpi)
function plotscatter(x::AbstractVector, y::AbstractVector, color::AbstractVector=[], size::AbstractVector=[]; quiet::Bool=false, hsize::Measures.AbsoluteLength=5Gadfly.inch, vsize::Measures.AbsoluteLength=5Gadfly.inch, figuredir::AbstractString=".", filename::AbstractString="", title::AbstractString="", xtitle::AbstractString="", ytitle::AbstractString="", line::Bool=false, xmin=nothing, xmax=nothing, ymin=nothing, ymax=nothing, zmin=nothing, zmax=nothing, gm=[], point_size=2Gadfly.pt, key_position::Symbol=:right, keytitle="", colormap=Gadfly.Scale.lab_gradient("green","yellow","red"), polygon=nothing, point_color="red", line_color="gray", line_width::Measures.AbsoluteLength=2Gadfly.pt, dpi=imagedpi)
if !isnothing(polygon)
xmin = !isnothing(xmin) ? min(minimumnan(polygon[:,1]), xmin) : minimumnan(polygon[:,1])
xmax = !isnothing(xmax) ? max(maximumnan(polygon[:,1]), xmax) : maximumnan(polygon[:,1])
Expand All @@ -420,10 +420,18 @@ function plotscatter(x::AbstractVector, y::AbstractVector, color::AbstractVector
if length(color) > 0
@assert length(color) == length(x)
if eltype(color) <: Number
zmin = !isnothing(zmin) ? zmin : minimumnan(color)
zmax = !isnothing(zmax) ? zmax : maximumnan(color)
if isnothing(zmin)
zmin = minimumnan(color)
else
color[color .< zmin] .= zmin
end
if isnothing(zmax)
zmax = maximumnan(color)
else
color[color .> zmax] .= zmax
end
zin = .!isnan.(color)
ff = Gadfly.plot(Gadfly.layer(x=x[zin], y=y[zin], color=color[zin], size=size[zin], Gadfly.Theme(highlight_width=0Gadfly.pt, default_color=point_color, point_size=point_size, key_position=key_position)), pm..., one2oneline..., Gadfly.Coord.Cartesian(xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax), Gadfly.Guide.title(title), Gadfly.Guide.XLabel(xtitle), Gadfly.Guide.YLabel(ytitle), Gadfly.Scale.color_continuous(minvalue=zmin, maxvalue=zmax, colormap=Gadfly.Scale.lab_gradient("green","yellow","red")), Gadfly.Guide.ColorKey(title=keytitle), Gadfly.Theme(key_position=key_position), gm...)
ff = Gadfly.plot(Gadfly.layer(x=x[zin], y=y[zin], color=color[zin], size=size[zin], Gadfly.Theme(highlight_width=0Gadfly.pt, default_color=point_color, point_size=point_size, key_position=key_position)), pm..., one2oneline..., Gadfly.Coord.Cartesian(xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax), Gadfly.Guide.title(title), Gadfly.Guide.XLabel(xtitle), Gadfly.Guide.YLabel(ytitle), Gadfly.Scale.color_continuous(minvalue=zmin, maxvalue=zmax, colormap=colormap), Gadfly.Guide.ColorKey(title=keytitle), Gadfly.Theme(key_position=key_position), gm...)
else
palette = Gadfly.parse_colorant(colors)
colormap = function(nc)
Expand Down
35 changes: 17 additions & 18 deletions src/NMFkPlotColors.jl
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ function colormap(colors::AbstractVector{String})
for i = eachindex(colors)
push!(c, parse(Colors.Colorant, colors[i]))
end
cm = [Gadfly.Scale.lab_gradient(c...)]
cm = Gadfly.Scale.lab_gradient(c...)
end

colors = ["red", "blue", "green", "orange", "magenta", "cyan", "brown", "pink", "lime", "navy", "maroon", "yellow", "olive", "springgreen", "teal", "coral", "#e6beff", "beige", "purple", "#4B6F44", "#9F4576"]
Expand Down Expand Up @@ -661,20 +661,19 @@ gist_ncar = [0 0 128;
254 248 254;
255 255 255];

colormap_rbwlong = [Gadfly.Scale.lab_gradient([Colors.RGB{Colors.N0f8}(rbwlong_ncar[i, :]...) for i=1:size(rbwlong_ncar, 1)]...)]
colormap_ncar = [Gadfly.Scale.lab_gradient([Colors.RGB{Colors.N0f8}(rgb_ncar[i, :]./255...) for i=1:size(rgb_ncar, 1)]...)]
colormap_gist = [Gadfly.Scale.lab_gradient([Colors.RGB{Colors.N0f8}(gist_ncar[i, :]./255...) for i=1:size(gist_ncar, 1)]...)]
colormap_hsv2 = [Gadfly.Scale.lab_gradient(Colors.RGB{Colors.N0f8}(42/255, 28/255, 14/255), parse(Colors.Colorant, "coral"), parse(Colors.Colorant, "darkmagenta"), parse(Colors.Colorant, "peachpuff"), parse(Colors.Colorant, "darkblue"), parse(Colors.Colorant, "cyan"), parse(Colors.Colorant, "green"), parse(Colors.Colorant, "yellow"), parse(Colors.Colorant, "red"))]
colormap_hsv = [Gadfly.Scale.lab_gradient(parse(Colors.Colorant, "magenta"), parse(Colors.Colorant, "peachpuff"), parse(Colors.Colorant, "blue"), parse(Colors.Colorant, "cyan"), parse(Colors.Colorant, "green"), parse(Colors.Colorant, "yellow"), parse(Colors.Colorant, "red"))]
colormap_rbw2 = [Gadfly.Scale.lab_gradient(parse(Colors.Colorant, "blue"), parse(Colors.Colorant, "cyan"), parse(Colors.Colorant, "green"), parse(Colors.Colorant, "yellow"), parse(Colors.Colorant, "red"), parse(Colors.Colorant, "darkmagenta"))]
colormap_rbw = [Gadfly.Scale.lab_gradient(parse(Colors.Colorant, "blue"), parse(Colors.Colorant, "cyan"), parse(Colors.Colorant, "green"), parse(Colors.Colorant, "yellow"), parse(Colors.Colorant, "red"))]
colormap_gyr = [Gadfly.Scale.lab_gradient(parse(Colors.Colorant, "green"), parse(Colors.Colorant, "yellow"), parse(Colors.Colorant, "red"))]
colormap_gy = [Gadfly.Scale.lab_gradient(parse(Colors.Colorant, "green"), parse(Colors.Colorant, "yellow"))]
colormap_ry = [Gadfly.Scale.lab_gradient(parse(Colors.Colorant, "red"), parse(Colors.Colorant, "yellow"))]
colormap_by = [Gadfly.Scale.lab_gradient(parse(Colors.Colorant, "blue"), parse(Colors.Colorant, "yellow"))]
colormap_g = [Gadfly.Scale.lab_gradient(parse(Colors.Colorant, "lightgreen"), parse(Colors.Colorant, "green"))]
colormap_r = [Gadfly.Scale.lab_gradient(parse(Colors.Colorant, "pink"), parse(Colors.Colorant, "red"))]
colormap_b = [Gadfly.Scale.lab_gradient(parse(Colors.Colorant, "lightblue"), parse(Colors.Colorant, "blue"))]
colormap_array_rgb = [colormap_r, colormap_b, colormap_g]
colormap_wb = [Gadfly.Scale.lab_gradient(parse(Colors.Colorant, "white"), parse(Colors.Colorant, "black"))]
# colormap_g_ = [Gadfly.Scale.lab_gradient(Colors.RGBA{Colors.N0f8}(0,1,0,0), Colors.RGBA{Colors.N0f8}(0,1,0,1))]
colormap_rbwlong = Gadfly.Scale.lab_gradient([Colors.RGB{Colors.N0f8}(rbwlong_ncar[i, :]...) for i=1:size(rbwlong_ncar, 1)]...)
colormap_ncar = Gadfly.Scale.lab_gradient([Colors.RGB{Colors.N0f8}(rgb_ncar[i, :]./255...) for i=1:size(rgb_ncar, 1)]...)
colormap_gist = Gadfly.Scale.lab_gradient([Colors.RGB{Colors.N0f8}(gist_ncar[i, :]./255...) for i=1:size(gist_ncar, 1)]...)
colormap_hsv2 = Gadfly.Scale.lab_gradient(Colors.RGB{Colors.N0f8}(42/255, 28/255, 14/255), parse(Colors.Colorant, "coral"), parse(Colors.Colorant, "darkmagenta"), parse(Colors.Colorant, "peachpuff"), parse(Colors.Colorant, "darkblue"), parse(Colors.Colorant, "cyan"), parse(Colors.Colorant, "green"), parse(Colors.Colorant, "yellow"), parse(Colors.Colorant, "red"))
colormap_hsv = Gadfly.Scale.lab_gradient(parse(Colors.Colorant, "magenta"), parse(Colors.Colorant, "peachpuff"), parse(Colors.Colorant, "blue"), parse(Colors.Colorant, "cyan"), parse(Colors.Colorant, "green"), parse(Colors.Colorant, "yellow"), parse(Colors.Colorant, "red"))
colormap_rbw2 = Gadfly.Scale.lab_gradient(parse(Colors.Colorant, "blue"), parse(Colors.Colorant, "cyan"), parse(Colors.Colorant, "green"), parse(Colors.Colorant, "yellow"), parse(Colors.Colorant, "red"), parse(Colors.Colorant, "darkmagenta"))
colormap_rbw = Gadfly.Scale.lab_gradient(parse(Colors.Colorant, "blue"), parse(Colors.Colorant, "cyan"), parse(Colors.Colorant, "green"), parse(Colors.Colorant, "yellow"), parse(Colors.Colorant, "red"))
colormap_gyr = Gadfly.Scale.lab_gradient(parse(Colors.Colorant, "green"), parse(Colors.Colorant, "yellow"), parse(Colors.Colorant, "red"))
colormap_gy = Gadfly.Scale.lab_gradient(parse(Colors.Colorant, "green"), parse(Colors.Colorant, "yellow"))
colormap_ry = Gadfly.Scale.lab_gradient(parse(Colors.Colorant, "red"), parse(Colors.Colorant, "yellow"))
colormap_by = Gadfly.Scale.lab_gradient(parse(Colors.Colorant, "blue"), parse(Colors.Colorant, "yellow"))
colormap_g = Gadfly.Scale.lab_gradient(parse(Colors.Colorant, "lightgreen"), parse(Colors.Colorant, "green"))
colormap_r = Gadfly.Scale.lab_gradient(parse(Colors.Colorant, "pink"), parse(Colors.Colorant, "red"))
colormap_b = Gadfly.Scale.lab_gradient(parse(Colors.Colorant, "lightblue"), parse(Colors.Colorant, "blue"))
colormap_wb = Gadfly.Scale.lab_gradient(parse(Colors.Colorant, "white"), parse(Colors.Colorant, "black"))
# colormap_g_ = Gadfly.Scale.lab_gradient(Colors.RGBA{Colors.N0f8}(0,1,0,0), Colors.RGBA{Colors.N0f8}(0,1,0,1))]
2 changes: 1 addition & 1 deletion src/NMFkPlotMatrix.jl
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ function plotmatrix(X::AbstractMatrix; minmax_cutoff::Number=0.0, minmax_dx::Num
else
cs = [Gadfly.Guide.ColorKey(title=key_title)]
end
cm = isnothing(colormap) ? [] : [Gadfly.Scale.ContinuousColorScale(colormap..., minvalue=minvalue, maxvalue=maxvalue)]
cm = isnothing(colormap) ? [] : [Gadfly.Scale.ContinuousColorScale(colormap, minvalue=minvalue, maxvalue=maxvalue)]
cs = isnothing(colormap) ? [] : cs

if permute
Expand Down

0 comments on commit a1ac797

Please sign in to comment.