Eurostat map using Python
I’ve started using Python a while ago and I really like using geopandas
(for one, the documentation is pretty good).
Using Eurostat data, this is a map comparing tertiary education in European countries in 2022. Tertiary education refers to anything university-level.
First, I’ve used a Natural Earth shapefile to get the base map of the world. Then, after I’ve read in the Eurostat file and made sure the country colunms in both files are called ‘Country’, I merge them like so:
= wb.merge(land10, on ='Country', how ='left')
df = gpd.GeoDataFrame(df) gdf
A few countries were missing from Eurostat so I coerced them into missing, ‘NaN’ values. The final map was created by the following code:
from mpl_toolkits.axes_grid1 import make_axes_locatable
= plt.subplots(1, 1)
fig, ax
= make_axes_locatable(ax)
divider
#axes on which to draw the legend in case of color map
= divider.append_axes("bottom", size="5%", pad=0.1)
cax
;
ax.set_axis_off()=ax,
gdf.plot(ax="Percentage",
column= 'YlGn',
cmap=True,
legend=cax,
cax={"label": "Percentage Tertiary Educated", "orientation": "horizontal"},
legend_kwds
)
= gdf[gdf.Country == 'Germany'].total_bounds
xmin, ymin, xmax, ymax = 20 # add a padding around the geometry
pad -pad, xmax+ pad)
ax.set_xlim(xmin-pad, ymax+ pad)
ax.set_ylim(ymin
# Figure footer title
0.4, 0.9, "Source: Eurostat 2022",
fig.text(="center", fontsize=8)
horizontalalignment
# Save plot to file
"eurostat.png", dpi=600) plt.savefig(
I would like to know how to make the map flat and not so squished (if you know what I mean). I’m going to explore other base maps in the future.
The script is also available in my repo.