Legend position gets overwritten / can not be set
See original GitHub issueWhen plotting with the new seaborn.objects
Plot method including a legend (like .add(Line(), legend=True)
), the position of the legend gets hardcoded to specific positions (https://github.com/mwaskom/seaborn/blob/master/seaborn/_core/plot.py#L1612-L1624), which differ depending on the usage of pyplot (legend gets pulled on top of the right side over the graph’s content) or not (e.g. in a Jupyter notebook, or on .save()
,the legend gets place to the right side outside of the plot graph area).
If the users want a different position of the legend (possible especially in the case of pyplot usage, where the legend may easily be generated over important data points), they have no possibility to move it to another place. The old (=not seaborn.objects
) method move_legend()
does not work for Plot
objects, neither can the seaborn objects .theme()
approach be used, with setting matplotlib rc params (which would be legend.loc
in conjunction with bbox_to_anchor
of the matplotlib legend), because the loc
is hardcoded, and will such be overwritten, additionally there is no possibility at all for the users to set bbox_to_anchor
for the legend.
The PR https://github.com/mwaskom/seaborn/pull/3128 solves this issue, through staying at the current default behavior, if no additional parameters are given, but respecting the matplotlib rc params entry for legend.loc
if it is given like .theme({"legend.loc": "upper left"})
.
Additionally it gives the new possibility to set the bbox_to_anchor
of the legend, like .theme({"legend_loc__bbox_to_anchor": (0.1, 0.95)})
(where the kind this is implemented might not be ideal).
This gives the users full control over the legend position.
Issue Analytics
- State:
- Created 10 months ago
- Comments:8 (4 by maintainers)
Top GitHub Comments
Sorry, thinking-typo, fixed to ‘pyplot’
NP, your welcome 😃