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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T11:35:17+00:00 2026-05-30T11:35:17+00:00

I have 2D data that I am trying to display with imshow. Regions of

  • 0

I have 2D data that I am trying to display with imshow. Regions of the data are nan and marked as masked.

Because of things like anisotropy, I use bilinear interpolation and would like to keep doing so. Using is_bad I am pretty sure I am getting the masked values are being rendered the way I want them, but the nan color seems to bleed into the good part of the data causing a blur.

Is there a good way to sharpen up the interface between nan and non-nan data? Do I have to identify the border and draw a line over it or can I do this with imshow parameters?

Thanks!

Eli

  • 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-30T11:35:18+00:00Added an answer on May 30, 2026 at 11:35 am

    Well, this is a bit of a convoluted solution, but I don’t know of a better one.

    Just to demonstrate the problem you’re talking about to people who may not be familiar with it:

    import numpy as np
    import matplotlib.pyplot as plt
    data = np.random.random((10,10))
    data[[2, 5, 7], [5, 8, 1]] = np.nan
    
    plt.imshow(data)
    plt.show()
    

    enter image description here

    The blurring is because matplotlib interpolates alpha (transparency) values. Changing this would require low-level tweaking.

    However, as long as you don’t need to show the layer beneath the image in the regions of no data, you can do something like this:

    import numpy as np
    import matplotlib.pyplot as plt
    import matplotlib as mpl
    
    # Generate some data...
    data = np.random.random((10,10))
    data[[2, 5, 7], [5, 8, 1]] = np.nan
    
    # Convert it to a masked array instead of just using nan's..
    data = np.ma.masked_invalid(data)
    
    # Plot a version with the invalid data replaced with the mean...
    plt.imshow(data.filled(data.mean()))
    
    # Now plot a white (or whatever color you'd like), nearest-interpolated array
    # over the invalid values...
    bad_data = np.ma.masked_where(~data.mask, data.mask)
    plt.imshow(bad_data, interpolation='nearest', cmap=mpl.cm.gray_r)
    
    plt.show()
    

    enter image description here

    If we don’t plot the original data using the “filled” version (data.filled(data.mean())), we’ll get “halos” around the blocked-out invalid values:

    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 am trying to have a tree display custom data that looks like this.
I have data in a sql database that'd I'd like to display on a
I have some data that I am trying to display using the Google Visualization
I have the following data set that I am trying to plot with ggplot2,
I have two arrays of data that I'm trying to amalgamate. One contains actual
I have some data about a day's events that I'm trying to visualise as
I have a very large possible data set that I am trying to visualize
I have a form that is trying to insert some data into an SQL
I have a data.frame and I'm trying to create a frequency table that shows
I have an ScrollViewer that I am trying to do data binding on 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.