Country Travel Tracker

1 minute read

PIC

These are the countries Iโ€™ve travelled to so far! This script (bottom of page) lets me add a country code, and itโ€™ll update this page :).

Count = 23 (As of 2024-09-12)

๐Ÿ‡จ๐Ÿ‡ฆ Canada

๐Ÿ‡บ๐Ÿ‡ธ United States

๐Ÿ‡ฒ๐Ÿ‡ฝ Mexico

๐Ÿ‡ฌ๐Ÿ‡น Guatemala

๐Ÿ‡ง๐Ÿ‡ท Brazil

๐Ÿ‡ฉ๐Ÿ‡ด Dominican Republic

๐Ÿ‡ฌ๐Ÿ‡ง United Kingdom

๐Ÿ‡ซ๐Ÿ‡ท France

๐Ÿ‡ช๐Ÿ‡ธ Spain

๐Ÿ‡ฒ๐Ÿ‡จ Monaco

๐Ÿ‡ฎ๐Ÿ‡น Italy

๐Ÿ‡ฉ๐Ÿ‡ช Germany

๐Ÿ‡จ๐Ÿ‡ฟ Czechia

๐Ÿ‡จ๐Ÿ‡ญ Switzerland

๐Ÿ‡ณ๐Ÿ‡ฑ Netherlands

๐Ÿ‡ฆ๐Ÿ‡บ Australia

๐Ÿ‡ณ๐Ÿ‡ฟ New Zealand

๐Ÿ‡ฐ๐Ÿ‡ท Korea, Republic of

๐Ÿ‡น๐Ÿ‡ญ Thailand

๐Ÿ‡ป๐Ÿ‡ณ Viet Nam

๐Ÿ‡น๐Ÿ‡ท Tรผrkiye

๐Ÿ‡ฌ๐Ÿ‡ท Greece

๐Ÿ‡ป๐Ÿ‡ฆ Holy See (Vatican City State)

Python Visualization Script

The following script is how I generated the image above from country codes.

import os
import random

import geopandas as gpd
import matplotlib.pyplot as plt
import seaborn as sns

# Path to your local shapefile
shapefile_path = "./ne_10m_admin_0_countries/ne_10m_admin_0_countries.shp"

# Load the local shapefile
world = gpd.read_file(shapefile_path)

# List of visited countries (ISO 3166-1 alpha-3 country codes)
visited_countries = [
    "CAN",
    "USA",
    "MEX",
    "GTM",
    "BRA",
    "DOM",
    "GBR",
    "FRA",
    "ESP",
    "MCO",
    "ITA",
    "DEU",
    "CZE",
    "AUS",
    "NZL",
    "KOR",
    "THA",
    "VNM",
    "TUR",
    "GRC",
    "VAT",
]

# Create a new column 'visited' to mark visited countries
world["visited"] = world["ADM0_A3"].apply(
    lambda x: "Visited" if x in visited_countries else "Not Visited"
)

# Create a unique color for each visited country
# Get a seaborn palette with enough colors for the visited countries
palette = sns.color_palette("Set2", len(visited_countries))

# Assign each visited country a color from the palette
visited_colors = {country: palette[i] for i, country in enumerate(visited_countries)}

# Create a new column to assign colors to visited countries
world["color"] = world["ADM0_A3"].apply(
    lambda x: visited_colors.get(x, "#fafafa")
)  # Default non-visited countries to gray

# Plot the map
fig, ax = plt.subplots(1, 1, figsize=(15, 10))

# Plot country borders
world.boundary.plot(ax=ax, linewidth=1, color="black")

# Plot visited countries with their assigned colors
world.plot(ax=ax, color=world["color"], edgecolor="black", legend=True)

# Add title
ax.set_title("Countries I've Visited", fontsize=16)
ax.axis("off")

output_image_path = (
    "assets/images/2024-09-05-countries-i-ve-travelled-to/visited_countries.png"
)
# Save the map as a PNG file
plt.savefig(
    os.path.join("../", output_image_path),
    bbox_inches="tight",
    dpi=300,
)

Comments