1

enter image description here

xy = np.random.random((50,3))
x = xy[:,0]
y = xy[:,1]
z = xy[:,2]*100

plt.scatter(x,y,c=z, cmap="Reds")

I have the above data, as can be seen they all have a x and y position along with a value this being conveyed by the colour of the data dot.

From this i want to create a heatmap / density map where the areas near dots are effected by it.

I have tried making heatmaps with ax.histogram2d() but the problem I have is to make the values affect "nearby areas" Example of what it looks like now so I would need the bins to effect their nearby bins

heatmap, xedges, yedges = np.histogram2d(x, y, weights=z, bins=(50,50))
extent = [0, 1, 0, 1]

enter image description here

Grim
  • 51
  • 5
  • 2
    You could use the 2D version of Seaborn's [`sns.kdeplot`](https://seaborn.pydata.org/generated/seaborn.kdeplot.html) (2D here means that both `x=` and `y=` are used). That function also supports a `weights=` parameter. Note that your post needs reproducible test data and minimal code to be acceptable at StackOverflow. Take a look at [the help center](https://stackoverflow.com/help/asking) to learn more about how StackOverflow works. – JohanC Dec 21 '22 at 20:21
  • @JohanC `sns.kdeplot` does almost what I want after but the weights need to be average. So say two points are being calculated with weights 10 and 20 kdeplot sums them and makes in 30 I need it to be 15 ps. Thanks for the info my post has been updated – Grim Dec 21 '22 at 20:47
  • See [Compute mean value per pixel using weighted 2d histogram](https://stackoverflow.com/a/64768711/12046409) for averaging using a histogram – JohanC Dec 21 '22 at 21:17

0 Answers0