I am using the new seaborn.objects
API available in v0.12.0. None of the examples show how to move the legend position. For example, moving the legend to the bottom. Is there a way to do this?
Using sns.move_legend
, as shown in this answer results in a TypeError
.
import seaborn as sns
import seaborn.objects as so
healthexp = sns.load_dataset('healthexp')
p = so.Plot(healthexp, "Year", "Spending_USD", color="Country")
p.add(so.Line())
sns.move_legend(p, "upper left", bbox_to_anchor=(.55, .45), title='Species')
Traceback
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
Input In [24], in <cell line: 3>()
1 p = so.Plot(healthexp, "Year", "Spending_USD", color="Country")
2 p.add(so.Line())
----> 3 sns.move_legend(p, "upper left", bbox_to_anchor=(.55, .45), title='Species')
File ~\anaconda3\envs\py10\lib\site-packages\seaborn\utils.py:444, in move_legend(obj, loc, **kwargs)
442 else:
443 err = "`obj` must be a seaborn Grid or matplotlib Axes or Figure instance."
--> 444 raise TypeError(err)
446 if old_legend is None:
447 err = f"{obj} has no legend attached."
TypeError: `obj` must be a seaborn Grid or matplotlib Axes or Figure instance.