Gnuplot.jl icon indicating copy to clipboard operation
Gnuplot.jl copied to clipboard

color outsize range of color bar

Open lazarusA opened this issue 4 years ago • 2 comments

Hello, I was trying to include a highclip and a lowclip for values outsize some given cbrange. If I include these values to set palette defined (.... ) I do get a new colorbar which includes the new color, but I would like to keep [plot] just the colorbar without these new values and still apply this extra color to the input array. Any suggestions?

something similar to this implementation: http://makie.juliaplots.org/stable/makielayout/layoutables_examples.html#Colorbar

function palette(cmap::ColorScheme; rev=false, smooth=false, highclip = :nothing, lowclip = :nothing)
    levels = Vector{String}()
    for x in LinRange(0, 0.9, (smooth  ?  256  : length(cmap.colors)))
        if rev
            color = get(cmap, 0.9-x)
        else
            color = get(cmap, x)
        end
        push!(levels, "$x '#" * Colors.hex(color) * "'")
    end
    if highclip == nothing && lowclip == nothing
        return "set palette defined (" * join(levels, ", ") * ")\nset palette maxcol $(length(cmap.colors))\n"
    elseif highclip != nothing
        return "set palette defined (" * join(levels, ", ") * ", 1 '$(highclip)'" * ")\nset palette maxcol $(length(cmap.colors)+1)\n"
    end
end

lazarusA avatar Feb 12 '21 11:02 lazarusA

Well, the effected that I was looking for is achieved just by changing for x in LinRange(0, 0.999, ... ) and get(cmap, 0.999-x), i.e., going closer to 1. Now the last color is imperceptible [still there] but is not distinguishable. I can work with that 😄 .

but cliplow is still a problem.... well it doesn't work for all palettes.... :(

lazarusA avatar Feb 12 '21 11:02 lazarusA

The palette_levels() functions (to be deployed in v.1.4.1) allows to modify the numeric levels before sending them to gnuplot. A simple example (to stretch a colormap) is as follows:

x = 0:0.1:10pi
v, l, n = palette_levels(:viridis)
@gsp palette(v.^0.25, l, n) cbr=[-1,1].*30 :-
@gsp :-  x  x.*sin.(x)  x.*cos.(x)  x./20  "w p pt 7 ps var lc pal"

If I understand correctly, in your case you may achieve the goal both by modifying the palette levels or by changing the color levels given as input. If you provide a complete example we can discuss what is the best approach.

gcalderone avatar Jan 04 '22 11:01 gcalderone