diff --git a/Fig6_PyGMT_geopandas.ipynb b/Fig6_PyGMT_geopandas.ipynb new file mode 100644 index 0000000..46a09f3 --- /dev/null +++ b/Fig6_PyGMT_geopandas.ipynb @@ -0,0 +1,97 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": null, + "id": "760146f6-d4c9-4e69-b539-f42e057c7945", + "metadata": {}, + "outputs": [], + "source": [ + "import geopandas as gpd\n", + "import pygmt\n", + "\n", + "provider = \"https://naciscdn.org/naturalearth\"\n", + "states = gpd.read_file(f\"{provider}/50m/cultural/ne_50m_admin_1_states_provinces.zip\")\n", + "rivers = gpd.read_file(f\"{provider}/50m/physical/ne_50m_rivers_lake_centerlines.zip\")\n", + "cities = gpd.read_file(f\"{provider}/110m/cultural/ne_110m_populated_places_simple.zip\")\n", + "\n", + "states = states[states[\"admin\"] == \"United States of America\"]\n", + "rivers = rivers[rivers.intersects(states.union_all())]\n", + "cities = cities[cities[\"adm0name\"] == \"United States of America\"]\n", + "\n", + "states[\"area\"] = states.to_crs(epsg=6933).area / 10 ** 9\n", + "\n", + "fig = pygmt.Figure()\n", + "fig.basemap(projection=\"L-96/35/33/41/12c\", region=[-126, -66, 25, 49], frame=\"+n\")\n", + "\n", + "pygmt.makecpt(cmap=\"hawaii\", series=[0, states[\"area\"].max()], reverse=True)\n", + "fig.plot(data=states, cmap=True, pen=\"0.2p,gray50\", fill=\"+z\", aspatial=\"Z=area\")\n", + "fig.colorbar(frame=\"xaf+lArea (1000 km@+2@+)\", position=\"jRB+o1.9c/0.2c+w3c/0.15c+ml\")\n", + "\n", + "fig.plot(data=rivers, pen=\"0.5p,dodgerblue4\")\n", + "\n", + "fig.plot(data=cities, style=\"s0.17c\", fill=\"darkorange\", pen=\"0.5p\")\n", + "fig.text(\n", + " x=cities.geometry.x,\n", + " y=cities.geometry.y,\n", + " text=cities[\"name\"],\n", + " offset=\"0.35c/0.2c\",\n", + " justify=\"BC\",\n", + " font=\"4.5p,Helvetica-Bold\",\n", + " fill=\"white@30\",\n", + " pen=\"0.2p,darkorange\",\n", + " clearance=\"0.05c+tO\",\n", + ")\n", + "\n", + "# Add the states Alaska and Hawaii separately in the lower left corner\n", + "for name, xshift in zip([\"Alaska\", \"Hawaii\"], [\"1.2c\", \"2.8c\"]):\n", + " substate = states[(states[\"name\"] == name)]\n", + " substate = substate.explode()\n", + " substate = substate[substate.to_crs(epsg=6933).area > 1.0e8].dissolve()\n", + " region = pygmt.info(substate, spacing=1)\n", + " with fig.shift_origin(xshift=xshift):\n", + " fig.plot(\n", + " data=substate,\n", + " region=region,\n", + " projection=\"M2c\",\n", + " cmap=True,\n", + " pen=\"0.2p,gray50\",\n", + " fill=\"+z\",\n", + " aspatial=\"Z=area\",\n", + " )\n", + "\n", + "fig.show()\n", + "# fig.savefig(fname=\"Fig6_PyGMT_geopandas.png\")" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "456f81ee-f666-4d2d-9147-290040583447", + "metadata": {}, + "outputs": [], + "source": [] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 3 (ipykernel)", + "language": "python", + "name": "python3" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython3", + "version": "3.12.3" + } + }, + "nbformat": 4, + "nbformat_minor": 5 +}