How can one create a heatmap from a 2D scatterplot data in Python, where for each (x,y) point in the scatterplot one has a z value associated to it? The z value will be the value used to color the heatmap.
For example, in R, I can use :
# This example is from http://knowledge-forlife.com/r-creating-heatmap-scatterplot-data/
#I'm just setting the seed so you can see the same example on your computer
set.seed(1)
#Our X data
x <- runif(150)
#Our Y data
y <- runif(150)
#Our Z data
z <- c(rnorm(mean=1,100),rnorm(mean=20,50))
#Store the length of our data
N <- length(x)
# View the scatterplot
plot(x, y)
#Here is the interpolation to give the heatmap effect.
#Use xo and yo to set the output grid you want to use.
#xo and yo are used to change the resolution of the interpolation
#Here, I have included a somewhat standard protocol for these parameters
s <- interp(x,y,z,xo=seq(min(x),max(x),length=N),
yo=seq(min(x),max(x),length=N),duplicate="mean")
#Here's where the fun happens
#Note you can add your typical plotting paramaters here, such as xlab or ylab
image.plot(s,xlim=c(0,1),ylim=c(0,1),zlim=c(-2,25))
Scatterplot (each (x,y) point in this scatterplot one has a z value associated to it; the z values aren't visible in the scatterplot):
Corresponding heatmap (the color represents the z values):
Note that this question is different from Generate a heatmap in MatPlotLib using a scatter data set, where the color in the heatmap represents the density of the (x,y) points).