Franz
Franz

Reputation: 643

How to place elements of legend next to each other?

I plot my plots using matplotlib.pyplot and I would like to plot some of the legend items next to each other instead of among each other. As you can see here, this would save space in my plots:

enter image description here

I tried plt.legend(ncol=2)to split the legend into two columns. This is working as expected but I cant define where to start the new column:

enter image description here

So what I want is to split the dot-items side by side and underneath the line items. Is there any smart way to do this?

Upvotes: 2

Views: 3618

Answers (1)

ImportanceOfBeingErnest
ImportanceOfBeingErnest

Reputation: 339560

My first suggestion would be to use two legends. This would allow each of them to be placed at a suitable position.

enter image description here

You can then also remove the border (frameon=False) around the legend and place them on top of each other.

enter image description here

Upvotes: 5

Related Questions