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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T20:40:55+00:00 2026-05-26T20:40:55+00:00

I have a plot in pylab which I want to clip to the borders

  • 0

I have a plot in pylab which I want to clip to the borders of a map of the UK.

I’ve also made a series of patches which contain the outlines of each country: one for England, one for Wales etc.

Clipping the plot one patch works brilliantly:

fig = plt.figure()
ax = fig.add_subplot(111)
im = ax.scatter(x,y,c = z)
ax.add_patch(patch)
im.set_clip_path(patch)

But if I try and do it for more than one, it leaves me with nothing – understandably, since no part of the plot is within each country simultaneously.

Does anyone know how I can clip using an ‘OR’ type statement? (ie. don’t clip if within this patch or this one etc).

  • 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-05-26T20:40:56+00:00Added an answer on May 26, 2026 at 8:40 pm

    I think you can do this by making multiple scatter plots, clipping each one with a unique patch (eg one has England, one has Ireland, etc). Though this might not be what you asked for, ie “Does anyone know how I can clip using an ‘OR’ type statement?”, it should have the same effect:

    import numpy as np
    import matplotlib.pyplot as plt
    import matplotlib.patches as patches
    
    np.random.seed(101)
    x = np.random.random(100)
    y = np.random.random(100)
    
    fig = plt.figure()
    ax = fig.add_subplot(111)
    imForEngland = ax.scatter(x,y)
    fig.savefig('beforeclip.png')
    imForWales = ax.scatter(x,y)
    england = patches.Circle((.75,.75),radius=.25,fc='none')
    wales = patches.Circle((.25,.25),radius=.25,fc='none')
    ax.add_patch(england)
    ax.add_patch(wales)
    imForEngland.set_clip_path(england)
    imForWales.set_clip_path(wales)
    
    fig.savefig('afterclip.png')
    

    Before the patches:
    enter image description here
    After the patches:
    enter image description here

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

Sidebar

Related Questions

I have a plot, which I want to save with a bigger resolution. But
Using matplotlib/pylab.... How do I plot 5 heatmaps as subplots which have the same
I have a plot figure and I want to retreive x and y cordinates
In relation to my question here , I have a plot for which the
With this approach. I have a line plot graph. I want to plot 'two'
I have a plot in which I'd like many ticks along the x-axis, yet
I have a plot which has timestamps on the x-axis and some signal data
I'm trying to make a plot with pylab/matplotlib, and I have two different sets
I have a plot with two y-axes, using twinx() . I also give labels
I have datapoints of different classes which I want to visualize. Here is the

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.