简体   繁体   中英

How to smooth data points in scatter plots in python?

I have a scatter plot where I am coloring each data point based on an array:

 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,)

and this is the result: 当前

Now, I want to keep the color but smooth the data points to get a smoothed scatter plot, something like this (from this post ) or this image:

期望

Comment: I figured that if I can add more points to my xs, ys, zs I can make the scatter plot with more data points, hence, it will look more like a heatmap plot, which is what I want. Now, for every point in xs, ys, zs , I want to add additional points with similar values around original points. Ideally, these additional points should form a normal distribution around actual original points in the xs, ys, zs . Is there a statistical tools to do this task? Eg How to change [1, 5, 10] to [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] ?

OP : Is there a statistical tools to do this task? Eg How to change [1, 5, 10] to [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]])

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM