close

How do I plot Shapely polygons and objects using Matplotlib?

Hello Guys, How are you all? Hope You all Are Fine. Today We Are Going To learn about How do I plot Shapely polygons and objects using Matplotlib in Python. So Here I am Explain to you all the possible Methods here.

Without wasting your time, Let’s start This Article.

Table of Contents

How do I plot Shapely polygons and objects using Matplotlib?

  1. How do I plot Shapely polygons and objects using Matplotlib?

    A little late but I find the most convenient way to do this is with Geopandas as suggested above but without writing to a file first.

  2. I plot Shapely polygons and objects using Matplotlib

    A little late but I find the most convenient way to do this is with Geopandas as suggested above but without writing to a file first.

Method 1

Use:

import matplotlib.pyplot as plt

x,y = polygon1.exterior.xy
plt.plot(x,y)

Or, more succinctly:

plt.plot(*polygon1.exterior.xy)

Method 2

A little late but I find the most convenient way to do this is with Geopandas as suggested above but without writing to a file first.

from shapely.geometry import Polygon
import matplotlib.pyplot as plt
import geopandas as gpd

polygon1 = Polygon([(0,5),
                    (1,1),
                    (3,0),
                    ])

 p = gpd.GeoSeries(polygon1)
 p.plot()
 plt.show()
Polygon Plotted using Geopandas

Summery

It’s all About this issue. Hope all Methods helped you a lot. Comment below Your thoughts and your queries. Also, Comment below which Method worked for you? Thank You.

Also, Read