How to fix google colab cutting of plots of confusion matrices

╄→гoц情女王★ 提交于 2019-12-10 21:14:26

问题


I'm trying to create a confusion matrix on google colab but once I plot it and try to save it the top and the bottom of the plot get cut off. Is there any way to fix this?

%matplotlib inline
import seaborn as sn
import pandas as pd
import matplotlib.pyplot as plt
from google.colab import files
array =  [[1, 0, 0], 
       [0, 1, 0.0101], 
      [0, 0, 0.9898]]
df_cm = pd.DataFrame(array, index = ["REM", "Wake", "NREM"],
              columns = ["REM", "Wake", "NREM"],)
plt.figure(figsize = (10,7))
sn.heatmap(df_cm, annot=True, cmap="YlGnBu", linewidths=0.5)
plt.savefig("Fid.pdf", bbox_inches='tight')
files.download("Fid.pdf")

Here is the result I'm getting. https://imgur.com/a/Y0RwHis


回答1:


Try reverting back to matplotlib 3.1.0

!pip install matplotlib==3.1.0

Or you can use the pre-release version (3.2.0rc)

!pip install --pre -U matplotlib


来源:https://stackoverflow.com/questions/58791437/how-to-fix-google-colab-cutting-of-plots-of-confusion-matrices

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!