Flo*_*ops 59 python matplotlib seaborn
When plotting heatmaps with seaborn (and correlation matrices with matplotlib) the first and the last row is cut in halve. This happens also when I run this minimal code example which I found online.
import pandas as pd
import seaborn as sns
import matplotlib.pyplot as plt
data = pd.read_csv('https://raw.githubusercontent.com/resbaz/r-novice-gapminder-files/master/data/gapminder-FiveYearData.csv')
plt.figure(figsize=(10,5))
sns.heatmap(data.corr())
plt.show()
Run Code Online (Sandbox Code Playgroud)
The labels at the y axis are on the correct spot, but the rows aren't completely there.
A few days ago, it work as intended. Since then, I installed texlive-xetex so I removed it again but it didn't solve my problem.
Any ideas what I could be missing?
小智 31
它是3.1.0和3.1.1之间的matplotlib回归中的错误,您可以通过以下方法更正此错误:
import seaborn as sns
df_corr = someDataFrame.corr()
ax = sns.heatmap(df_corr, annot=True) #notation: "annot" not "annote"
bottom, top = ax.get_ylim()
ax.set_ylim(bottom + 0.5, top - 0.5)
Run Code Online (Sandbox Code Playgroud)
小智 14
使用以上方法修复并手动设置了热图限制。
第一
ax = sns.heatmap(...
Run Code Online (Sandbox Code Playgroud)
检查当前轴
ax.get_ylim()
(5.5, 0.5)
Run Code Online (Sandbox Code Playgroud)
固定于
ax.set_ylim(6.0, 0)
Run Code Online (Sandbox Code Playgroud)
小智 5
我通过在我的代码中添加这一行来解决它,使用matplotlib==3.1.1:
ax.set_ylim(sorted(ax.get_xlim(), reverse=True))
注意。这样做的唯一原因是 x 轴没有改变,所以在未来的 mpl 版本中使用风险自负