python - Python 中的空间数据热图

标签 python pandas spatial heatmap

我正在编写 Python 代码。我的数据集由三列组成,前两列是坐标,第三列是热估计

                   X              Y      heat
0      497935.000000  179719.000000  0.048428
1      497935.000000  179719.000000  0.029399
2      497935.000000  179719.000000  0.066734
3      497935.000000  179719.000000  0.065524
4      497935.000000  179719.000000  0.062458
5      497935.000000  179719.000000  0.032225
6      497935.000000  179719.000000  0.028557
7      497463.000000  179526.000000  0.000388
8      497899.000000  179305.000000  0.000733
9      497805.000000  179364.000000  0.000158
10     498264.000000  180349.000000  0.000036
11     498020.000000  179602.000000  0.003149
...              ...            ...       ...

我想在 XY 平面上绘制数据,为每个点分配一种颜色以反射(reflect)其热值。目前我尝试使用命令

plt.scatter(df.X, df.Y)

enter image description here

但在 Python 中,每个点的颜色取决于其热量。 提前致谢

最佳答案

来自documentation :

The keyword c may be given as the name of a column to provide colors for each point:

In [64]: df.plot.scatter(x='a', y='b', c='c', s=50);

因此,您需要做的就是简单地指定 heat 列包含有关每个点颜色的信息:

df.plot.scatter(x=data.X, y=data.Y, c=data.heat)

如果您想应用自定义颜色贴图,还有 cmap 参数,允许您指定不同的 color map

您还可以在 scatter() 的文档中阅读有关 in 的更多信息。方法。

关于python - Python 中的空间数据热图,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38264887/

相关文章:

python - 将 IBM_DB 与 Pandas 结合使用

python - 对 Pandas 中的每周数据进行上采样

mysql - 该 Polygon 对象会自行关闭。为什么此插入仍然失败并出现错误 3037 : Invalid GIS data?

python - 查找 GeoTiff 图像中每个像素的纬度/经度坐标

python - 关键点描述符匹配 : How to calculate a goodness-of-fit per template?

python - 按 dtype 选择 Pandas 列

R 以一定的容差叠加点和多边形

R用ggmap对象叠加geom_polygon,空间文件转换

python - 在 Kivy 中启动多个小部件

python - 如何将一个包含 +1.048.576 行的数据框导出到多个 Excel 文件/工作表中