Menu

#304 narrow a color palette

open
nobody
None
5
2025-06-24
2025-06-19
No

Hey,
I would like to narrow down a colour palette to use only a certain color range.
For example for viridis, which goes from dark blue to turquoise to yellow. I would like to have my data only in turquoise to yellow.
Of course there's the obvious way of just redefining the palette.
Also possible: if my data ranges from 0-10, I could set the cb range from -10:10 and have the wanted effect, but then my colorbox would be from -10:10 as well (which would be sufficient to cover 0:10).
So, my question could also be asked as: is there a way to control the range shown in the colorbox and the range of the palette individually, or they both are exclusively controlled via the cb range?

Thanks,
Alex

Discussion

  • Ethan Merritt

    Ethan Merritt - 2025-06-19

    set cbrange maps the entire palette onto some range of values. There is no single command that will map only a portion of the palette. You can, however, expand a portion of the existing palette to replace the whole thing, which would satisfy your starting example of using only the top half of the viridis palette:

    set palette viridis
    set colormap new vtop
    do for [i=1:256] { vtop[i] = vtop[128 + i/2] }
    set palette colormap vtop
    set cbrange [0:10]
    

    Does that help?

     
  • Alexander Stangl

    Dear Ethan,
    thanks a lot, that's what I was looking for!

     

    Last edit: Alexander Stangl 2025-06-24

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.