FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

imshow interpolation uses masked values · Issue #8012 · matplotlib/matplotlib · GitHub

Repository navigation

imshow interpolation uses masked values #8012

Description

Bug report

I recently upgraded to v2.0.0 and noticed that the new imshow interpolation is not honoring masked values. This is likely related to the new edge handling, described here: http://matplotlib.org/examples/pylab_examples/image_interp.html

Code for reproduction

a = np.random.random((7,7))*1000
ndv = -9999.0
a[2:4,1:5] = ndv
am = np.ma.masked_equal(a, ndv)

plt.figure()
#Plot with no interpolation, looks fine
plt.imshow(am, interpolation='none')
plt.title("interpolation='none'")
#Plot with bilinear interpolation, the -9999.0 values are used 
plt.imshow(am, interpolation='bilinear')
plt.title("interpolation='bilinear'")

Actual outcome

Expected outcome

The interpolation should ignore masked values as in previous versions.

Matplotlib version

  • Matplotlib v2.0.0, Python 2.7.13, OSX
  • installed from pip

Activity

  1. changed the title [-]imshow interpolation ignores masked values[/-] [+]imshow interpolation uses masked values[/+] on Feb 3, 2017
  2. added this to the milestone on Feb 3, 2017
  3. tacaswell commented on Feb 3, 2017

    Member

    It is honoring it, just in weird ways, will have a PR shortely:

  4. tacaswell commented on Feb 3, 2017

    Member

    Note that in carves out a larger area because the region of screen pixels that get input from the masked data values is larger.

  5. tacaswell commented on Feb 3, 2017

    Member

    The fix seems to break something else, will get to this tomorrow.

  6. added
    Release criticalFor bugs that make the library unusable (segfaults, incorrect plots, etc) and major regressions.
    on Feb 3, 2017
  7. self-assigned this
    on Feb 3, 2017
  8. tacaswell commented on Feb 5, 2017

    Member

    This is way nastier than I expected 😞

  9. QuLogic commented on Mar 13, 2017

    Member

    @tacaswell Doesn't this still require some tweaks (cf. the last comment in #8024 and #8183)?

  10. tacaswell commented on Mar 14, 2017

    Member

    Yes, on my to-do list for tonight

  11. gurraburra commented on Aug 29, 2024

    Note that in carves out a larger area because the region of screen pixels that get input from the masked data values is larger.

    This seems still to be the case, would It be possible for interpolation to not change the size of the masked area?

  12. tacaswell commented on Aug 29, 2024

    Member

    This seems still to be the case, would It be possible for interpolation to not change the size of the masked area?

    No, because the way the interpolation works is by (effectively) convolving the input data with a fixed size kernel. Any place you evaluate the kernel that overlaps with a masked point also needs to be poisoned (e.g. if you drop a np.nan into any interpolation method then the output is always np.nan).

  13. gurraburra commented on Aug 29, 2024

    This seems still to be the case, would It be possible for interpolation to not change the size of the masked area?

    No, because the way the interpolation works is by (effectively) convolving the input data with a fixed size kernel. Any place you evaluate the kernel that overlaps with a masked point also needs to be poisoned (e.g. if you drop a np.nan into any interpolation method then the output is always np.nan).

    Yes I understand. My problem is not that I have np.nan, but simply that I want to mask some voxels from the image being shown. One solution could be to add a mask option to imshow, then the interpolation could be done before masking. Or another option would be to detect if the data is masked, then remove the mask (perhaps also replace masked values with zero), do the interpolation and then reapply the mask.

  14. tacaswell commented on Aug 29, 2024

    Member

    If you want the masked pixel to be transparent, you are stuck, if you want to make it white, you can do something like

    mask = np.ones((*data.shape, 4))  # RGBA of the right size
    mask[~to_hide] = 0                # make the pixels you want to keep transparent
    im_data = ax.imshow(data)
    im_mask = ax.imshow(mask, zorder=im1.get_zorder() + 1, interpolation='nearest')
    
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

Release criticalFor bugs that make the library unusable (segfaults, incorrect plots, etc) and major regressions.

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions


    Back | FazBrowse Home | New Git URL