gpt4 book ai didi

python - seaborn:带有背景颜色的图例

转载 作者:IT老高 更新时间:2023-10-28 20:37:32 26 4
gpt4 key购买 nike

以下问题说明了如何更改图例的背景颜色: matplotlib legend background color .但是,如果我使用 seaborn,这是行不通的。有没有办法做到这一点?

import matplotlib.pyplot as plt
import numpy as np
a = np.random.rand(10,1)

plt.plot(a, label='label')
legend = plt.legend()
frame = legend.get_frame()
frame.set_facecolor('green')
plt.show()


import seaborn as sns

plt.plot(a, label='label')
legend = plt.legend()
frame = legend.get_frame()
frame.set_facecolor('green')
plt.show()

with matplotlib with seaborn

最佳答案

seaborn 默认关闭图例框架,如果你想自定义框架的外观,我认为你需要在调用 plt.legend< 时添加 frameon=True/

关于python - seaborn:带有背景颜色的图例,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30729473/

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