【发布时间】:2021-01-30 21:17:12
【问题描述】:
使用 distplot 绘制直方图
sns.distplot(a, color="red", label="100% Equities")
在 Seaborn 0.11 或更高版本下运行会产生警告,表明 distplot 将被弃用并改用 displot。
使用 displot 作为直接替换(只需将函数名称从 distplot 更改为 displot)不会产生相同的直方图。
替换代码是什么?
【问题讨论】:
-
label 似乎不是 displot 的参数:seaborn.pydata.org/generated/seaborn.displot.html
-
上面的代码是针对 distplot(不是 displot)。 distplot 是已弃用的代码,它确实有一个标签。 histplot(见下面的答案)也确实从 bar 继承标签。如果你在你给出的链接中追查 kwargs(选择 histplot,然后在最后选择栏 - 你会发现 label 关键字可用。)Matplotlib 做了很多继承:-)
-
BTW 这是在尝试使用已弃用的代码时发出的警告消息。
FutureWarning: `distplot` is a deprecated function and will be removed in a future version. Please adapt your code to use either `displot` (a figure-level function with similar flexibility) or `histplot` (an axes-level function for histograms).