Python Seaborn kdeplot没有绘制一些数据?
我正在尝试让示例在我的数据集上运行。出于某种原因,我的一个数据集根本没有打印,但另一个似乎打印得很好。为了得到一个最小的工作示例,我只从非常大的数据集中采样了10行 我的输入数据如下所示:Python Seaborn kdeplot没有绘制一些数据?,python,pandas,matplotlib,seaborn,Python,Pandas,Matplotlib,Seaborn,我正在尝试让示例在我的数据集上运行。出于某种原因,我的一个数据集根本没有打印,但另一个似乎打印得很好。为了得到一个最小的工作示例,我只从非常大的数据集中采样了10行 我的输入数据如下所示: #Dataframe dfA index x y category 0 595700 5 1.000000 14.0 1 293559 4 1.000000 14.0 2 562295 3 0.000000 14.0 3 21
#Dataframe dfA
index x y category
0 595700 5 1.000000 14.0
1 293559 4 1.000000 14.0
2 562295 3 0.000000 14.0
3 219426 4 1.000000 14.0
4 592731 2 1.000000 14.0
5 178573 3 1.000000 14.0
6 553156 4 0.500000 14.0
7 385031 1 1.000000 14.0
8 391681 3 0.999998 14.0
9 492771 2 1.000000 14.0
# Dataframe dfB
index x y category
0 56345 3 1.000000 6.0
1 383741 4 1.000000 6.0
2 103044 2 1.000000 6.0
3 297357 5 1.000000 6.0
4 257508 3 1.000000 6.0
5 223600 2 0.999938 6.0
6 44530 2 1.000000 6.0
7 82925 3 1.000000 6.0
8 169592 3 0.500000 6.0
9 229482 4 0.285714 6.0
import seaborn as sns
import matplotlib.pyplot as plt
sns.set(style="darkgrid")
# Set up the figure
f, ax = plt.subplots(figsize=(8, 8))
# Draw the two density plots
ax = sns.kdeplot(dfA.x, dfA.y,
cmap="Reds", shade=True, shade_lowest=False)
ax = sns.kdeplot(dfB.x, dfB.y,
cmap="Blues", shade=True, shade_lowest=False)
我的代码片段如下所示:
#Dataframe dfA
index x y category
0 595700 5 1.000000 14.0
1 293559 4 1.000000 14.0
2 562295 3 0.000000 14.0
3 219426 4 1.000000 14.0
4 592731 2 1.000000 14.0
5 178573 3 1.000000 14.0
6 553156 4 0.500000 14.0
7 385031 1 1.000000 14.0
8 391681 3 0.999998 14.0
9 492771 2 1.000000 14.0
# Dataframe dfB
index x y category
0 56345 3 1.000000 6.0
1 383741 4 1.000000 6.0
2 103044 2 1.000000 6.0
3 297357 5 1.000000 6.0
4 257508 3 1.000000 6.0
5 223600 2 0.999938 6.0
6 44530 2 1.000000 6.0
7 82925 3 1.000000 6.0
8 169592 3 0.500000 6.0
9 229482 4 0.285714 6.0
import seaborn as sns
import matplotlib.pyplot as plt
sns.set(style="darkgrid")
# Set up the figure
f, ax = plt.subplots(figsize=(8, 8))
# Draw the two density plots
ax = sns.kdeplot(dfA.x, dfA.y,
cmap="Reds", shade=True, shade_lowest=False)
ax = sns.kdeplot(dfB.x, dfB.y,
cmap="Blues", shade=True, shade_lowest=False)
为什么dataframe
dfA
中的数据没有实际绘制?我认为高斯KDE不适合任何一个数据集。有一个变量具有离散值,还有一个变量的大部分值似乎是常量。这不是由二元高斯分布很好地建模的
至于到底发生了什么,如果没有完整的数据集,我无法确定,但我预计KDE带宽(特别是y轴上的带宽)将非常窄,以至于密度不可忽略的区域非常小。您可以尝试设置更宽的带宽,但我的建议是对此数据使用不同类型的绘图。您是否只创建一个轴对象,并将两个轴都打印到同一个轴上(或者甚至打印没有某些轴的图形)?如何处理子图(2)+
sns.kdeplot(dfA.x,dfA.y,cmap=“Reds”,shade=True,shade\u lower=False,ax=axarr[0])
+sns.kdeplot(dfB.x,dfB.y,cmap=“Blues”,shade=True,shade\u lower=False,axarr[1])
。但即使我注释掉第二个绘图注释,dfA也不会绘图