web-dev-qa-db-ja.com

Seabornヒートマップのフォントサイズを自動調整

シーボーンヒートマップを使用しているときに、四角形の内側にぴったり収まるようにフォントサイズを自動調整する方法はありますか?たとえば:

sns.heatmap(corrmat, vmin=corrmat.values.min(), vmax=1, square=True, cmap="YlGnBu", 
        linewidths=0.1, annot=True, annot_kws={"size":8})  

ここでサイズは「annot_kws」で設定されます。

19
Gabriel

ヒートマップを歪めますが、この例は、.set(...)コンテキストを使用してフォントを拡大縮小する方法を示しています

import matplotlib.pyplot as plt
import seaborn as sns
sns.set(font_scale=3)

# Load the example flights dataset and conver to long-form
flights_long = sns.load_dataset("flights")
flights = flights_long.pivot("month", "year", "passengers")

# Draw a heatmap with the numeric values in each cell
f, ax = plt.subplots(figsize=(9, 6))
sns.heatmap(flights, annot=True, fmt="d", linewidths=.5, ax=ax)
f.savefig("output.png")
1
djinn

あなたも行うことができます:

sns.heatmap(corrmat, vmin=corrmat.values.min(), vmax=1, square=True, cmap="YlGnBu", linewidths=0.1, annot=True, annot_kws={"fontsize":8})  
1
dex314

seaborn heatmap のフォントサイズを調整するには、いくつかの方法があります

_import seaborn as sns # for data visualization
flight = sns.load_dataset('flights') # load flights datset from GitHub seaborn repository

# reshape flights dataeset in proper format to create seaborn heatmap
flights_df = flight.pivot('month', 'year', 'passengers') 

sns.heatmap(flights_df) # create seaborn heatmap

sns.set(font_scale=2) # font size 2
_

出力>>>

enter image description here

すべてのシーボーングラフラベルのsns.set(font_scale=2) # font size 2セットサイズは、必要に応じて別の方法に従う理由です。

_import seaborn as sns # for data visualization
import matplotlib.pyplot as plt # for data visualization

flight = sns.load_dataset('flights') # load flights datset from GitHub seaborn repository

# reshape flights dataeset in proper format to create seaborn heatmap
flights_df = flight.pivot('month', 'year', 'passengers') 

sns.heatmap(flights_df) # create seaborn heatmap


plt.title('Heatmap of Flighr Dataset', fontsize = 20) # title with fontsize 20
plt.xlabel('Years', fontsize = 15) # x-axis label with fontsize 15
plt.ylabel('Monthes', fontsize = 15) # y-axis label with fontsize 15

plt.show()
_

出力>>>

enter image description here

0
Rudra Mohan