close

How to save a Seaborn plot into a file

Hello Guys, How are you all? Hope You all Are Fine. Today We Are Going To learn about How to save a Seaborn plot into a file in Python. So Here I am Explain to you all the possible Methods here.

Without wasting your time, Let’s start This Article.

Table of Contents

How to save a Seaborn plot into a file?

  1. How to save a Seaborn plot into a file?

    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.

  2. save a Seaborn plot into a file

    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.

Method 1

The suggested solutions are incompatible with Seaborn 0.8.1

giving the following errors because the Seaborn interface has changed:

AttributeError: 'AxesSubplot' object has no attribute 'fig'
When trying to access the figure

AttributeError: 'AxesSubplot' object has no attribute 'savefig'
when trying to use the savefig directly as a function

The following calls allow you to access the figure (Seaborn 0.8.1 compatible):

swarm_plot = sns.swarmplot(...)
fig = swarm_plot.get_figure()
fig.savefig(...) 

Method 2

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.

Conclusion

It’s all About this issue. Hope all Methods helped you a lot. Comment below Your thoughts and your queries. Also, Comment below which Method worked for you? Thank You.

Also, Read