Advanced Plotting with Geoplot
Discover what can be done with the Geoplot package for maps visualization.
We'll cover the following
Introduction
While GeoPandas and Matplotlib offer a simple interface for basic plotting of vectorial maps, more complex tasks can become rather challenging to implement. Recognizing this gap, Geoplot was conceived as a high-level Python geospatial plotting library. It offers a suite of tools designed to facilitate the visualization of Geopandas, GeoDataFrame, and GeoSeries objects. In essence, Geoplot is to GeoPandas what Seaborn is to Matplotlib, providing an advanced layer of abstraction for ease of use.
Geoplot boasts support for an extensive array of plot types. These range from basic points, lines, and polygons to more complex representations such as cartograms, sankey diagrams, and density plots. It also enables certain geometric operations, including the creation of Voronoi polygons.
In the the next two sections, we'll explore two of Geoplot's key features and their functionality:
Cartograms
Density plots
Cartograms
A cartogram is a type of map that alters the geometry or space of the map to represent the value of a specific variable. This variable could be any measurable attribute, such as population, income, or election results. Rather than representing geographical space in a literal sense, cartograms prioritize the visual representation of the chosen data attribute. The result is a map where the size of the regions (like countries, states, or districts) is directly proportional to the data of interest, rather than their actual geographical area.
Cartograms can be used in data visualization and geospatial analysis to provide an alternative perspective on geographic distribution of data. By adjusting the size of the regions according to the data, cartograms allow for immediate visual comparison between regions, making disparities or patterns more apparent. This is especially useful when the size of the regions in a typical map could otherwise overshadow or hide the underlying data trends. For instance, a cartogram could be used to visualize population density, where each region is resized according to its population, offering a much clearer picture of global population distribution than a standard map.
In the following example, we create a cartogram to represent the police expenditure per capita in Atlanta. The cartogram
method from geoplot
receives the GeoDataFrame
to be plotted (line 8), the column that should be used to scale the polygons (i.e., scale
argument, line 9), and optionally, the column to create a color scale (i.e., hue
argument, in line 10).
Get hands-on with 1400+ tech skills courses.