gpt4 book ai didi

python - Geopandas 连接形状文件的着色

转载 作者:太空宇宙 更新时间:2023-11-03 20:14:13 25 4
gpt4 key购买 nike

我正在尝试使用 GEOPANDAS PYTHON 为一组串联的地理数据帧的 map 对象设置不同的颜色(而不是单一颜色)。

我已经尝试过设置facecolor和cmap的传统方法,但是它不适用于串联的地理数据帧。

我想要为 gdf ​​和边界获得不同的颜色形状(例如红色和蓝色),而不是我当前获得的单一颜色。

这是代码:

import pandas as pd
import geopandas as gpd
from geopandas import GeoDataFrame
import matplotlib.pyplot as plt
import pandas
from shapely import wkt

#Converting an excel file into a geodataframe

Shape=pd.read_excel('C:/Users/user/OneDrive/documents/Excel .xlsx')
print(Shape)
Shape['geometry'] = Shape['geometry'].apply(wkt.loads)
gdf = gpd.GeoDataFrame(Shape, geometry='geometry')
gdf.plot()

#reading another geodataframe
Boundaries=gpd.read_file('C:/Users/user/Desktop/Boundaries/eez_v10.shp')

#concatenating Boundaries and gdfgeodataframes
map=pd.concat([gdf,Boundaries], sort=False)
ax=map.plot(figsize=(20,20))
plt.xlim([47,60])
plt.ylim([22,32])
plt.show()

最佳答案

您不需要执行 concat,只需将两个 df 绘制到同一轴即可。

gdf = gpd.GeoDataFrame(Shape, geometry='geometry')
Boundaries=gpd.read_file('C:/Users/user/Desktop/Boundaries/eez_v10.shp')

ax = gdf.plot(color='blue')
Boundaries.plot(ax=ax, color='red')

关于python - Geopandas 连接形状文件的着色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58561912/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com