
Creating Heatmap from Scratch in Python (2018) - geomatics99
http://www.geodose.com/2018/01/creating-heatmap-in-python-from-scratch.html
======
alexhutcheson
I like seaborn's jointplot()[1] function for generating plots like this. I
actually prefer the "hexagonal bin" plot, but jointplot() can also do kernel
density estimation like this post does.

Hexbin example:
[https://seaborn.pydata.org/examples/hexbin_marginals.html](https://seaborn.pydata.org/examples/hexbin_marginals.html)

KDE example:
[https://seaborn.pydata.org/examples/joint_kde.html](https://seaborn.pydata.org/examples/joint_kde.html)

If you are doing any exploratory analysis using scatterplots, I highly
recommend that you also generate hexbin plot or heatmap. Far too often it
turns out all of the points are concentrated in a small area of the plot, but
that's not always apparent on a scatterplot.

[1]
[https://seaborn.pydata.org/generated/seaborn.jointplot.html](https://seaborn.pydata.org/generated/seaborn.jointplot.html)

------
anc84
Please be aware that you MUST NOT use this for geographic coordinates such as
"GPS" or "WGS84" latitude & longitude pairs. Depending on the longitude areas
are of different sizes. You must use code that knows about that or your
results will be utterly wrong.

~~~
peteradio
This would only skew density maps not counts maps.

~~~
anc84
Well, this is about density maps unless I overlooked something?

------
yetihehe
I much prefer kriging, which seems to better model sparse areas.
[https://en.wikipedia.org/wiki/Kriging](https://en.wikipedia.org/wiki/Kriging)
too bad there are no image comparisons for those methods. Main difference -
instead of sum of distances with cutoff, you make sum of values weighted by
distances for each map point.

~~~
plopz
What you describe sounds more like idw than kriging.

~~~
yetihehe
Indeed, I've started with nice images on web which were described as
"kriging", then went on to page about kriging, seen some general ideas and
implemented what I thought would be fast, simple and work. That way I had
something which looked right for my application (visualising district heating
temperatures in city), but only now I know how it's really called. Still
better looking that heatmap.

------
4thaccount
Neat...I just wish there was an easy way to give the basemap library a 3-item
tuple with (lat, lon, value) and have it automatically do a heat map and not
just plot the points. That is an option in some software.

~~~
rakshitadmar
I have something of the sort. Give it later, lon and a value, it performs
cubic interpolation and forms a heatmap. Some of the code is specific to my
application but I'm sure you can reuse.

[https://github.com/rraks/sigcatch](https://github.com/rraks/sigcatch)

Open to contributions.

~~~
4thaccount
Thank you! I'll look.

------
KyleOS
I feel like these days we should be creating more user-friendly graphs - both
for the creator of the graph and for the reader. I created this graph of the
Atmospheric concentrations of CO2 earlier today
([https://kyso.io/KyleOS/atmospheric-
co2-concentrations#code=h...](https://kyso.io/KyleOS/atmospheric-
co2-concentrations#code=hidden)). Would love to see the OP's heatmap recreated
with plotly.

------
alexhutcheson
If you're making heatmaps with GIS data, give some critical thought to the
interpretation of the map to make sure you're not just doing this:
[https://xkcd.com/1138/](https://xkcd.com/1138/)

------
gigatexal
This is really cool. Thank you for sharing.

~~~
geomatics99
you're welcome

