问题
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