0

As a follow up to this question How to put the legend outside the plot in Matplotlib, I'm trying to put my legend outside my Seaborn plot. My simplified code is:

        sns.lineplot(data=df,
                     x='x',
                     y='y',
                     hue='z',
                     palette=some dictionary)
        plt.legend(bbox_to_anchor=(1.05, 1), loc=2, borderaxespad=0.)
        plt.tight_layout()

However, the legend takes over the majority of the figure!

enter image description here

How can I instruct seaborn/matplotlib to not shrink the main figure but instead add as much whitespace as necessary?

Rylan Schaeffer
  • 1,112
  • 13
  • 32
  • 1
    You need to set a smaller font for the legend, and/or set a larger figsize. The legend just fills the area needed to put all the texts. Note that you forgot to provide minimal reproducible code. – JohanC Mar 02 '22 at 21:34

0 Answers0