0

I'm trying to plot a confusion matrix with seaborn. here is my code:

u=['Fire','No Fire']
v=['Fire','No Fire']

plt.figure(figsize=(5,5),dpi=500)

plt.rcParams["font.family"] = "serif"
plt.rcParams["font.serif"] = "Times New Roman"

b=sns.heatmap(cmat,fmt='.2%',annot=True,cmap='RdYlGn',linewidths=.5,yticklabels=u,xticklabels=v)
b.set_yticklabels(u, size = 10)
b.set_xticklabels(v, size = 10)
plt.yticks(weight = 'bold')
plt.xticks(weight = 'bold')


plt.ylabel('Actual',fontsize=18,fontweight='bold')
plt.xlabel('Predicted',fontsize=18,fontweight='bold')
plt.savefig('conf.png', dpi=500,bbox_inches='tight')

When I run this code TP,FN,TN and TN doesn't align center and return a plot like this:

enter image description here

Can anyone help me to solve this?

Trenton McKinney
  • 56,955
  • 33
  • 144
  • 158
  • `NameError: name 'cmat' is not defined` – Trenton McKinney Jun 26 '22 at 17:47
  • This question is not reproducible without **data**. This question needs a [SSCCE](http://sscce.org/). Please see [How to provide a reproducible dataframe](https://stackoverflow.com/q/52413246/7758804), then **[edit] your question**, and paste the clipboard into a code block. Always provide a [mre] **with code, data, errors, current output, and expected output, as [formatted text](https://stackoverflow.com/help/formatting)**. If relevant, plot images are okay. If you don't include an mre, it is likely the question will be downvoted, closed, and deleted. – Trenton McKinney Jun 26 '22 at 17:47
  • 1
    See [code & plot](https://i.stack.imgur.com/C4L7s.png). This issue is not reproducible. Make sure you're using up to date versions of both seaborn and matplotlib. – Trenton McKinney Jun 26 '22 at 17:56

0 Answers0