gpt4 book ai didi

python - seaborn 中的图例重叠情节区域

转载 作者:行者123 更新时间:2023-12-04 01:50:59 25 4
gpt4 key购买 nike

这个问题在这里已经有了答案:





How to put the legend out of the plot

(17 个回答)


3年前关闭。




enter image description here

我使用 seaborn 制作了上面的情节,但我无法将图例正确放置在情节之外。请注意,图例在图像的右侧被切断。这是它的真实外观,我没有手动切割。这是我正在使用的代码:

sns.lineplot(x="Time", y='Anomaly', style='country', hue='region', size='area', sizes=(1., 4), data=df)
# Put the legend out of the figure
plt.subplots_adjust(right=0.2)
plt.legend(bbox_to_anchor=(.95, 1), loc=2, borderaxespad=0.)
plt.tight_layout()
plt.show()

- 编辑:

这是复制此问题的数据:
https://www.dropbox.com/s/w4gd447e22zb5yk/subset.csv?dl=0

最佳答案

您没有为我们指定样本集来测试实现并生成绘图,但使用玩具初始化,修改 bbox_to_anchor似乎可以解决问题。见 matplotlib's legend guide .
bbox_to_anchor控制手动图例放置。将其设置为 (1,1)把它放在右上角。

plt.legend(bbox_to_anchor=(1, 1), loc=2, borderaxespad=0.)

样本图 有修改:
enter image description here

关于python - seaborn 中的图例重叠情节区域,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53128352/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com