You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
a=np.random.random((7,7))*1000ndv=-9999.0a[2:4,1:5] =ndvam=np.ma.masked_equal(a, ndv)
plt.figure()
#Plot with no interpolation, looks fineplt.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.
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).
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.
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')
Activity
[-]imshow interpolation ignores masked values[/-][+]imshow interpolation uses masked values[/+]tacaswell commentedon Feb 3, 2017
It is honoring it, just in weird ways, will have a PR shortely:
tacaswell commentedon Feb 3, 2017
Note that in carves out a larger area because the region of screen pixels that get input from the masked data values is larger.
tacaswell commentedon Feb 3, 2017
The fix seems to break something else, will get to this tomorrow.
tacaswell commentedon Feb 5, 2017
This is way nastier than I expected 😞
QuLogic commentedon Mar 13, 2017
@tacaswell Doesn't this still require some tweaks (cf. the last comment in #8024 and #8183)?
tacaswell commentedon Mar 14, 2017
Yes, on my to-do list for tonight
gurraburra commentedon 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?
tacaswell commentedon Aug 29, 2024
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.naninto any interpolation method then the output is alwaysnp.nan).gurraburra commentedon Aug 29, 2024
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.
tacaswell commentedon Aug 29, 2024
If you want the masked pixel to be transparent, you are stuck, if you want to make it white, you can do something like