I have a data frame with latitude, longitude and annual consumption data. I am trying to plot the annual consumption data using GeoPandas with a quantile scheme by making a polygon column. I followed the following tutorial. enter link description here Show I used the latitude and longitude data to make polygon shapes using the following code.
My data frame looks like below The issue is, when I plot it, it looks like a big mess of interconnecting points. The boundaries are not seperated. I want a similar boundary separation like the tutorial based on longitude and latitude data. To plot shapely polygons and objects using matplotlib, the steps are as follows −
Examplefrom shapely.geometry import Polygon import matplotlib.pyplot as plt plt.rcParams["figure.figsize"] = [7.00, 3.50] plt.rcParams["figure.autolayout"] = True polygon1 = Polygon([(0, 5), (1, 1), (3, 0), (4, 6), ]) x, y = polygon1.exterior.xy plt.plot(x, y, c="red") plt.show() Output
Updated on 06-May-2021 12:51:12
Suscribe for monthly updates:Plotting shapely polygons is something we will often do, either for its own sake when we need to create a map, of for visual debugging purposes when we are crafting an algorithm. To illustrate this with a non-trivial example, let’s first create a polygon (which will have a hole in it) by computing the difference between two polygons, and plot the resulting one. Using Geopandas GeoSeries.plot()The simplest and more general way to plot a shapely polygon is to resort to Geopandas. More precisely, we will create a GeoSeries that holds our polygon. There are many things we can do with a GeoSeries object (see the official docs). In particular, the GeoSeries class has a
You can also plot the polygon’s boundary with
Manually extracting exterior and interior boundariesAn alternative method, in case we don’t want to rely on Geopandas, is to do this manually. We will need to extract both exterior and interior boudnaries (if the polygon has holes in it). Each polygon object has an exterior ring, and zero or multiple interior rings. We can extract the coordinates of these rings and plot them as follows: |