How to save seaborn plot

You can save the seaborn plot with the following methods. I highly recommend you “Python Crash Course Book” to learn Python.

Method 1: Save Seaborn Plot using Matplotlib

In this method, I will use the Matplotlib library to save the seaborn plot.

# Import the required libraries
import seaborn as sns
from matplotlib import pyplot as plt

# Load the iris dataset
iris = sns.load_dataset("iris")

# Plot the Histogram
sns.histplot(data=iris, x="sepal_width")

# Save the Plot
plt.savefig('plot.png')

Method 2: Using Seaborn

In this method, I will use the seaborn library to save the plot.

# Import the Seaborn library as sns
import seaborn as sns

# Load the iris dataset
iris = sns.load_dataset("iris")

# Plot the Histogram
plot = sns.histplot(data=iris, x="sepal_width")

# Save the plot
plot.figure.savefig("output.png")

Leave a Comment

Your email address will not be published.