I'm using Seaborn to generate many types of graphs, but will use just a simple example here for illustration purposes based on an included dataset:
import seaborn
tips = seaborn.load_dataset("tips")
axes = seaborn.scatterplot(x="day", y="tip", size="sex", hue="time", data=tips)
In this result, the single legend box contains two titles "time" and "sex", each with sub-elements.
How could I easily separate the legend into two boxes, each with a single title? I.e. one for legend box indicating color codes (that could be placed at the left), and one legend box indicating size codes (that would be placed at the right).
If you want to use matplotlib instead of seaborn,
I took Diziet's answer and expanded on it. He produced the necessary syntax I was needing, but as he pointed out, was missing a way to calculate how many lines of legend are required for splitting the legend. I have added this, and wrote a complete script:
The following code works well because there is the same number of time categories as sex categories. If it is not necessarily the case, you would have to calculate a priori how many lines of legend are required by each "label"