Figure resizing with large legend different in JupyterLab notebook and in standalone python script

Viewed 14

I am creating a plot which occasionally will have a large legend. I had created a function in JupyterLab notebook and everything looked fine. Now I am trying to use the same function in a standalone script, and suddenly the plot is scaled down to accommodate the large legend. I have tested this - I've run jupyterlab importing the function from the same source as standalone, and again the results are the same. This is a jpeg file created with the jupyterlab enter image description here

And this is the equivalent jpeg file created by standalone script. enter image description here I know that this is the default, but clearly, Jupiter somehow deals with it. Does anyone have any idea how I could replicate what Jupiter does in my standalone script?

The code for the plot in the function:

plt.clf()
ax = sb.lineplot(x=tk['yob'],y=tk['prop'],hue=tk['Prefix'],style=tk['Prefix'],markers=True,linewidth=0.8)
plt.xlabel("Year of birth")
plt.ylim(0,)
plt.xlim(1999,)
plt.legend(bbox_to_anchor=(1.05, 1), loc=2, borderaxespad=0.)
plt.tight_layout()
plt.savefig("trends.jpg", dpi=199)
0 Answers
Related