import geopandas as gpd import matplotlib.pyplot as plt import matplotlib.patches as mpatches # 1. Load your shapefile Replace this path with the path to your .shp file (or .geojson / .gpkg) shapefile_path = r"C:\Users\thoma\OneDrive\Documents\Data Analysis\Projects\Shapefiles\ne_10m_admin_0_countries\ne_10m_admin_0_countries.shp" gdf = gpd.read_file(shapefile_path) # 2. Reproject to a different CRS EPSG:4326 – WGS 84 lat/lon (default for most world shapefiles) EPSG:3857 – Web Mercator (used by Google Maps / OpenStreetMap) ESRI:54030 – Robinson projection (looks great for world maps) ESRI:54009 – Mollweide (equal-area) gdf = gdf.to_crs("ESRI:54030") # Robinson — remove or swap as needed # 3. Quick peek at the data print(gdf.head()) # first few rows print(gdf.columns.tolist()) # column names — useful for choosing a colour field print(gdf.crs) # confirm the coordinate reference system # 4. Basic world map fig, ax = plt.subplots(figsize=(18, 10)) gdf.plot( ax=ax, color="#d4e6c3", # fill colour edgecolor="#555555", # border colour linewidth=0.4, ) ax.set_title("World Map", fontsize=18, fontweight="bold", pad=14) ax.set_axis_off() # hide lat/lon tick marks plt.tight_layout() plt.savefig("world_map_basic.png", dpi=150, bbox_inches="tight") plt.show() # 5. Choropleth map (colour by an attribute column) Replace "YOUR_COLUMN" with a numeric column from your shapefile e.g. "POP_EST", "GDP_MD_EST", "AREA", etc. COLUMN = "YOUR_COLUMN" if COLUMN in gdf.columns: fig, ax = plt.subplots(figsize=(18, 10)) gdf.plot( column=COLUMN, ax=ax, cmap="YlOrRd", # matplotlib colormap — try "viridis", "Blues", "plasma" … legend=True, legend_kwds={ "label": COLUMN, "orientation": "horizontal", "shrink": 0.5, "pad": 0.02, }, edgecolor="#444444", linewidth=0.3, missing_kwds={"color": "#cccccc", "label": "No data"}, ) ax.set_title(f"World Map — {COLUMN}", fontsize=18, fontweight="bold", pad=14) ax.set_axis_off() plt.tight_layout() plt.savefig("world_map_choropleth.png", dpi=150, bbox_inches="tight") plt.show() else: print(f"Column '{COLUMN}' not found. Available columns: {gdf.columns.tolist()}") # 6. Highlight specific countries Adjust the column name ("NAME", "ADMIN", "ISO_A3" …) to match your data NAME_COL = "NAME" # common options: "NAME", "ADMIN", "SOVEREIGNT" HIGHLIGHT = ["United Kingdom", "France", "Germany"] if NAME_COL in gdf.columns: mask = gdf[NAME_COL].isin(HIGHLIGHT) fig, ax = plt.subplots(figsize=(18, 10)) gdf[~mask].plot(ax=ax, color="#d0d0d0", edgecolor="#888888", linewidth=0.3) gdf[mask].plot(ax=ax, color="#e05c5c", edgecolor="#333333", linewidth=0.6) legend_handles = [ mpatches.Patch(color="#e05c5c", label="Highlighted"), mpatches.Patch(color="#d0d0d0", label="Other"), ] ax.legend(handles=legend_handles, loc="lower left", fontsize=10) ax.set_title("World Map — Highlighted Countries", fontsize=18, fontweight="bold", pad=14) ax.set_axis_off() plt.tight_layout() plt.savefig("world_map_highlighted.png", dpi=150, bbox_inches="tight") plt.show() else: print(f"Column '{NAME_COL}' not found. Available columns: {gdf.columns.tolist()}") ![[world_map_basic.png]] ![[world_map_highlighted.png]]