Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8048197
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T06:21:24+00:00 2026-06-05T06:21:24+00:00

I am trying to view a basic polygon read from a Shapefile using matplotlib

  • 0

I am trying to view a basic polygon read from a Shapefile using matplotlib and pyshp
But all my efforts yield just an empty axes with no polygon. Here are few of my tries, using the dataset showing the borders of Belgium:

import shapefile as sf
r = sf.Reader("BEL_adm/BEL_adm0")
p=r.shapes()
b=p[0]
points = b.points

import matplotlib.pyplot as plt
from matplotlib.path import Path
imporst matplotlib.patches as patches

verts = points

verts = []
for x,y in points:
    verts.append(tuple([x,y]))

codes = ['']*len(verts)
codes[0] = Path.MOVETO
codes[-1] = Path.CLOSEPOLY

for i in range(1,len(verts)):
    codes[i]=Path.LINETO

path = Path(verts, codes)
fig = plt.figure()
ax = fig.add_subplot(111)
patch = patches.PathPatch(path, facecolor='orange', lw=2)
ax.add_patch(patch)
ax.set_xlim(-2,2)
ax.set_ylim(-2,2)
plt.show()

Another try with patches also yields an empty frame:

fig = plt.figure(figsize=(11.7,8.3))

ax = plt.subplot(111)
x,y=zip(*b.points)
import matplotlib.patches as patches
import matplotlib.pyplot as plt
bol=patches.Polygon(b.points,True, transform=ax.transAxes)

ax.add_patch(bol)
ax.set_ylim(0,60)
ax.set_xlim(0,200)
plt.show()

Would be happy to see what I am missing.
Thanks, Oz

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T06:21:25+00:00Added an answer on June 5, 2026 at 6:21 am

    instead of calling set_xlim(), set_ylim() to set the range of axis, you can use ax.autoscale().

    For your Polygon version, you don’t need to set transform argument to ax.transAxes, just call:

    bol=patches.Polygon(b.points,True)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to view a users tweets from my app but twitter responses with
We are trying to get the Model-View-Presenter pattern used on (virtually) all new dev
I'm trying to load a new view into an existing view controller, but I
I'm trying to make a custom view in Django admin. I'm reading from this
I am trying to do a basic search feature but I am having a
I'm trying to pass Json to my View using ViewData Controller ViewData(JsonRegionList) = Json(RegionService.GetActiveRegions())
I'm trying to load a view controller from a nib in Interface Builder. My
I am using Visual Basic 2010 and am trying to create a datagrid where
I'm trying to build a basic contact form using jQuery. The markup is essentially
Hi I'm trying to do a basic update based on an id using Linq

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.