Hi, I did not realise you are developing seaborn. Thanks for that, amazing and helpful package to get all kinds of stuff done. Maybe you’re not waiting to extend the conversation with a noob, but see it as feedback from a user; someone working with, not creating the code (my main work is in molecular biology).
I’ve just been trying out to place/replace a legend made via sns.catplot(...., legend_out=False)
.
The placement obtained with the default ‘legend_out’ is not alweays satisfactory. (But that is not a big problem; edit the figure in an svg-editor; that works often faster than finding that one option that might do the job). But trying to understand the stuff, searching the web or the documentation, one runs into quite some overlap of how things can be done.
The above out-of-figure legend-placement can be done outwith seaborn, possibly derived from
move-seaborn-plot-legend-to-a-different-position, while someone else is even writing a book chapter about setting a figure size only.
All these various ways are good in the sense that a lot is possible; but for a (not-a-full-time programmer) beginner it is enormously confusing. It took quite some time to appreciate the level one is operating at (‘Axes’, ‘Figure’??; using plt. interface or the object-orientation?? ) and how functions cross-refer. And the realisation that one has to inactivate an item that is well presented (say a legend) and built it completely over (say via matplot.lib) is also not that obvious. This involves quite a learning curve. From the seaborn documentation:
g = sns.catplot(x="total_bill", y="day", hue="time",
height=3.5, aspect=1.5,
kind="box", legend=False, data=tips);
g.add_legend(title="Meal")
So after the plot, a legend can be created in seaborn. And as you will know, with extra matplotlib code this can be placed somewhere else (at least in the figure I was working on):
g.add_legend(title=‘Meal’,loc=‘upper right’, bbox_to_anchor=(0.98, 0.90))
As referred to in the seaborn documentation, this ‘mixing’ is not always obvious; but this works (possibly because it is at the figure level) too:
leg = g._legend #just a guess ;-)
leg.set_bbox_to_anchor((0.08, 0.12))
leg.set_draggable(True)
So what I do not understand is the need to change the matplotlib api, where maybe providing more transparent access to an element from seaborn that would allow the direct use of a matplotlib function could help a lot of users.
Being built on top of matplotlib it makes sense that various settings in seaborn (or pandas.plot) translate/overlap matplotlib functions. Also that this overlap is not complete. But as a user one would like to have a quick way of getting to an aspect of a figure whithout the need to learn all the multiple ways to accomplish something (e.g. “move that legend”).
If there is a documented matplotlib solution for fine-tuning (a part of) a figure absent from pandas or seaborn, ideally one would be able to use that solution without needing to rebuild that (part of the) figure in matplotlib.
Say, instead of g._legend
above, a function like g.get_legend()
in the list of seaborn methods would help access to using matplotlib in a more seamless manner (at least until the proposed legend-api change is working/implemented).