legend overlapping plot area in seaborn

Viewed 4401

enter image description here

I made the plot above using seaborn but I am not able to place the legend outside plot properly. Please note that the legend is cut off on the right side of the image. This is how it looks in real, I did not cut it manually. This is the code I am using:

sns.lineplot(x="Time", y='Anomaly', style='country', hue='region', size='area', sizes=(1., 4), data=df)
# Put the legend out of the figure
plt.subplots_adjust(right=0.2)
plt.legend(bbox_to_anchor=(.95, 1), loc=2, borderaxespad=0.)
plt.tight_layout()
plt.show()

-- EDIT:

here is a data to replicate this issue: https://www.dropbox.com/s/w4gd447e22zb5yk/subset.csv?dl=0

1 Answers

You have not specified a sample set for us to be able to test the implementation and generate the plot, but with a toy initialization, modifying bbox_to_anchor seems to do the trick. See matplotlib's legend guide.

bbox_to_anchor controls manual legend placement. Setting it to (1,1) places it in the top right corner.

plt.legend(bbox_to_anchor=(1, 1), loc=2, borderaxespad=0.)

Sample plot with modification: enter image description here

Related