Choose Colors for Scientific Data Visualization
Some general suggestion
- Choosing color palettes for scientific figures
- Color in Scientific Figures
- Design Tips for Scientists
- 2014, Plos Computational Biology, Ten Simple Rules for Better Figures
Background in color space
- RGB color space
- Mixture of red, green and blue color
- HSB color space
- Hue (色相)
- Saturation (饱和度)
-
Brightness (亮度), some tines also called value or lightness
- See https://www.codeproject.com/Articles/1202772/Color-Topics-for-Programmers
- HSLuv
- A alternative to
HSL, claimed to be more human friendly
- A alternative to
python for color space mapping
- For detailed implementation of such conversion see:
import colorsys
# convert rgb to hsv
colorsys.rgb_to_hsv(0.2, 0.4, 0.4)
# (0.5, 0.5, 0.4)
colorsys.hsv_to_rgb(0.5, 0.5, 0.4)
# (0.2, 0.4, 0.4)
Some useful tricks
- Given rgb colors:
- Change the lightness / saturation
- The easist way may be convert
rgbvalues tohsvvalues, changes/v, than map back to rgb value
- The easist way may be convert
- Take complementary color
- Convert to
hsv, then seth=(h+0.5)%1 - Also see https://stackoverflow.com/questions/40233986/python-is-there-a-function-or-formula-to-find-the-complementary-colour-of-a-rgb
- Convert to
- Interpolate from one color to another
- We shall still convert
rgbtohsv, thenh… - See discussion in https://stackoverflow.com/questions/13488957/interpolate-from-one-color-to-another
- We shall still convert
- Change the lightness / saturation
Color map for visualization
Color Map Requirements
- According to Diverging Color Maps for Scientific Visualization
– The map yields images that are aesthetically pleasing.
– The map has a maximal perceptual resolution.
– Interference with the shading of 3D surfaces is minimal.
– The map is not sensitive to vision deficiencies.
– The order of the colors should be intuitively the same for all people.
– The perceptual interpolation matches the underlying scalars of the map
Claasification of color maps
- qualitative / nominal color maps: discrete, unordered classes
- sequential / ordinal / saturation color maps: hue is nearly fixed, (nearly monochromatic), difference in saturation and lightness indicate numericial difference
- diverging / ratio / bipolar / doubleended color maps: two major color components
- cyclic: change in lightness of two different colors that meet in the middle and beginning/end at an unsaturated color
Collection of perceptually accurate colormaps
- https://colorcet.holoviz.org/
- colorcet, https://github.com/holoviz/colorcet
- https://www.kennethmoreland.com/color-maps/
- https://github.com/1313e/CMasher
Caveats
- https://arxiv.org/abs/1509.03700
- Diverging color map and Mach bands
- Don’t use color map like
jetorhot- 2020, Nature Communication, The misuse of colour in science communication
Examples
Choose which type of color scale to use
- qualitative: bar chart, violin plot, etc. To illustrate contrast, use complementary hues, to illustrate similarity, use analog hues.
- sequential: indicates difference toward one direction, like expression level, frequency, etc
- diverging: indicates difference toward two direction, like Z-score of differentially expressed genes
Customization of color maps
Qualitative
- Choose of discrete colors is rather subjective, which you think is beautiful, you boss may tnink it’s ugly …
- May pick the one you love from ggsci, Wes Anderson Palettes, GeoDataViz-Toolkit, https://pattern-library.economist.com/color.html, or other resources, or anything you want …
Sequential
- Perceptually uniform cmap recommanded by seaborn here
rocket,mako,flare,crest,magma,viridis
- Perceptually uniform cmap by matplotlib
viridis,plasma,inferno,magma,cividis
Diverging
- seaborn
vlag,icefire
- matplotlib
- “
BrBGandRdBuare good options.coolwarmis a good option, but it doesn’t span a wide range of L values”
- “
python examples
- See this notebook
R example
- https://www.nceas.ucsb.edu/sites/default/files/2020-04/colorPaletteCheatsheet.pdf
- pals package
- The author also recommand
coolwarmfor diverging palette
- The author also recommand