简体   繁体   中英

How can I keep cells square in heatmap?

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.

seaborn 热图有选项square

heatmap(data, square=True)

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()

在此处输入图片说明

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM