2

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?

Franz
  • 623
  • 8
  • 14
  • 1
    You could plot the line items first, followed by a dummy item with an empty label, and then plot the four dot items. That way (with `ncol=4`) it could work (although I wouldn't call it a smart solution....). See e.g. https://stackoverflow.com/a/34218288/3581217 – Bart Jun 08 '17 at 16:21

1 Answers1

5

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

ImportanceOfBeingErnest
  • 321,279
  • 53
  • 665
  • 712
  • Thanks a lot. Thats not exactly what I was looking for but quiet a very good idea. – Franz Jun 09 '17 at 08:03
  • Maybe I should have mentionned that there is no way to have differing numbers of columns or "shared" cells like in a spreadsheet table or so. (Other then rewriting the legend code to allow for it). So one needs to use some kind of workaround. Those are ideas, yes, and I'm sure there are other ideas as well. – ImportanceOfBeingErnest Jun 09 '17 at 08:11