Color Range: pick color in range base on values in a vector

If you wrap your color range into a ColorScheme object, then the linear interpolation that you need to convert between wealth and color is already implemented:

julia> using Colors, ColorSchemes

julia> cs = ColorScheme([colorant"yellow", colorant"red"]);

julia> wealth = [1, 12, 45, 2, 129, 10];

julia> colors = get.(Ref(cs), (wealth .- minimum(wealth)) ./ maximum(wealth))
6-element Array{RGB{N0f8},1} with eltype RGB{FixedPointNumbers.N0f8}:
 RGB{N0f8}(1.0,1.0,0.0)
 RGB{N0f8}(1.0,0.914,0.0)
 RGB{N0f8}(1.0,0.659,0.0)
 RGB{N0f8}(1.0,0.992,0.0)
 RGB{N0f8}(1.0,0.008,0.0)
 RGB{N0f8}(1.0,0.929,0.0)
2 Likes