- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我有一个如下所示的数据框:
df:
RY MAJ_CAT Value
2016 Cause Unknown 0.00227
2016 Vegetation 0.04217
2016 Vegetation 0.04393
2016 Vegetation 0.07878
2016 Defective Equip 0.00137
2018 Cause Unknown 0.00484
2018 Defective Equip 0.01546
2020 Defective Equip 0.05169
2020 Defective Equip 0.00515
2020 Cause Unknown 0.00050
year_2016 = df[df['RY']==2016]
year_2018 = df[df['RY']==2018]
year_2020 = df[df['RY']==2020]
sns.distplot(year_2016['value'].values, hist=False,rug=True)
sns.distplot(year_2018['value'].values, hist=False,rug=True)
sns.distplot(year_2020['value'].values, hist=False,rug=True)
g = sns.FacetGrid(df,col='MAJ_CAT')
g = g.map(sns.distplot,df[df['RY']==2016]['value'].values, hist=False,rug=True))
g = g.map(sns.distplot,df[df['RY']==2018]['value'].values, hist=False,rug=True))
g = g.map(sns.distplot,df[df['RY']==2020]['value'].values, hist=False,rug=True))
KeyError: "None of [Index([(0.00227, 0.04217, 0.043930000000000004, 0.07877999999999999, 0.00137, 0.0018800000000000002, 0.00202, 0.00627, 0.00101, 0.07167000000000001, 0.01965, 0.02775, 0.00298, 0.00337, 0.00088, 0.04049, 0.01957, 0.01012, 0.12065, 0.23699, 0.03639, 0.00137, 0.03244, 0.00441, 0.06748, 0.00035, 0.0066099999999999996, 0.00302, 0.015619999999999998, 0.01571, 0.0018399999999999998, 0.03425, 0.08046, 0.01695, 0.02416, 0.08975, 0.0018800000000000002, 0.14743, 0.06366000000000001, 0.04378, 0.043, 0.02997, 0.0001, 0.22799, 0.00611, 0.13960999999999998, 0.38871, 0.018430000000000002, 0.053239999999999996, 0.06702999999999999, 0.14103, 0.022719999999999997, 0.011890000000000001, 0.00186, 0.00049, 0.13947, 0.0067, 0.00503, 0.00242, 0.00137, 0.00266, 0.38638, 0.24068, 0.0165, 0.54847, 1.02545, 0.01889, 0.32750999999999997, 0.22526, 0.24516, 0.12791, 0.00063, 0.0005200000000000001, 0.00921, 0.07665, 0.00116, 0.01042, 0.27046, 0.03501, 0.03159, 0.46748999999999996, 0.022090000000000002, 2.2972799999999998, 0.69021, 0.22529000000000002, 0.00147, 0.1102, 0.03234, 0.05799, 0.11744, 0.00896, 0.09556, 0.03202, 0.01347, 0.00923, 0.0034200000000000003, 0.041530000000000004, 0.04848, 0.00062, 0.0031100000000000004, ...)], dtype='object')] are in the [columns]"
最佳答案
设置数据框
import pandas as pd
import numpy as np
import seaborn as sns
# setup dataframe of synthetic data
np.random.seed(365)
data = {'RY': np.random.choice([2016, 2018, 2020], size=400),
'MAJ_CAT': np.random.choice(['Cause Unknown', 'Vegetation', 'Defective Equip'], size=400),
'Value': np.random.random(size=400) }
df = pd.DataFrame(data)
更新答案
seaborn v0.11
sns.displot
与 kind='kde'
和 rug=True
'MAJ_CAT'
一起
sns.displot(data=df, x='Value', hue='RY', kind='kde', palette='tab10', rug=True)
'MAJ_CAT'
分别地
sns.displot(data=df, col='MAJ_CAT', x='Value', hue='RY', kind='kde', palette='tab10', rug=True)
seaborn v0.11
, distplot
已弃用 for year in df.RY.unique():
values = df.Value[df.RY == year]
sns.distplot(values, hist=False, rug=True)
hue
至 FacetGrid
g = sns.FacetGrid(df, col='MAJ_CAT', hue='RY')
p1 = g.map(sns.distplot, 'Value', hist=False, rug=True).add_legend()
关于Python Seaborn : Plot multiple distplot in Facetgrid,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62254125/
我决定试一试seaborn 0.11.0 版!据我所知,使用将替换 distplot 的 displot 函数。我只是想弄清楚如何将高斯拟合绘制到直方图上。这是一些示例代码。 import seabo
出于可重复性的原因,出于可重复性的原因,我在[此处][1]共享该数据集。 这就是我正在做的事情 - 从第 2 列开始,我正在读取当前行并将其与前一行的值进行比较。如果更大的话,我会继续比较。如果当前值
我正在尝试为 distplot 子图编写一个 for 循环。 我有一个包含许多不同长度列的数据框。 (不包括 NaN 值) fig = make_subplots( rows=len(asse
如何在 Seaborn 分布图中 y 最大的 x 位置添加一条垂直线? import seaborn as sns, numpy as np sns.set(); np.random.seed(0)
如何在 Seaborn 分布图中 y 最大的 x 位置添加一条垂直线? import seaborn as sns, numpy as np sns.set(); np.random.seed(0)
这个问题在这里已经有了答案: How to change the figure size of a seaborn axes or figure level plot (13 个答案) 关闭 5 年
我想在图表中绘制两个标签,但没有成功。它仅显示最后一个标签 "Old_Formula"。 这是一个简单的例子 import matplotlib.pyplot as plt import numpy
我有一个pandas系列x: 0 -0.000069 1 -0.000059 2 -0.000025 3 -0.000021 4 -0.000021
我正在使用 ipython 笔记本并尝试使用以下函数导出seaborn distplots。如果我调用该函数并一次仅使用一个变量执行,它就可以正常工作。如果我在循环中调用该函数,它将继续在上一个函数调
我正尝试在 Seaborn 中为一个研究项目制作一些直方图。我希望 y 轴为相对频率,x 轴为 -180 到 180。这是我的一个直方图的代码: import pandas as pd from ma
我有一个名为 data1 的数据数组,其中包含从 0 到超过一千的值。我只想有一个直方图和一个从 0 到 10 的这些值的 KDE。因此我写道: sns.distplot(data1, kde=Tru
我想在 seaborn distplot 中有一个权重选项,类似于 numpy 直方图中的选项。如果没有此选项,唯一的替代方法是将权重应用于输入数组,这可能会导致大小(和时间)不切实际。 最佳答案 您
我正在尝试使用 distplot() 绘制分布,并且我想要 y 轴上的绝对数字而不是相对频率 没有拟合函数 我认为可以通过设置 norm_hist=False 来实现(1) ,但相对频率仍显示在 y
是否可以为 seaborn distplots 设置最小和最大显示限制? 我正在尝试遍历 Pandas 数据框的列,但我所有的输出都获得相同的轴。 for v in var_list: df[
我正在使用 Seaborn在 Jupyter notebook 中绘制如下直方图: import numpy as np import pandas as pd from pandas import
我正在使用 Seaborn 的 distplot() 函数,我并置了两个密度图——每个密度图在同一个图中都有不同的颜色——我想给它们贴上标签。 我使用函数文档中提到的参数“标签”。 我的代码是: Re
可以Seaborn distplot是否设置为自动重新缩放 y 轴以捕获多个绘制数据集的最大 y 范围? 使用 Seaborn 进行批量绘图时,有时不可避免地会在不增加最大频率值的情况下提供数据。当发
当我使用 seaborn 的 distplot 时(在 0.7.1 中)可视化直方图,如果输入序列仅包含单个元素,我会收到错误消息。换句话说,像 import numpy as np import s
我想用数据框中的另一个变量为 seaborn.distplot 着色。 这是一个抽象的例子: import numpy import pandas import seaborn A = numpy.r
我已经在寻找解决方案,但找不到适合我的问题的解决方案。我正在尝试绘制一个带有密度函数的直方图,在 y 轴上显示密度。 meanopa 是标准普尔 500 指数的平均对数返回率。我不明白的是以下内容。
我是一名优秀的程序员,十分优秀!