如何在python中的散点图中平滑数据点?

问题描述 投票:3回答:1

我有一个散点图,我根据数组着色每个数据点:

 plt.scatter(xs,ys,c=av,cmap=plt.cm.hot,s=50,alpha=0.5)

In [96]: xs.shape
Out[96]: (5594,)

In [97]: ys.shape
Out[97]: (5594,)

In [98]: av.shape
Out[98]: (5594,)

这就是结果:Current

现在,我想保持颜色,但要平滑数据点以获得平滑的散点图,如下所示(来自此post)或此图像:

Desired

评论:我认为如果我可以为我的xs, ys, zs添加更多的点数,我可以使用更多的数据点来制作散点图,因此,它看起来更像是热图图,这就是我想要的。现在,对于xs, ys, zs中的每个点,我想在原始点周围添加具有相似值的其他点。理想情况下,这些附加点应该在xs, ys, zs中围绕实际原始点形成正态分布。有没有统计工具来完成这项任务?例如。如何将[1, 5, 10]更改为[0.9,0.98,1,1.02,1.1, 4.9,4.98,5,5.02,5.1, 9.9,9.98,10,10.02,10.1]

python matplotlib
1个回答
1
投票

OP:有没有统计工具来完成这项任务?例如。如何将[1,5,10]更改为[0.9,0.98,1,1.02,1.1,4.9,4.98,5,5.02,5.1,9.9,9.98,10,10.02,10.1]?

obs=[1, 5 ,10]

syntheticobs=np.random.normal(0,0.1,(6,3))+obs
synthethicobs

Out[]:array([[ 1.02166209,  5.00716569,  9.96726293],
             [ 0.96727493,  4.94823697, 10.03424305],
             [ 1.10756036,  5.12464335,  9.86776082],
             [ 0.97866246,  5.12743117, 10.06647638],
             [ 0.87842188,  5.00994338, 10.1114983 ],
             [ 1.10728294,  4.82523615, 10.03642462]])
© www.soinside.com 2019 - 2024. All rights reserved.