How to save a Seaborn plot into a file

后端 未结 10 1049
庸人自扰
庸人自扰 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:16

    Its also possible to just create a matplotlib figure object and then use plt.savefig(...):

    from matplotlib import pyplot as plt
    import seaborn as sns
    import pandas as pd
    
    df = sns.load_dataset('iris')
    plt.figure() # Push new figure on stack
    sns_plot = sns.pairplot(df, hue='species', size=2.5)
    plt.savefig('output.png') # Save that figure
    

提交回复
热议问题