12

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,770
  • 9
  • 42
  • 73

2 Answers2

11

seaborn heatmap has the option square:

heatmap(data, square=True)
Olivetree
  • 415
  • 1
  • 4
  • 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
  • 321,279
  • 53
  • 665
  • 712