2017-08-16 37 views
1

我使用seaborn繪製熱圖。但是如果有太多的yticks,其中一些會自動隱藏。其結果是這樣的:
heatmap如果有太多yticks,Seaborn自動隱藏yticks

正如你所看到的,yticks只顯示1,3,5,7 .... 31,33 我怎樣才能讓seaborn或matplotlib全部顯示出來,如:1 ,2,3,4 ..... 31,32,33,34?

我的代碼是:

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

y = np.random.randint(1, 100, 510) 
y = y.reshape((34,15)) 
df = pd.DataFrame(y, columns=[x for x in 'wwwwwwwwwwwwwww'], index=['1','2','3','4','5','6','7','8','9','10','11','12','13','14','15','16','17','18','19','20','21','22','23','24','25','26','27','28','29','30','31','32','33','34']) 
sns.heatmap(df, annot=True) 
plt.yticks(rotation=0) 
plt.show() 

回答

2

Seaborn heatmap提供論據

xticklabels, yticklabels:「自動」,布爾,類似列表或int,可選
如果真,繪製列名的數據幀。如果爲False,則不要繪製列名稱。如果像列表一樣,將這些替代標籤繪製爲xticklabels。如果是整數,則使用列名稱,但只繪製每n個標籤。如果「自動」,嘗試密集地繪製不重疊的標籤。

因此,easies解決方案是添加yticklabels=1作爲參數。

sns.heatmap(df, annot=True, yticklabels=1) 

enter image description here

+0

非常感謝你。這對我來說可以! – sunnwmy