SCATTERPLOT new color to each marker

Hi

I want to make a scatterplot, where each marker has an unique color.

Consider this code:

xVals = []
yVals = []
cellVals = []
cols = []

my_function()  # this function will fill up xVals, yVals, and cellVals

mx = max(cellVals ...)
mn = min(cellVals ...)
df = mx - mn

P = plot()

for cNum in size(xVals)[1] : -1 :1
	
	v = cellVals[cNum]
	dv = v - mn
	dv = dv * 1 / df
	rd = dv
	bl = 1 - dv 
	push!(cols, RGB(rd,0,bl))
	
end
plot!(P, xVals, yVals, seriestype = :scatter, aspect_ratio = 1, c=cols)
display(P)

This fails with error message :

ERROR: MethodError: no method matching plot_color(::Tuple{Float64, Int64, Float64})
Closest candidates are:
plot_color(::Any, ::Nothing) at ~/.julia/packages/PlotUtils/NE7U1/src/colors.jl:20
plot_color(::Any, ::Number) at ~/.julia/packages/PlotUtils/NE7U1/src/colors.jl:23
plot_color(::Colorant) at ~/.julia/packages/PlotUtils/NE7U1/src/colors.jl:15

Stacktrace:
[1] get_series_color(c::Tuple{Float64, Int64, Float64}, sp::Plots.Subplot{Plots.GRBackend}, n::Int64, seriestype::Symbol)
@ Plots ~/.julia/packages/Plots/yJrrq/src/args.jl:2081
[2] (::Plots.var"#116#117"{Plots.Subplot{Plots.GRBackend}, Int64, Symbol})(x::Tuple{Float64, Int64, Float64})
@ Plots ~/.julia/packages/Plots/yJrrq/src/args.jl:2085
[3] iterate
@ ./generator.jl:47 [inlined]
[4] _collect(c::Vector{Any}, itr::Base.Generator{Vector{Any}, Plots.var"#116#117"{Plots.Subplot{Plots.GRBackend}, Int64, Symbol}}, #unused#::Base.EltypeUnknown, isz::Base.HasShape{1})
@ Base ./array.jl:744
[5] collect_similar
@ ./array.jl:653 [inlined]
[6] map
@ ./abstractarray.jl:2867 [inlined]
[7] get_series_color(c::Vector{Any}, sp::Plots.Subplot{Plots.GRBackend}, n::Int64, seriestype::Symbol)
@ Plots ~/.julia/packages/Plots/yJrrq/src/args.jl:2084
[8] _update_series_attributes!(plotattributes::RecipesPipeline.DefaultsDict, plt::Plots.Plot{Plots.GRBackend}, sp::Plots.Subplot{Plots.GRBackend})
@ Plots ~/.julia/packages/Plots/yJrrq/src/args.jl:2166
[9] add_series!(plt::Plots.Plot{Plots.GRBackend}, plotattributes::RecipesPipeline.DefaultsDict)
@ Plots ~/.julia/packages/Plots/yJrrq/src/pipeline.jl:364
[10] _process_seriesrecipe(plt::Any, plotattributes::Any)
@ RecipesPipeline ~/.julia/packages/RecipesPipeline/OXGmH/src/series_recipe.jl:46
[11] _process_seriesrecipes!(plt::Any, kw_list::Any)
@ RecipesPipeline ~/.julia/packages/RecipesPipeline/OXGmH/src/series_recipe.jl:27
[12] recipe_pipeline!(plt::Any, plotattributes::Any, args::Any)
@ RecipesPipeline ~/.julia/packages/RecipesPipeline/OXGmH/src/RecipesPipeline.jl:97
[13] _plot!(plt::Plots.Plot, plotattributes::Any, args::Any)
@ Plots ~/.julia/packages/Plots/yJrrq/src/plot.jl:216
[14] plot!#160
@ ~/.julia/packages/Plots/yJrrq/src/plot.jl:206 [inlined]
[15] top-level scope
@ REPL[8]:1

If i try to use heatmap, like this :

using ColorSchemes
heatmap(xVals, yVals, cellVals, c = :thermal)

also fails with :

Error showing value of type Plots.Plot{Plots.GRBackend}:
ERROR: MethodError: no method matching heatmap_edges(::Vector{Float64}, ::Symbol, ::Vector{Float64}, ::Symbol, ::Tuple{Int64}, ::Bool)
Closest candidates are:
heatmap_edges(::AbstractVector, ::Symbol, ::AbstractVector, ::Symbol, ::Tuple{Int64, Int64}, ::Bool) at ~/.julia/packages/Plots/yJrrq/src/utils.jl:288
heatmap_edges(::AbstractVector, ::Symbol, ::AbstractVector, ::Symbol, ::Tuple{Int64, Int64}) at ~/.julia/packages/Plots/yJrrq/src/utils.jl:288
heatmap_edges(::AbstractVector, ::Symbol) at ~/.julia/packages/Plots/yJrrq/src/utils.jl:278

Stacktrace:
[1] gr_add_series(sp::Plots.Subplot{Plots.GRBackend}, series::Plots.Series)
@ Plots ~/.julia/packages/Plots/yJrrq/src/backends/gr.jl:1897
[2] gr_display(sp::Plots.Subplot{Plots.GRBackend}, w::Measures.AbsoluteLength, h::Measures.AbsoluteLength, viewport_canvas::Vector{Float64})
@ Plots ~/.julia/packages/Plots/yJrrq/src/backends/gr.jl:1034
[3] gr_display(plt::Plots.Plot{Plots.GRBackend}, fmt::String)
@ Plots ~/.julia/packages/Plots/yJrrq/src/backends/gr.jl:699
[4] gr_display
@ ~/.julia/packages/Plots/yJrrq/src/backends/gr.jl:665 [inlined]
[5] _display(plt::Plots.Plot{Plots.GRBackend})
@ Plots ~/.julia/packages/Plots/yJrrq/src/backends/gr.jl:2240
[6] display(#unused#::Plots.PlotsDisplay, plt::Plots.Plot{Plots.GRBackend})
@ Plots ~/.julia/packages/Plots/yJrrq/src/output.jl:164

The content of xVals, yVals and cellVals are all real numbers.

julia> xVals
6846-element Vector{Any}:
0.0195
0.0195
0.019
0.0185
0.0185
0.019
0.019
0.019

-8.673617379884035e-19
0.0004999999999999988
0.0005
0.0005
1.0842021724855044e-19
-0.0005
-0.0005000000000000002
-4.336808689942018e-19

julia> yVals
6846-element Vector{Any}:
0.0002886751345948129
-0.0002886751345948132
-0.0005773502691896261
-0.00028867513459481295
0.000288675134594813
0.0005773502691896261
-0.0005773502691896257
-0.0011547005383792518

0.0011547005383792516
0.0014433756729740647
0.0002886751345948129
-0.0002886751345948128
-0.0005773502691896258
-0.00028867513459481295
0.0002886751345948127
0.0005773502691896258

julia> cellVals
6846-element Vector{Any}:
89
78
37
19
89
128
37
58

19
89
34
60
200
50
19
128

So its not that I am trying to make a heatmap out of imaginary numbers or complex ones.

The only thing that seems to work is this :

P = plot()

for cNum in size(xVals)[1] : -1 :1
	
	v = cellVals[cNum]
	dv = v - mn
	dv = dv * 1 / df
	rd = dv
	bl = 1 - dv 
	push!(cols, (rd,0,bl))
	plot!(P, [xVals[cNum]], [yVals[cNum]], seriestype = :scatter, aspect_ratio = 1, c=RGB(rd,0,bl))
end

display(P)

Ya, I have counted down the array, for no reason.

The result is :

So,basically, i plotted every single marker, where i take its x-Coordinate as a vector with one element, and same with the y-Coordinate. It thus plots as many y-series as there are markers in the plot.

This is not nice.

Is there a better way to achieve an unique color, to each unique marker of a scatterplot, based on the value of an element of an array, where each element is associated to the markers in a 1-to-1 basis ?

Also, how can I move the list of y-series more to the right or turn it off completely, replacing it with a colorbar? Thank you.

Output of versioninfo()

Julia Version 1.7.3
Commit 742b9abb4d* (2022-05-06 12:58 UTC)
Platform Info:
  OS: Linux (x86_64-pc-linux-gnu)
  CPU: Intel(R) Core(TM) i5 CPU       M 540  @ 2.53GHz
  WORD_SIZE: 64
  LIBM: libopenlibm
  LLVM: libLLVM-14.0.6 (ORCJIT, westmere)

Thank you.

I think you are looking for marker_z:

using Plots

scatter([1,4,5], [7,4,8], marker_z = [1,2,3])