Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to plot a list of Shapely points

I created a list of Shapely Point objects based on the point data set. How can I plot this list of points below?

points = [Point(-4.85624511894443, 37.1837967179202), 
          Point(-4.855703975302475, 37.18401757756585),
          Point(-4.85516283166052, 37.1842384372115),
          Point(-4.85343407576431, 37.182006629169),
          Point(-4.85347524651836, 37.1804461589773),
          Point(-4.855792124429867, 37.18108913443582),
          Point(-4.85624511894443, 37.1837967179202)]
like image 887
Hello-experts Avatar asked Dec 19 '19 23:12

Hello-experts


People also ask

How do you plot polygon points in Python?

We can plot Shapely polygons by resorting to Geopandas plot() function, or directly, extracting the polygon's boundaries.


1 Answers

You can get two lists of x and y coordinates by accessing x and y attributes of Point and then use, for example, plt.scatter or plt.plot functions of Matplotlib as follows:

import matplotlib.pyplot as plt
from shapely.geometry import Point

points = [Point(-4.85624511894443, 37.1837967179202), 
          Point(-4.855703975302475, 37.18401757756585),
          Point(-4.85516283166052, 37.1842384372115),
          Point(-4.85343407576431, 37.182006629169),
          Point(-4.85347524651836, 37.1804461589773),
          Point(-4.855792124429867, 37.18108913443582),
          Point(-4.85624511894443, 37.1837967179202)]
xs = [point.x for point in points]
ys = [point.y for point in points]
plt.scatter(xs, ys)
# or plt.plot(xs, ys) if you want to connect points by lines

enter image description here


If you are using Jupyter Notebook or Jupyter Lab, you could wrap the list of points in a MultiPoint object to get an SVG image. This can be useful for debugging purposes when you want to plot something quickly without importing Matpotlib.

>>> MultiPoint(points)

gives:
enter image description here

like image 192
Georgy Avatar answered Oct 11 '22 20:10

Georgy