Python空间数据热图 [英] Heat Map of Spatial Data in Python
问题描述
我正在编写Python代码.我的数据集由三列组成,第一列是坐标,第三列是热量估算
Im am writing a Python Code. My dataset is composed of three columns, the firs two are the coordinates, and the third is a heat estimation
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平面上绘制数据,为每个点分配颜色并反映其热值.目前,我尝试使用命令
I would like to plot the data in the XY plane, assigning a colour to each point with reflects its heat value. For the moment I tried with the command
plt.scatter(df.X,df.Y)
plt.scatter(df.X, df.Y)
但是在Python中,每个点的颜色都取决于其热量.在此先感谢
but where every dot has a colour with depends on its heat, in Python. Thanks in Advance
推荐答案
来自文档:
关键字c可以作为列的名称来提供,以为每个点提供颜色:
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
列包含有关每个点颜色的信息:
So what you need to do is to simply specify that the heat
column contains the information about each point's color:
df.plot.scatter(x=data.X, y=data.Y, c=data.heat)
如果要应用自定义颜色贴图,还可以使用 cmap
参数,该参数允许您指定其他
If you want to apply a custom color map, there is also the cmap
parameter, allowing you to specify a different color map
您还可以在文档中阅读有关 scatter()<的更多信息方法.
You can also read more about in in the docs for the scatter() method.
这篇关于Python空间数据热图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!