Geovisualización#
Coropletas#
Cartogramas#
import geopandas as gpd
import matplotlib.pyplot as plt
gdf = gpd.read_file("https://github.com/algarciach/AnalisisGeoespacial/raw/main/Covid19_model/Data/covid19_municipios_antioquia.gpkg")
gdf.info()
<class 'geopandas.geodataframe.GeoDataFrame'>
RangeIndex: 125 entries, 0 to 124
Data columns (total 15 columns):
# Column Non-Null Count Dtype
--- ------ -------------- -----
0 codigo_municipio 125 non-null object
1 nombre_municipio 125 non-null object
2 codigo_subregion 125 non-null object
3 nombre_subregion 125 non-null object
4 area_municipio 125 non-null float64
5 altitud 125 non-null float64
6 temperatura 125 non-null float64
7 humedad_relativa 125 non-null float64
8 poblacion 125 non-null int64
9 urbanizacion 125 non-null float64
10 densidad 125 non-null float64
11 muertes_covid19 125 non-null int64
12 recuperados_covid19 125 non-null int64
13 cfr 125 non-null float64
14 geometry 125 non-null geometry
dtypes: float64(7), geometry(1), int64(3), object(4)
memory usage: 14.8+ KB
# Plot the GeoDataFrame by urbanizacion
f, ax = plt.subplots(1, 1, figsize=(10, 10))
gdf.plot(column='urbanizacion', ax=ax, legend=True, scheme='Quantiles', cmap='viridis', legend_kwds={'fmt':'{:.2f}'})
plt.title('Indice de urbanizacion por Municipio en Antioquia')
ax.set_axis_off()
plt.axis('equal')
plt.show()
---------------------------------------------------------------------------
ModuleNotFoundError Traceback (most recent call last)
File /opt/hostedtoolcache/Python/3.11.13/x64/lib/python3.11/site-packages/geopandas/plotting.py:736, in plot_dataframe(df, column, cmap, color, ax, cax, categorical, legend, scheme, k, vmin, vmax, markersize, figsize, legend_kwds, categories, classification_kwds, missing_kwds, aspect, autolim, **style_kwds)
735 try:
--> 736 import mapclassify
738 except ImportError:
ModuleNotFoundError: No module named 'mapclassify'
During handling of the above exception, another exception occurred:
ImportError Traceback (most recent call last)
Cell In[3], line 3
1 # Plot the GeoDataFrame by urbanizacion
2 f, ax = plt.subplots(1, 1, figsize=(10, 10))
----> 3 gdf.plot(column='urbanizacion', ax=ax, legend=True, scheme='Quantiles', cmap='viridis', legend_kwds={'fmt':'{:.2f}'})
4 plt.title('Indice de urbanizacion por Municipio en Antioquia')
5 ax.set_axis_off()
File /opt/hostedtoolcache/Python/3.11.13/x64/lib/python3.11/site-packages/geopandas/plotting.py:962, in GeoplotAccessor.__call__(self, *args, **kwargs)
960 kind = kwargs.pop("kind", "geo")
961 if kind == "geo":
--> 962 return plot_dataframe(data, *args, **kwargs)
963 if kind in self._pandas_kinds:
964 # Access pandas plots
965 return PlotAccessor(data)(kind=kind, **kwargs)
File /opt/hostedtoolcache/Python/3.11.13/x64/lib/python3.11/site-packages/geopandas/plotting.py:739, in plot_dataframe(df, column, cmap, color, ax, cax, categorical, legend, scheme, k, vmin, vmax, markersize, figsize, legend_kwds, categories, classification_kwds, missing_kwds, aspect, autolim, **style_kwds)
736 import mapclassify
738 except ImportError:
--> 739 raise ImportError(mc_err)
741 if classification_kwds is None:
742 classification_kwds = {}
ImportError: The 'mapclassify' package is required to use the 'scheme' keyword.

# Plot the GeoDataFrame by Urbanizacion
f, ax = plt.subplots(1, 1, figsize=(10, 10))
gdf.plot(column='urbanizacion', ax=ax, legend=True, scheme='EqualInterval', cmap='viridis', legend_kwds={'fmt':'{:.2f}'})
plt.title('Indice de Urbanizacion por Municipio en Antioquia')
ax.set_axis_off()
plt.axis('equal')
plt.show()

# Plot the GeoDataFrame by densidad
f, ax = plt.subplots(1, 1, figsize=(10, 10))
gdf.plot(column='densidad', ax=ax, legend=True, scheme='Quantiles', cmap='viridis', legend_kwds={'fmt':'{:.2f}'})
plt.title('Densidad de Población por Municipio en Antioquia')
ax.set_axis_off()
plt.axis('equal')
plt.show()

# Plot the GeoDataFrame by densidad
f, ax = plt.subplots(1, 1, figsize=(10, 10))
gdf.plot(column='densidad', ax=ax, legend=True, scheme='EqualInterval', cmap='viridis', legend_kwds={'fmt':'{:.2f}'})
plt.title('Densidad de Población por Municipio en Antioquia')
ax.set_axis_off()
plt.axis('equal')
plt.show()

bins = [ 2.5, 5, 7.5, 10]
f, ax = plt.subplots(1, 1, figsize=(10, 10))
gdf.plot(column='cfr', ax=ax, legend=True, scheme='UserDefined', cmap='RdYlGn',
classification_kwds={'bins': bins}, legend_kwds={'title':'Rangos (0-10)'})
plt.title('Tasa de Letalidad por Municipio en Antioquia')
plt.axis('equal')
ax.set_axis_off()
plt.show()
