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 8983679
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T20:53:59+00:00 2026-06-15T20:53:59+00:00

When plotting small patch objects in matplotlib, artifacts are introduced due to the display

  • 0

When plotting small patch objects in matplotlib, artifacts are introduced due to the display resolution. Using anti-aliasing does not solve the problem.

Is there a solution to this problem?

import matplotlib.pyplot as plt
import matplotlib.patches as patches

ax = plt.axes()

for x in range(-10,11):
    for y in range(-10,11):
        rect = patches.Rectangle((x, y), width=0.1, height=0.1, color='k',aa=True)
        ax.add_patch(rect)

plt.xlim([-30, 30])
plt.ylim([-30, 30])
plt.show()

output

  • 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-15T20:54:01+00:00Added an answer on June 15, 2026 at 8:54 pm

    Thanks for putting together a simple example of the problem – it really makes investigating this much easier!

    Is there a solution to this problem?

    Yes, it turns out there is! My initial guess, by just looking at the image you attached, was that there is some strange clipping/snapping going on. After ruling out the antialiasing possibility (by flicking the switch that you provided) my only other avenue of testing was to set the “snap” keyword to false (for the very limited docs on the snap method see http://matplotlib.org/api/artist_api.html#matplotlib.artist.Artist.set_snap).

    Setting the snap does the trick and you end up with the expected results:

    import matplotlib.pyplot as plt
    import matplotlib.patches as patches
    
    ax = plt.axes()
    
    for x in range(-10,11):
        for y in range(-10,11):
            rect = patches.Rectangle((x, y), width=0.1, height=0.1, 
                                     color='k', snap=False)
            ax.add_patch(rect)
    
    plt.xlim([-30, 30])
    plt.ylim([-30, 30])
    plt.show()
    

    A visual comparison (probably best opening the image in a new window as your browser will probably scale the image and introduce further visual effects):

    comparison of the snap property

    I’m not particularly knowledgeable about the snap property in mpl and whether this is really desirable behaviour, so I will post a question on the mpl-devel mailing list to open up a conversation about this question. Hopefully this answer will help you in the meantime.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm plotting data in Python using matplotlib. I am updating the data of the
I'm plotting a bunch of UTM coordinates using a matplotlib.pyplot.scatter. I also have a
I am plotting things using matplotlib and Basemap (within a wxpython gui). Currently, my
I am plotting speed/distance data from racing events, using Matplotlib, for example distance vs.
I am plotting a heatmap in matplotlib using: plt.pcolor(rand(5,5)) how can I annotate the
I am plotting 20 different lines on a single plot using matplotlib. I use
I have written a small webapp using the flask framework that involves plotting using
While plotting using Matplotlib, I have found how to change the font size of
When plotting color-maps using gnuplot, I usually use the following lines: ... set palette
I am plotting an array of pie charts, each using the same two colors

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.