When I try to save my plot working with seaborn, like this:
import seaborn as sn
import pandas as pd
import matplotlib.pyplot as plt
from pylab import savefig
array = [[100,0],
[33,67]]
df_cm = pd.DataFrame(array)
svm = sn.heatmap(df_cm, annot=True,cmap='coolwarm', linecolor='white', linewidths=1)
svm.savefig('svm_conf.png', dpi=400)
I get this error
AttributeError Traceback (most recent call last)
<ipython-input-71-5c0ae9cda020> in <module>()
----> 1 svm.savefig('svm_conf.png', dpi=400)
AttributeError: 'AxesSubplot' object has no attribute 'savefig'
I have saved some boxplots before, with the same code, but this time, it doesn't work.
Matplotlib plots can be saved as image files using the plt. savefig() function.
To save plot figure as JPG or PNG file, call savefig() function on matplotlib. pyplot object. Pass the file name along with extension, as string argument, to savefig() function.
Actually what you would need to do is:
sn.heatmap
See the last 2 lines below:
import seaborn as sn
import pandas as pd
import matplotlib.pyplot as plt
from pylab import savefig
array = [[100,0],
[33,67]]
df_cm = pd.DataFrame(array)
svm = sn.heatmap(df_cm, annot=True,cmap='coolwarm', linecolor='white', linewidths=1)
figure = svm.get_figure()
figure.savefig('svm_conf.png', dpi=400)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With