【问题标题】:Why are numeric values getting printed on the boundary of heatmaps? [duplicate]为什么数值会打印在热图的边界上? [复制]
【发布时间】:2020-04-08 01:55:08
【问题描述】:

使用 seaborn 绘制热图时,数字会打印在热图的边界上。我已经使用相同的代码多次绘制热图。它曾经运行良好,但我正面临这个错位问题。

使用的代码

#Defining a custom function
def get_confusion_matrix(clf,X_te,y_test):
y_pred = clf.predict(X_te)
df_cm = pd.DataFrame(confusion_matrix(y_test, y_pred), range(2),range(2))
df_cm.columns = ['Predicted NO','Predicted YES']
df_cm = df_cm.rename({0: 'Actual NO', 1: 'Actual YES'})
sns.set(font_scale=1.4)#for label size
sns.heatmap(df_cm, annot=True,annot_kws={"size": 16}, fmt='d',cmap="YlGnBu", linewidths=5)


#Using the function to plot the heatmap
get_confusion_matrix(model_s1,X_tr,y_train_1)

【问题讨论】:

  • 请同时发布您用来绘制绘图的代码。这将有助于理解问题。
  • @DishinHGoyani 感谢您的建议。我已经添加了代码 sn-p。
  • 您使用的是哪个版本的 matplotlib?如果您使用的是 3.1.1,请尝试下载上次更新或将其降级到 3.1.0,边界存在一些问题,但我不知道它是否也与您的问题有关。如我所见,您的热图有点可爱github.com/matplotlib/matplotlib/issues/14675

标签: python machine-learning seaborn data-science heatmap


【解决方案1】:

当前版本的 matplotlib 破坏了热图。将包降级到 3.1.0

pip install matplotlib==3.1.0

PS:从datascience.stackexchange复制并粘贴答案,因为答案在 StackOverflow 之外

【讨论】:

    猜你喜欢
    • 2020-01-11
    • 2021-08-31
    • 1970-01-01
    • 2021-12-15
    • 2020-02-28
    • 2012-07-09
    • 2022-06-16
    • 2019-05-31
    • 1970-01-01
    相关资源
    最近更新 更多