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)]
We can plot Shapely polygons by resorting to Geopandas plot() function, or directly, extracting the polygon's boundaries.
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
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:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With