Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Lines to separate groups in seaborn heatmap

I am plotting data as a Seaborn heatmap in Python. My data is intrinsically grouped into categories, and I'd like to have lines on the plot to indicate where the groups lie on the map. As a simple example, suppose I wanted to modify this plot from the documentation...

import seaborn as sns; sns.set()
flights = sns.load_dataset("flights")
flights = flights.pivot("month", "year", "passengers")
ax = sns.heatmap(flights, cbar=False)

enter image description here

Where I wanted to emphasize the comparisons between quarters of the year by making a plot like the one below; how would I do that?

enter image description here

like image 494
T. Carson Avatar asked Sep 06 '16 15:09

T. Carson


People also ask

What is CMAP in heatmap?

You can customize the colors in your heatmap with the cmap parameter of the heatmap() function in seaborn. The following examples show the appearences of different sequential color palettes.

What is FMT in SNS heatmap?

The annot only help to add numeric value on python heatmap cell but fmt parameter allows to add string (text) values on the cell. Here, we created a 2D numpy array which contains string values and passes to annot along with that pass a string value “s” to fmt.


1 Answers

You want ax.hlines:

ax.hlines([3, 6, 9], *ax.get_xlim())

like image 130
Stop harming Monica Avatar answered Nov 18 '22 23:11

Stop harming Monica