gpt4 book ai didi

seaborn - 如何为 seaborn.histplot() 使用 kde_kws 参数?

转载 作者:行者123 更新时间:2023-12-05 02:02:43 33 4
gpt4 key购买 nike

我正在尝试使用 sns.histplot() 而不是 sns.distplot() 因为我在 colab 中收到以下消息:

FutureWarning: distplot is a deprecated function and will be removedin a future version. Please adapt your code to use either displot (afigure-level function with similar flexibility) or histplot (an axes-level function for histograms).

代码:

import pandas as pd
import seaborn as sns

df = sns.load_dataset('tips')
sns.histplot(df['tip'], kde=True, kde_kws={'fill' : True});

我在 sns.histplot() 中传递 kde_kws 参数时出错:

TypeError: init() 得到了一个意外的关键字参数“fill”

最佳答案

来自 the documentation kde_kws= 旨在传递“控制 KDE 计算的参数,如在 kdeplot() 中”。这些参数是哪些参数并不完全明确,但它们似乎是 bw_method=bw_adjust= 之类的参数,它们改变了 KDE 的计算方式,而不是显示方式。如果你想改变 KDE 绘图的外观,你可以使用 line_kws=,但是,顾名思义,KDE 仅由一条线表示,因此无法填充。

如果您同时想要直方图和填充的 KDE,则需要在同一轴上组合 histplot()kdeplot()

sns.histplot(df['tip'], stat='density')
sns.kdeplot(df['tip'], fill=True)

关于seaborn - 如何为 seaborn.histplot() 使用 kde_kws 参数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65623867/

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