Lines to separate groups in seaborn heatmap
14,567
You want ax.hlines
:
ax.hlines([3, 6, 9], *ax.get_xlim())
Related videos on Youtube
Author by
T. Carson
Updated on July 13, 2022Comments
-
T. Carson almost 2 years
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)
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?
-
T. Carson over 7 yearsI figured there had to be a simple answer; drives me nuts when I can't find it. Thank you so much. :)
-
mwaskom over 7 years
ax.axhline
will avoid having to specify the x limits of the line, but you'll have to call it multiple times. -
ilyas almost 6 years@Goyo Is there a way to separate the heatmap at certain locations. So I do not want to draw a line, but rather separate by a tiny distance, think of it as creating islands.
-
Stop harming Monica almost 6 years@ilyas I don't think so but you can slice the data and plot to several subplots.