How to save a Seaborn plot into a file

后端 未结 10 1050
庸人自扰
庸人自扰 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 08:53

    You should just be able to use the savefig method of sns_plot directly.

    sns_plot.savefig("output.png")
    

    For clarity with your code if you did want to access the matplotlib figure that sns_plot resides in then you can get it directly with

    fig = sns_plot.fig
    

    In this case there is no get_figure method as your code assumes.

提交回复
热议问题