Could not save whole figure of barplot with long yticklabel

94 Views Asked by At

I want to save a barplot, but found it was clipped when save it to a file.

import seaborn as sns
import matplotlib.pyplot as plt

tips = sns.load_dataset("tips")
sns.set_theme(font_scale=1.6)
fig,ax = plt.subplots(figsize=(8,6))
g = sns.barplot(x="tip", y="day", data=tips)
g.set(yticklabels=['Thur','Fri','Sat','Very long long long long Sun'])
fig.savefig('1.png',dpi=400)

Here is the figure shown in jupyter notebook

enter image description here

However, the figure saved was looked like this:

enter image description here

1

There are 1 best solutions below

1
On BEST ANSWER

You should add bbox_index='tight' as a parameter and argument to plt.savefig()

fig.savefig('1.png',dpi=400, bbox_inches='tight')