2

While plotting heatmaps using seaborn, the numbers are getting printed on the boundary of the heatmap. I have already plotted heatmaps many times using the same code. It used to work well but, I'm facing this issue of misalignment.

enter image description here

Code used

#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)
James Z
  • 12,209
  • 10
  • 24
  • 44
  • please, Also post your code which you have used to draw plot. it would be help to understand problem. – Dishin H Goyani Dec 15 '19 at 08:54
  • @DishinHGoyani Thanks for your suggestion. I have added the code snippet. – soham_dhole Dec 15 '19 at 09:04
  • Which version of matplotlib you are using? Try to download last update or downgrade it to 3.1.0 if you are using 3.1.1, there were some issues with boundaries, but I don't know if it is related to your question as well. As I can see, your heatmap is cuted a little bit https://github.com/matplotlib/matplotlib/issues/14675 – timanix Dec 15 '19 at 09:28

1 Answers1

1

Current version of matplotlib broke heatmaps. Downgrade the package to 3.1.0

pip install matplotlib==3.1.0

PS: Copy and paste answer from : datascience.stackexchange as the answer is out of StackOverflow

Dishin H Goyani
  • 7,195
  • 3
  • 26
  • 37