我正在嘗試格式化我的子圖,但是由于某種原因,我無法弄清楚為什么所有這些圖的位置都不是平坦的。現在,它們看起來像這樣:

如您所見,我有兩個問題:1. 我不知道如何排除文本標簽(如“日期”)和 2. 我需要格式化子圖以共享相同的軸,因此它們保持對齊。到目前為止我的代碼:
fig = plt.figure(figsize=(25, 15))
ax1 = plt.subplot2grid((23,20), (0,0), colspan=19, rowspan=17)
ax2 = plt.subplot2grid((23,20), (19,0), colspan=19, rowspan=1)
sns.set(font_scale=0.95)
sns.heatmap(pivot, ax= ax1, annot=True, fmt=".0f", robust=True, linewidth=0.1, square=True, cmap="Blues")
sns.heatmap((pd.DataFrame(pivot.sum(axis=0))).transpose(), ax=ax2, annot=True, fmt=".0f", robust=True, linewidth=0.1, square=True, cmap="Blues", xticklabels=False, yticklabels=False)
plt.show()
我的資料框是這樣的:
dates 2020Q1 2020Q2 2020Q3 2020Q4 2021Q1 2021Q2 2021Q3
inicio
2020Q1 56.0 45.0 15.0 7.0 4.0 4.0 3.0
2020Q2 NaN 418.0 277.0 86.0 46.0 33.0 28.0
2020Q3 NaN NaN 619.0 398.0 167.0 122.0 93.0
2020Q4 NaN NaN NaN 1163.0 916.0 521.0 319.0
2021Q1 NaN NaN NaN NaN 976.0 680.0 363.0
2021Q2 NaN NaN NaN NaN NaN 811.0 559.0
2021Q3 NaN NaN NaN NaN NaN NaN 1879.0
uj5u.com熱心網友回復:
- 更改
square=True為square=Falsein
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/317769.html標籤:Python matplotlib 海生 热图 子图
上一篇:如何在3D圖上繪制直方圖?
下一篇:X軸標簽未顯示在條形圖上
