2

this is a great heatmap: http://graphics.wsj.com/infectious-diseases-and-vaccines/ I'm trying to do something similar in Seaborn, and wondered if I could take a custom color palette like turn it into a cmap, and then use center in order to skew it?

import seaborn as sns
from matplotlib import pyplot as plt

mypalette = ['#e8f0ff', '#51abff', '#12b74c', '#fffb16', '#ffc044', '#ff9400', '#ff6a00', '#c13300', '#b20c0c']
sns.palplot(sns.color_palette(mypalette))

The closest I can get is something like

plt.figure('hmap')
flights = sns.load_dataset("flights")
flights = flights.pivot("month", "year", "passengers")
ax = sns.heatmap(flights, cmap = mypalette, center = 350)

of course, this palette lacks a gradient. Apologies for the dataset, I realise it isn't skewed, but seemed like a simple one to use.

Jeff S.
  • 87
  • 2
  • 11

1 Answers1

3

Use Listed colors or Linear Segmented Colormap from Matplotlib, eg. like in this question (Discrete legend in seaborn heatmap plot):

myColors = ((0.8, 0.0, 0.0, 1.0), (0.0, 0.8, 0.0, 1.0), (0.0, 0.0, 0.8, 1.0))

cmap = LinearSegmentedColormap.from_list('Custom', myColors, len(myColors))

You can specify your colours using RGB or also hex format. However, seaborn provides many predefined palettes, see https://seaborn.pydata.org/tutorial/color_palettes.html.

My Work
  • 2,143
  • 2
  • 19
  • 47