How to save a Seaborn plot into a file

后端 未结 10 1048
庸人自扰
庸人自扰 2020-12-07 08:43

I tried the following code (test_seaborn.py):

import matplotlib
matplotlib.use(\'Agg\')
import matplotlib.pyplot as plt
matplotlib.style.use(\'g         


        
10条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-12-07 09:13

    Some of the above solutions did not work for me. The .fig attribute was not found when I tried that and I was unable to use .savefig() directly. However, what did work was:

    sns_plot.figure.savefig("output.png")
    

    I am a newer Python user, so I do not know if this is due to an update. I wanted to mention it in case anybody else runs into the same issues as I did.

提交回复
热议问题