python - 将概率传递给 seaborn kdeplot
问题描述
假设我想使用以下数据绘制sns.kdeplot
:
np.random.seed(42)
x = [np.random.randint(0, 10) for _ in range(10)]
x
[6, 3, 7, 4, 6, 9, 2, 6, 7, 4]
但是现在,假设我有每个值的概率,而不是每个值:
# y is a pd.Series
y
6 0.3
7 0.2
4 0.2
9 0.1
3 0.1
2 0.1
是否有可能kdeplot
从这些概率中构建?
我认为 seaborn 可能会计算这些值,因此我认为这是可能的
解决方案
您应该能够使用(在 v0.11.0 中添加)的weights
参数来完成此操作,例如kdeplot
sns.kdeplot(x=x, weights=y)
推荐阅读
- c# - System.MissingMethodException:找不到方法:'无效 Microsoft.AspNetCore.Identity.DataProtectorTokenProvider
- vue.js - 计算属性是否总是用于在 Vuex 中检索存储值?
- python - 带有 lambda 信号的 PyQt 复选框列表
- css - ios 13 CSS 设置-webkit-overflow-scrolling:自动无法工作
- python - Python Pandas:具有灵活列位置的 iloc
- javascript - Javascript鼠标滚轮与滚动条滚动事件
- unit-testing - 关于返回承诺的函数的 spyOn 问题
- google-maps - 嗨,有没有办法减少我的地图标记大小,这是我的代码:
- c# - LINQ 查询子对象 C sharp 8 和 asp.net core 3.0
- kotlin - Teamcity Kotlin 构建基类属性扩展