Py学习  »  Python

Python Geopandas:从欧洲地图中排除法属圭亚那

Nick • 1 年前 • 1069 次点击  

我正在用python geopandas为欧洲地图编写代码。

我目前正面临法属圭亚那的问题。我不想把它显示在地图上,但是,我找不到把它从法国分离出来的方法。

这是我的代码:

import geopandas as gpd
import pandas as pd
import matplotlib.pyplot as plt


europe = gpd.read_file(gpd.datasets.get_path('naturalearth_lowres'))
europe = europe[europe.continent == 'Europe']
#europe = europe[europe.name != 'France']


data = pd.read_csv('HICP_EU_bycountry_12_2022.csv', delimiter=';')
data = data[['Area', 'Rate']]


merged_data = europe.merge(data, left_on='name', right_on='Area', how='left')


fig, ax = plt.subplots(figsize=(10, 6))

merged_data.plot(column='Rate', cmap='Reds', linewidth=0.8, ax=ax, edgecolor='0.8', legend=True)

ax.set_title('Inflation Rates in Europe', fontsize=16)
ax.set_axis_off()

for idx, row in merged_data.iterrows():
    rate = row['Rate']
    if not pd.isna(rate):
        ax.annotate(text=str(rate), xy=row['geometry'].centroid.coords[0], horizontalalignment='center', fontsize=8)

ax.set_facecolor('#f7f7f7')

plt.show()
Python社区是高质量的Python/Django开发社区
本文地址:http://www.python88.com/topic/157756
 
1069 次点击  
文章 [ 2 ]  |  最新文章 1 年前