Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/299.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在pandas/python上用Z分数绘制概率密度函数_Python_Pandas_Matplotlib_Plot - Fatal编程技术网

在pandas/python上用Z分数绘制概率密度函数

在pandas/python上用Z分数绘制概率密度函数,python,pandas,matplotlib,plot,Python,Pandas,Matplotlib,Plot,使用此代码: df1 = (df.ix[:,1:] - df.ix[:,1:].mean()) / df.ix[:,1:].std() 我用第二列分组数据框中项目的频率分布计算了一列的z分数。现在结果是这样的: Z Score Frequency Distribution -2.394214 1 -2.280489 1 -2.166763 2 -2.109900 7 -2.053037 4 -1.939311 7

使用此代码:

df1 = (df.ix[:,1:] - df.ix[:,1:].mean()) / df.ix[:,1:].std()
我用第二列分组数据框中项目的频率分布计算了一列的z分数。现在结果是这样的:

Z Score     Frequency Distribution
-2.394214       1
-2.280489       1
-2.166763       2
-2.109900       7
-2.053037       4
-1.939311       7
-1.882448      11
-1.825586       9
-1.768723       7
-1.711860       4
-1.654997      11 ..about 73 items
现在我想创建一个概率密度图,在x轴上有z分数,在y轴上有频率密度。所以我决定先试试条形图,看看结果如何。条形图显示了如下内容:

有了这个代码:
ax1=counts1.plot(kind='bar',stacked=False)
,所以我想让我们看看概率密度函数会是什么样子,我把bar改为'kde',得到了如下结果:

我想情节还可以,但我对我的x轴不太满意。是否可以在x轴上为每个z分数编制索引(比方说像我的条形图的x轴)?我不熟悉pandas/matplotlib/我正在尝试学习绘图,非常感谢您的帮助。

准备虚拟数据:

绘图:

绘图后获得的儿童艺术家的
列表的输出:

ax.get_children()
[<matplotlib.lines.Line2D at 0x1d68b5c6d68>, <--- first element in list of child artists
 <matplotlib.spines.Spine at 0x1d6895f14a8>,
 <matplotlib.spines.Spine at 0x1d6895f1f98>,
 <matplotlib.spines.Spine at 0x1d68d881828>,
 <matplotlib.spines.Spine at 0x1d68b995048>,
 <matplotlib.axis.XAxis at 0x1d689aeb978>,
 <matplotlib.axis.YAxis at 0x1d68d7ff908>,
 <matplotlib.text.Text at 0x1d689b55cf8>,
 <matplotlib.text.Text at 0x1d689b55a20>,
 <matplotlib.text.Text at 0x1d689b55c88>,
 <matplotlib.legend.Legend at 0x1d687645390>,
 <matplotlib.patches.Rectangle at 0x1d689b55080>]
ax.get_children()

[,我相信你做得不对,你能发布一个你的初始数据样本(或者利用np.random或其他我们可以用来加载数据的东西)吗?谢谢你,尼克。这是一个非常好的答案。
ax = df.plot(x='ZScore', y='FreqDist', kind='kde', figsize=(10, 6))
# get the x axis values corresponding to this slice (See beneath the plot)
arr = ax.get_children()[0]._x
# take the first and last element of this array to constitute the xticks and 
# also rotate the ticklabels to avoid overlapping
plt.xticks(np.linspace(arr[0], arr[-1]), rotation=90)
plt.show()
ax.get_children()
[<matplotlib.lines.Line2D at 0x1d68b5c6d68>, <--- first element in list of child artists
 <matplotlib.spines.Spine at 0x1d6895f14a8>,
 <matplotlib.spines.Spine at 0x1d6895f1f98>,
 <matplotlib.spines.Spine at 0x1d68d881828>,
 <matplotlib.spines.Spine at 0x1d68b995048>,
 <matplotlib.axis.XAxis at 0x1d689aeb978>,
 <matplotlib.axis.YAxis at 0x1d68d7ff908>,
 <matplotlib.text.Text at 0x1d689b55cf8>,
 <matplotlib.text.Text at 0x1d689b55a20>,
 <matplotlib.text.Text at 0x1d689b55c88>,
 <matplotlib.legend.Legend at 0x1d687645390>,
 <matplotlib.patches.Rectangle at 0x1d689b55080>]