Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What was the default color palette for images in seaborn version 0.2?

A thing I immediately liked about seaborn was that it set the Matplotlib default color palette for images (imshow, pcolormesh, contourf, ...) to a very good one I had not seen before (black-blue-green-brown-pink-purple-white):

plt.contourf(np.random.random((20,20)))

Default contourf plot under seaborn v. 0.2.1

But when I upgraded the package from version 0.21 to 0.3, this default changed to some greyscale:

Default contourf plot under seaborn v. 0.3

What is the default color palette from v. 0.2.1 called and how do I get it back?

like image 903
j08lue Avatar asked Dec 16 '22 00:12

j08lue


2 Answers

The default color palette in seaborn v. 0.2.1 is Dave Green's 'cubehelix' and you can get it back in v. 0.3 via

import seaborn as sns
sns.set(rc={'image.cmap': 'cubehelix'})

A 'brute force' way of finding this out is rolling back to the old version and creating a default plot:

img = plt.contourf(np.random.random((20,20)))
print(img.cmap.name)

In fact, the default in seaborn is defined in this file in the seaborn repo. A look into the Matplotlib sample matplotlibrc file might also help to find the right parameters to adjust.

like image 109
j08lue Avatar answered Dec 17 '22 12:12

j08lue


Just to add to j08lue's answer, the reason it changed is that it's pretty much impossible to choose a single default colormap that is appropriate for all kinds of data, and having a bad color map can cause lots of problems. The hope it that by making the default a grayscale map, it will encourage people to think about their data and choose the right kind of map.

By the way all (most?) matplotlib functions that plot with a colormap will take a cmap keyword argument, i.e. plt.contourf(x, y, z, cmap="cubehelix") will work.

like image 20
mwaskom Avatar answered Dec 17 '22 12:12

mwaskom