# visualizacion-geoespacial-avanzada-con-pygmt
Visualización Geoespacial Avanzada con PyGMT
Volver a la portada del cursoPrimeros Pasos con PyGMT
Sección 1 · Introducción a PyGMT
En este video
- Instalas PyGMT con conda-forge, o con pip más GMT aparte, y verificas el entorno con show_versions
- Entiendes region (oeste, este, sur, norte) y projection, donde la M mayúscula fija el ancho total del mapa
- Dibujas costas, agua y fronteras con coast, controlas el marco con frame y guardas la figura con savefig en PNG y PDF
- Cargas relieve con load_earth_relief, lo dibujas con grdimage y colorbar, y ves por qué conviene pasar region de forma explícita
- Cambias estilos de forma temporal con pygmt.config dentro de un bloque with
# terminal
mamba create -n pygmt -c conda-forge pygmt
mamba activate pygmt
python -c "import pygmt; print(pygmt.__version__)"
# Salida:
# v0.19.0
python -c "import pygmt; pygmt.show_versions()"
# Salida:
# PyGMT information: version: v0.19.0
# numpy: 2.4.6 pandas: 3.0.3 xarray: 2026.4.0
# ghostscript: 10.07.0
# GMT library information: version: 6.7.0
# library path: .../gmt-6.7.0/bin/gmt_w64.dll
# lienzo.py
import pygmt
fig = pygmt.Figure()
fig.basemap(region=[-118, -86, 14, 33],
projection="M15c", frame=True)
fig.show()
# costa.py
import pygmt
fig = pygmt.Figure()
fig.coast(region=[-118, -86, 14, 33],
projection="M15c", land="tan",
water="lightblue", shorelines="0.5p",
borders="1/0.8p,red", frame=True)
fig.show()
# marco.py
import pygmt
fig = pygmt.Figure()
fig.coast(region=[-118, -86, 14, 33],
projection="M15c", land="gray",
water="lightblue",
frame=["WSne+tMéxico", "a4f2"])
fig.show()
import os
fig.savefig("mexico.png", dpi=300)
fig.savefig("mexico.pdf")
for f in ["mexico.png", "mexico.pdf"]:
print(f, os.path.getsize(f) // 1024, "KB")
import pygmt
grid = pygmt.datasets.load_earth_relief(
resolution="10m", region=[-118, -86, 14, 33])
print(grid.shape)
print(float(grid.min()), float(grid.max()))
# Paso que el video ejecuta sin mostrarlo en pantalla:
region = [-118, -86, 14, 33]
fig = pygmt.Figure()
fig.grdimage(grid=grid, region=region,
projection="M15c", cmap="geo",
frame=True)
fig.colorbar(frame=["a2000", "x+lElevación", "y+lm"])
fig.show()
import pygmt
fig = pygmt.Figure()
with pygmt.config(MAP_FRAME_TYPE="plain",
FORMAT_GEO_MAP="ddd.x"):
fig.basemap(region=[-118, -86, 14, 33],
projection="M12c", frame="af")
fig.coast(land="gray", shorelines="0.3p")
fig.show()