11

When the cbar is on, the cells in seaborn's heatmap are rectangular. I could change the figsize of my axis, but I am wondering if there is an easier way to keep the cells square.

Demetri Pananos
  • 6,032
  • 6
  • 35
  • 68

2 Answers2

10

seaborn heatmap has the option square:

heatmap(data, square=True)
Olivetree
  • 395
  • 3
  • 8
  • 1
    I tried `square=True` and `ax.set_aspect("equal")` but neither doesn't fix bottom and top rows' units. Any idea how to fix this? – Rylan Schaeffer Jan 23 '20 at 00:43
7

You can use ax.set_aspect("equal") to set an equal aspect ratio for the axes ax.

Example:

import numpy as np
import seaborn as sns
import matplotlib.pyplot as plt

data = np.random.rand(4,16)
ax = sns.heatmap(data)
ax.set_aspect("equal")
plt.show()

enter image description here

ImportanceOfBeingErnest
  • 289,005
  • 45
  • 571
  • 615