Abi*_*iel 6 python legend-properties seaborn seaborn-0.12.x
seaborn.objects我正在使用v0.12.0 中提供的新API。所有示例均未显示如何移动图例位置。例如,将图例移至底部。有没有办法做到这一点?
使用, 如本答案sns.move_legend所示会产生.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')
Run Code Online (Sandbox Code Playgroud)
---------------------------------------------------------------------------
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.
Run Code Online (Sandbox Code Playgroud)