{"spec_id":"map-projections","library":"plotly","language":"python","code":"\"\"\" anyplot.ai\nmap-projections: World Map with Different Projections\nLibrary: plotly 6.7.0 | Python 3.13.13\nQuality: 88/100 | Updated: 2026-05-23\n\"\"\"\n\nimport os\n\nimport plotly.graph_objects as go\nfrom plotly.subplots import make_subplots\n\n\n# Theme tokens\nTHEME = os.getenv(\"ANYPLOT_THEME\", \"light\")\nPAGE_BG = \"#FAF8F1\" if THEME == \"light\" else \"#1A1A17\"\nINK = \"#1A1A17\" if THEME == \"light\" else \"#F0EFE8\"\nINK_SOFT = \"#4A4A44\" if THEME == \"light\" else \"#B8B7B0\"\n\n# Map geographic colors\nLAND_COLOR = \"#009E73\"  # Imprint palette position 1 — consistent across themes\nOCEAN_COLOR = \"#C8E0F0\" if THEME == \"light\" else \"#192632\"\nCOAST_COLOR = \"#006B4F\" if THEME == \"light\" else \"#00C990\"\nGRATICULE = \"rgba(26,26,23,0.20)\" if THEME == \"light\" else \"rgba(240,239,232,0.20)\"\n\n# Projections to showcase\nprojections = [\n    {\"name\": \"Mercator\", \"type\": \"mercator\"},\n    {\"name\": \"Robinson\", \"type\": \"robinson\"},\n    {\"name\": \"Mollweide\", \"type\": \"mollweide\"},\n    {\"name\": \"Orthographic\", \"type\": \"orthographic\"},\n    {\"name\": \"Equal Earth\", \"type\": \"equal earth\"},\n    {\"name\": \"Natural Earth\", \"type\": \"natural earth\"},\n]\n\n# Create 2×3 subplot grid of geo maps\nfig = make_subplots(\n    rows=2,\n    cols=3,\n    subplot_titles=[p[\"name\"] for p in projections],\n    specs=[[{\"type\": \"geo\"}, {\"type\": \"geo\"}, {\"type\": \"geo\"}], [{\"type\": \"geo\"}, {\"type\": \"geo\"}, {\"type\": \"geo\"}]],\n    horizontal_spacing=0.02,\n    vertical_spacing=0.10,\n)\n\n# Add each projection as a geo subplot\nfor idx, proj in enumerate(projections):\n    row = idx // 3 + 1\n    col = idx % 3 + 1\n    geo_key = f\"geo{idx + 1}\" if idx > 0 else \"geo\"\n\n    fig.add_trace(go.Scattergeo(lon=[], lat=[], mode=\"markers\", showlegend=False, geo=geo_key), row=row, col=col)\n\n    fig.update_layout(\n        **{\n            geo_key: {\n                \"projection_type\": proj[\"type\"],\n                \"showland\": True,\n                \"landcolor\": LAND_COLOR,\n                \"showocean\": True,\n                \"oceancolor\": OCEAN_COLOR,\n                \"showcoastlines\": True,\n                \"coastlinecolor\": COAST_COLOR,\n                \"coastlinewidth\": 1.2,\n                \"showcountries\": True,\n                \"countrycolor\": COAST_COLOR,\n                \"countrywidth\": 0.6,\n                \"showlakes\": True,\n                \"lakecolor\": OCEAN_COLOR,\n                \"showframe\": True,\n                \"framecolor\": INK_SOFT,\n                \"framewidth\": 1,\n                \"lataxis\": {\"showgrid\": True, \"gridcolor\": GRATICULE, \"gridwidth\": 0.8, \"dtick\": 30},\n                \"lonaxis\": {\"showgrid\": True, \"gridcolor\": GRATICULE, \"gridwidth\": 0.8, \"dtick\": 30},\n                \"bgcolor\": PAGE_BG,\n            }\n        }\n    )\n\n# Overall layout\nfig.update_layout(\n    autosize=False,\n    title={\n        \"text\": \"map-projections · python · plotly · anyplot.ai\",\n        \"font\": {\"size\": 16, \"color\": INK},\n        \"x\": 0.5,\n        \"xanchor\": \"center\",\n        \"y\": 0.99,\n    },\n    showlegend=False,\n    paper_bgcolor=PAGE_BG,\n    plot_bgcolor=PAGE_BG,\n    margin={\"l\": 80, \"r\": 40, \"t\": 80, \"b\": 60},\n)\n\n# Subplot title styling\nfig.update_annotations(font={\"size\": 12, \"color\": INK_SOFT})\n\n# Save\nfig.write_image(f\"plot-{THEME}.png\", width=800, height=450, scale=4)\nfig.write_html(f\"plot-{THEME}.html\", include_plotlyjs=\"cdn\")\n"}