A Better Default Colormap for Matplotlib | SciPy 2015 | Nathaniel Smith and Stéfan van der Walt

By: Enthought

653   2   77486

Uploaded on 07/08/2015

Complete SciPy 2015 Talk & Tutorial Playlist here: http://ow.ly/PHjEN

Comments (11):

By 21    2017-09-20

I think he is talking about the actual false colors being used. I also thought the same thing.

The picture seems to use the "Jet" Matlab colormap, which is pretty bad by many accounts:




Original Thread

By hprotagonist    2017-10-18


here's a great talk about this, in the context of replacing the Jet colormap for matplotlib.

Original Thread

By vanderZwan    2017-10-30

There is the cube-helix approach, but I suspect you're thinking about something else.

The linked talk about the creation of the viridis colour map[0] actually spends a good ten minutes on explaining colour theory, and makes it look very simple in the process.

About ten minutes in it shows the "perceptual colour space" of a typical non-colourblind person. A few minutes later it shows the color spaces for people with various types of colourblindness.

Perhaps one could project one perceptual space into the other in a way that more-or-less preserves the original information, but essentially with more banding?

[0] https://www.youtube.com/watch?v=xAoljeRJ3lU

Original Thread

By anonymous    2017-09-20

As you noted in a comment, your scatter and contour data are not directly related, but you want to display them on the same colormap.

I suggest setting a common colour span that contains both sets of data. Since obsData refers to the scatter points and areaData to the contours, I'd set

vmin,vmax = (fun(np.concatenate([obsData,areaData])) for fun in (np.min,np.max))

to determine the span of the collected data set (obviously, to be generalized for multiple input data sets). These can be passed to scatter and contourf to set the limits of the colour mapping:

cs = m[0].scatter(xs,ys,c=obsData,cmap=plt.cm.viridis,vmin=vmin,vmax=vmax)
cs2 = m[1].contourf(x,y,areaData,cmap=cs.cmap,vmin=vmin,vmax=vmax)

Some manual increase of the span might be in order to obtain a pretty result.

Note that I changed the colormap to viridis. If you really want to fairly represent your data, this should be your first step.

Original Thread

By anonymous    2017-09-20

There is also a rather "new" way of obtaining an optimal distinctive color palette, also with regards to color blindness and possible black and white conversion with the Viridis color palettes.

To get the palette, simply install the package and use the function viridis_pal()

viridis_pal(option = "D")(n)  # n = number of colors seeked

With options "A","B","C" and "D" to choose between these palettes:

[EDIT: I'm not allowed to post more than two links because of not enough reputation points, I'll update with more images if I get upvotes...]

For more examples visit the package's vignette. Some of the beautiful examples for it:

enter image description here

There is also an excellent talk explaining the complexity of good palettes on YouTube:

A Better Default Colormap for Matplotlib | SciPy 2015 | Nathaniel Smith and Stéfan van der Walt

Original Thread

By anonymous    2017-12-11

Given what you've shown of nn, it looks like the corresponding values are in order. Therefore, I think you could convert your list to a 2D NumPy array

values = np.array(values).reshape((19, 4978))

and then plot them using plt.imshow(values). For example,

import numpy as np
import matplotlib.pyplot as plt

# generate some random values
values = np.random.random(19*4978).tolist()

# convert the list to a 2D NumPy array
values = np.array(values).reshape((19, 4978))
h, w = values.shape

fig, ax = plt.subplots()
plt.yticks(np.arange(h), list('PNIYLKCVFWABCDEFGHI'))

enter image description here

Note that while the default colormap, viridis, is not as colorful as the example you drew, it does have some very interesting features. Perhaps the most important is that the "intensity" of the colors correspond well to a monotonically increasing scale. Thus you can intuitively "read off" the value represented by the colors in the plot. The same could not be said of a plot using the colorful jet colormap, or a colormap like the one you proposed where 1--10 is colored red and 10--20 is colored blue, etc. The reader would be forced to constantly refer to the colorbar or a legend to check the correspondences between colors and values.

Original Thread

By anonymous    2018-02-12

I meant [this one](https://www.youtube.com/watch?v=xAoljeRJ3lU). Keep in mind, that viridis is shipped and the default-one in matplotlib 2 (is/was external package at the time of the video).

Original Thread

By anonymous    2018-04-08

Not answer your question but please don't use `rainbow`. See more here https://www.climate-lab-book.ac.uk/2014/end-of-the-rainbow/ & this video https://www.youtube.com/watch?v=xAoljeRJ3lU

Original Thread

By anonymous    2018-08-16

@albo22 I'm glad I could help. Tangential to your problem here, but consider using a perceptually uniform colormap such as `viridis`. For a detailed explanation of the problem, [see here](https://www.youtube.com/watch?v=xAoljeRJ3lU) :)

Original Thread

Popular Videos 51

Submit Your Video

If you have some great dev videos to share, please fill out this form.