Package: scicomap
buy me caffeineScientific color mapsBlog postScicomap Medium blog post (free)Tutorial notebookInstallationpipinstallscicomapIntroductionScicomap is a package that provides scientific color maps and tools to standardize your favourite color maps if you don't like the built-in ones.
Scicomap currently provides sequential, bi-sequential, diverging, circular, qualitative and miscellaneous color maps. You can easily draw examples, compare the rendering, see how colorblind people will perceive the color maps. I will illustrate the scicomap capabilities below.This package is heavily based on theEvent Horyzon Plot packageand uses good color maps found in thethe python portage of the Fabio Crameri,cmasher,palettable,colorcetandcmoceanMotivationThe accurate representation of data is essential. Many common color maps distort data through uneven colour gradients and are often unreadable to those with color-vision deficiency. An infamous example is the jet color map. These color maps do not render all the information you want to illustrate or even worse render false information through artefacts. Scientist or not, your goal is to communicate visual information in the most accurate and appealing fashion. Moreover, do not overlook colour-vision deficiency, which represents 8% of the (Caucasian) male population.Color spacesPerceptual uniformity is the idea that Euclidean distance between colors in color space should match human color perception distance judgements. For example, a blue and red that are at a distance d apart should look as discriminable as green and purple that are at a distance d apart.
Scicomap uses the CAM02-UCS color space (Uniform Colour Space). Its three coordinates are usually denoted by J', a', and b'. And its cylindrical coordinates are J', C', and h'. The perceptual color space Jab is similar to Lab. However, Jab uses an updated color appearance model that in theory provides greater precision for discriminability measurements.Lightness: also known as value or tone, is a representation of a color's brightnessChroma: the intrinsic difference between a color and gray of an objectHue: the degree to which a stimulus can be described as similar to or different from stimuli that are described as red, green, blue, and yellowEncoding informationLightness J': for a scalar value, intensity. It must vary linearly with the physical quantityhue h' can encode an additional physical quantity, the change of hue should be linearly proportional to the quantity. The hue h' is also ideal in making an image more attractive without interfering with the representation of pixel values.chroma is less recognizable and should not be used to encode physical informationColor map uniformizationFollowing the references and the theories, the uniformization is performed byMaking the color map linear in J'Lifting the color map (making it lighter, i.e. increasing the minimal value of J')Symmetrizing the chroma to avoid further artefactsAvoid kinks and edges in the chroma curveBitonic symmetrization or notScicomapChoosing the right type of color mapsScicomap provides a bunch of color maps for different applications. The different types of color map areimportscicomapasscsc_map=sc.SciCoMap()sc_map.get_ctype()dict_keys(['diverging', 'sequential', 'multi-sequential', 'circular', 'miscellaneous', 'qualitative'])I'll refer to theThe misuse of colour in science communicationfor choosing the right scientific color mapGet the matplotlib cmapplt_cmap_obj=sc_map.get_mpl_color_map()Choosing the color map for a given typeGet the color maps for a given typesc_map=sc.ScicoSequential()sc_map.get_color_map_names()dict_keys(['afmhot', 'amber', 'amber_r', 'amp', 'apple', 'apple_r', 'autumn', 'batlow', 'bilbao', 'bilbao_r', 'binary', 'Blues', 'bone', 'BuGn', 'BuPu', 'chroma', 'chroma_r', 'cividis', 'cool', 'copper', 'cosmic', 'cosmic_r', 'deep', 'dense', 'dusk', 'dusk_r', 'eclipse', 'eclipse_r', 'ember', 'ember_r', 'fall', 'fall_r', 'gem', 'gem_r', 'gist_gray', 'gist_heat', 'gist_yarg', 'GnBu', 'Greens', 'gray', 'Greys', 'haline', 'hawaii', 'hawaii_r', 'heat', 'heat_r', 'hot', 'ice', 'inferno', 'imola', 'imola_r', 'lapaz', 'lapaz_r', 'magma', 'matter', 'neon', 'neon_r', 'neutral', 'neutral_r', 'nuuk', 'nuuk_r', 'ocean', 'ocean_r', 'OrRd', 'Oranges', 'pink', 'plasma', 'PuBu', 'PuBuGn', 'PuRd', 'Purples', 'rain', 'rainbow', 'rainbow-sc', 'rainbow-sc_r', 'rainforest', 'rainforest_r', 'RdPu', 'Reds', 'savanna', 'savanna_r', 'sepia', 'sepia_r', 'speed', 'solar', 'spring', 'summer', 'tempo', 'thermal', 'thermal_r', 'thermal-2', 'tokyo', 'tokyo_r', 'tropical', 'tropical_r', 'turbid', 'turku', 'turku_r', 'viridis', 'winter', 'Wistia', 'YlGn', 'YlGnBu', 'YlOrBr', 'YlOrRd'])Assessing a color mapIn order to assess if a color map should be corrected or not,scicomapprovides a way to quickly check if the lightness is linear, how asymmetric and smooth is the chroma and how the color map renders for color-deficient users. I will illustrate some of the artefacts using classical images, as the pyramid and specific functions for each kind of color map.An infamous exampleimportscicomapasscimportmatplotlib.pyplotasplt# the thing that should not beugly_jet=plt.get_cmap("jet")sc_map=sc.ScicoMiscellaneous(cmap=ugly_jet)f=sc_map.assess_cmap(figsize=(22,10))Clearly, the lightness is not linear, has edges and kinks. The chroma is not smooth and asymmetrical. See the below illustration to see how bad and how many artefacts the jet color map introducesCorrecting a color map - ExampleSequential color mapLet's assess the built-in color maphawaiiwithout correction:sc_map=sc.ScicoSequential(cmap='hawaii')f=sc_map.assess_cmap(figsize=(22,10))The color map seems ok, however, the lightness is not linear and the chroma is asymmetrical even if smooth. Those small defects introduce artefact in the information rendering, as we can visualize using the following examplef=sc_map.draw_example()We can clearly see the artefacts, especially for the pyramid for which our eyes should only pick out the corners in the pyramid (ideal situation). Those artefacts are even more striking for color-deficient users (this might not always be the case). Hopefully,scicomapprovides an easy way to correct those defects:# fixing the color map, using the same minimal lightness (lift=None),# not normalizing to bitone and# smoothing the chromasc_map.unif_sym_cmap(lift=None,bitonic=False,diffuse=True)# re-assess the color map after fixing itf=sc_map.assess_cmap(figsize=(22,10))After fixing the color map, the artefacts are less presentAll the built-in color mapsSequentialDivergingMutli-sequentialMiscellaneousCircularQualitativeReferencesThe misuse of colour in science communicationWhy We Use Bad Color Maps and What You Can Do About ItTHE RAINBOW IS DEAD…LONG LIVE THE RAINBOW! – SERIES OUTLINEScientific colour mapsPicking a colour scale for scientific graphicsColorCETGood Colour Maps: How to Design ThemPerceptually uniform color space for image signals including high dynamic range and wide gamutChanges log1.0.0DocstringTutorial notebookWeb documentation0.4Including files in source distributions0.3Add a section "how to use with matplotlib"[Bug] Center diverging color map in examples0.2[Bug] Fix typo in chart titles0.1First version