Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is a good converging colourmap for matplotlib

When making scatter plots, there are many options for diverging colour maps, that emphasise data at the extrema, but no options for a converging colour map, that emphasises data near the middle of the range. Can anyone suggest one, or tell me why it's a bad idea to use one?

My use case is a scatter plot where each point represents a fit to a different data set, and colour represents the reduced chi squared of the fit. I want to emphasise values close to one, and de-emphasise bad fits.

Edit

Here's my use case in more detail. I'm measuring the performance of an algorithm designed to distinguish between real and systematic signals in time series data (in this case planet transits in Kepler data versus glitches in the data). For each simulation I have an input value, a number describing the algorithm's decision, and a reduced chi squared measuring the goodness of fit. I want to use the colour scheme to highlight the points that have reduced chi squares closest to one, and not the cases where the fit is bad.

There are many ways I could do this (e.g with point size), but I'd like to do it with colour if I can.

like image 383
Fergal Avatar asked May 21 '15 18:05

Fergal


People also ask

What is the default Matplotlib colormap?

The new default colormap used by matplotlib. cm. ScalarMappable instances is 'viridis' (aka option D).

How do you normalize a Colorbar in Python?

will map the data in Z linearly from -1 to +1, so Z=0 will give a color at the center of the colormap RdBu_r (white in this case). Matplotlib does this mapping in two steps, with a normalization from the input data to [0, 1] occurring first, and then mapping onto the indices in the colormap.

What is CMAP viridis?

( cmaps.viridis is a matplotlib.colors.ListedColormap ) import matplotlib.pyplot as plt import matplotlib.image as mpimg import numpy as np import colormaps as cmaps img=mpimg.imread('stinkbug.png') lum_img = np.flipud(img[:,:,0]) imgplot = plt.pcolormesh(lum_img, cmap=cmaps.viridis)


1 Answers

An easy approach is to modify a standard colormap. There's a scipy cookbook page on how to make a colormap transformation, and using the cmap_map function from there, one can do: enter image description hereenter image description here

inv = cmap_map(lambda x: 1-x, cm.PRGn)  # the "transformation" = 1-x

#  plot the original or modified for comparison
x,y=mgrid[1:2,1:10:0.1]
plt.imshow(y, cmap=cm.PRGn)
plt.title("original")
plt.figure()
plt.imshow(y, cmap=inv)
plt.title("inverted")
plt.show()
like image 62
tom10 Avatar answered Oct 13 '22 10:10

tom10