Python 中空间数据的热图
Heat Map of Spatial Data in Python
我正在编写 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 平面上绘制数据,为每个点指定一种颜色以反映其热值。目前我尝试使用命令
plt.scatter(df.X, df.Y)
但是每个点的颜色取决于它的热量,在 Python 中。
提前致谢
From the 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);
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)
If you want to apply a custom color map, there is also the cmap
parameter, allowing you to specify a different color map
You can also read more about in in the docs for the scatter() method.
我正在编写 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 平面上绘制数据,为每个点指定一种颜色以反映其热值。目前我尝试使用命令
plt.scatter(df.X, df.Y)
但是每个点的颜色取决于它的热量,在 Python 中。 提前致谢
From the 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);
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)
If you want to apply a custom color map, there is also the cmap
parameter, allowing you to specify a different color map
You can also read more about in in the docs for the scatter() method.