I am writing a code for a map of europe with python geopandas.
I am currently facing a problem with French Guiana. I don't want it to display in the map, however, I don't find a way to detach it from France.
Here is my code:
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()
As there is no separation between territories in this dataset, we can cut the polygons to your desired size using a bounding box (bbox) as a clip.
This is relatively simple, but we will need a small function and the
Polygonclass from Shapely to convert a bbox to a shape. In order to achieve this, we need to complete the following steps:europe.From https://stackoverflow.com/a/68741143/18253502, we can convert bbox coordinates to a shapely Polygon. Bbox coordinates can be made at http://bboxfinder.com.
Now
europehas been clipped to the bbox extent:Note that the Eastern tip of Russia is missing, as it wraps around to the other Longitude (see https://stackoverflow.com/a/71408567/18253502 for more details).