seaborn heatmap y-axis reverse order

john kals picture john kals · Dec 11, 2015 · Viewed 29k times · Source

Have a look at this heatmap found in the seaborn heatmap documentation.

Right now the y-axis starts with 9 at the bottom, and ends with 0 on top. Is there a way to turn this around, i.e. start with 0 at bottom and end with 9 at the top?

Answer

user3412205 picture user3412205 · Dec 23, 2015

Looks like ax.invert_yaxis() solves it.

Following the example from which you got the figure:

import numpy as np; np.random.seed(0)
import seaborn as sns; sns.set()
uniform_data = np.random.rand(10, 12)
ax = sns.heatmap(uniform_data)
ax.invert_yaxis()

Gives: enter image description here