[英]Geopandas - plot points with their IDs
I would like to paint on a map a list of points with the id of each point next to it, this is what I am doing我想在地图上绘制一个点列表,旁边是每个点的 id,这就是我正在做的
dfPoints["id"] = dfPoints.index
geomertrySensores2 = [Point(xy) for xy in zip(dfPoints['longitud'], dfPoints['latitud'])]
crs = {'int':'epsg:4326'}
geoSensores = gpd.GeoDataFrame(dfPoints,crs=crs, geometry = geomertrySensores2)
# creating color map for categories
categories = np.unique(geoSensores["id"])
colors = np.linspace(0, 1, len(categories))
colordict = dict(zip(categories, colors))
geoSensores["Color"] = geoSensores["id"].apply(lambda x: colordict[x])
f, ax = pl.subplots(figsize=(20,15))
geoBase.plot(color = 'grey', alpha=0.4, ax = ax)
geoSensores.plot(ax=ax, markersize=20, color="blue", marker="o", column='id')
But I can't add the id of each point on the map How would be the way to do it?但我无法在地图上添加每个点的 id 怎么做? I have 255 points, so I would like to paint the id of each point next to it and not use color palette我有 255 个点,所以我想在它旁边绘制每个点的 id,而不是使用调色板
I managed to fix this using matplotlib:我设法使用 matplotlib 解决了这个问题:
f, ax = pl.subplots(figsize=(120,90))
geoVias.plot(color = 'grey', alpha=0.4, ax = ax)
geoSensores.plot(ax=ax, markersize=20, color="blue", marker="o", column='id')
for index, row in geoSensores.iterrows():
x = row.geometry.centroid.x
y = row.geometry.centroid.y
pl.text(x, y, row.id, fontsize=10)
but the map was very saturated, so I used bokeh which allows zooming但是地图非常饱和,所以我使用了可以缩放的散景
p = figure(title="Ubicacion de sensores",
plot_height = 700 ,
plot_width = 900, )
def getPointCoords(row, geom, coord_type):
"""Calculates coordinates ('x' or 'y') of a Point geometry"""
if coord_type == 'x':
return row[geom].x
elif coord_type == 'y':
return row[geom].y
ubicacionSensores['x'] = ubicacionSensores.apply(getPointCoords, geom='geometry', coord_type='x', axis=1)
ubicacionSensores['y'] = ubicacionSensores.apply(getPointCoords, geom='geometry', coord_type='y', axis=1)
p_df = geoSensores.drop('geometry', axis=1).copy()
psource = ColumnDataSource(p_df)
p.circle('x', 'y', source=psource, color='red', size=7)
my_hover = HoverTool()
my_hover.tooltips = [('Sensor id', '@id')]
p.add_tools(my_hover)
def getLineCoords(row, geom, coord_type):
"""Returns a list of coordinates ('x' or 'y') of a LineString geometry"""
if coord_type == 'x':
return list( row[geom].coords.xy[0] )
elif coord_type == 'y':
return list( row[geom].coords.xy[1] )
geoVias['x'] = geoVias.apply(getLineCoords, geom='geometry', coord_type='x', axis=1)
geoVias['y'] = geoVias.apply(getLineCoords, geom='geometry', coord_type='y', axis=1)
m_df = geoVias.drop('geometry', axis=1).copy()
msource = ColumnDataSource(m_df)
p.multi_line('x', 'y', source=msource, color='grey', alpha=0.4, line_width=1)
show(p)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.