【发布时间】:2016-12-30 23:50:50
【问题描述】:
我正在尝试让Seaborn kdeplot 示例在我的数据集上工作。出于某种原因,我的一个数据集根本没有绘制,但另一个似乎绘制得很好。为了获得一个最小的工作示例,我从我的非常大的数据集中仅采样了 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 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
我的代码 sn-p 如下所示:
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)
为什么数据框dfA 中的数据实际上并未在绘图?
【问题讨论】:
-
您是否只创建一个轴对象并将两者绘制成相同的(或者甚至在没有某些轴的情况下绘制面向图形的图形)?
f, axarr = plt.subplots(2)+sns.kdeplot(dfA.x, dfA.y, cmap="Reds", shade=True, shade_lowest=False, ax=axarr[0])+sns.kdeplot(dfB.x, dfB.y, cmap="Blues", shade=True, shade_lowest=False, ax=axarr[1])呢? -
我试图在同一轴上绘制两者。但是即使我注释掉第二个情节 cmets,dfA 也不会情节
标签: python pandas matplotlib seaborn