Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

matplotlib modified color map with white as zero

Some of the standard matplotlib cmaps, such as viridis or jet show dark colors in small values. While this is what I need, I like them to show nothing, i.e. white background if the value is exactly zero. For non zero values the usual colors of that color map are fine.

Is it possible to do this?

like image 895
xaratustra Avatar asked Sep 06 '25 16:09

xaratustra


1 Answers

You would rather mask zero out of your data, e.g. setting those values to nan or use a masked array. Then you can just set_bad("white") for your colormap.

like image 62
ImportanceOfBeingErnest Avatar answered Sep 10 '25 02:09

ImportanceOfBeingErnest