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
When interpolating a 2D heatmap on Windows, I get colored artifacts drawn over the 'bad' points. I am using LogNorm for normalization. I suspect it has something to do with the masked values caused by having 0s in a LogNorm. I set then to white with set_bad() function. On Linux, the interpolation looks entirely different (the white areas are not interpolated) and no artifacts can be seen.
I've also tried different interpolating methods, all of them seem to create artifacts, except for nearest.
Zooming in creates more artifacts:
Zooming in to one of these artifacts, reveals this:
Interesting that you do not see the 'fuzz' on linux. This is due to some instability in the interpolation over big constant regions near the clipping limits.
When you interpolate using "Gaussian" you are probably getting data that is "near" zero, but not quite due to floating point round off, which is different between machines. It doesn't show up as white because its not quite invalid...
I'm not actually sure why imshow has an interpolation keyword as it seems to cause no end of trouble. Having the user do the interpolation themsleves outside of imshow would get rid of a black box that is expected to work magically.
I've "solved" it by creating a custom colormap that defines 0 as white (which was my intention anyway), and by adding clip=True on the LogNorm. The artifacts are probably still there, but now at least they are the same color.
I am not familiar with the codebase of matplotlib, but I believe @jklymak has a point in that using imshow with interpolation does not give the user any chance to customize interpolation results. Interpolating before would allow fixing rounding errors.
@tacaswell The reason I do not see it in Linux is that the interpolation function does not work on the 'masked' area.
I just checked against 2.2 and the artifacts are gone. There was another curious side-effect: the LogNorm would return 'bad' for value of 0, and now it seems to return a valid value, since my original code now prints an entirely blue squared plot with no white stripes. I reproduced the stripes by writing np.nan instead of 0, and verified artifacts are gone.
If LogNorm for 0 should have returned np.nan (and thus created the white stripes), a bug should be filed for that. But as for this particular bug, it has been resolved. Thanks!
@arthur00 LogNorm returning valid values for 0 seems like a bug, can you open a new issue for that?
The reason imshow needs an interpolation kwarg is that the number and pitch of the pixels in the input image and the number and pitch of the pixels in the output image do not match so there will be interpolation (either up or down sampling). There is not a generic 'right' way to do this, so we expose a way for the user to change it.
LogNorm seems to be correctly returning 'masked' for 0, however the set_bad('white') does not seem to be working anymore. LogNorm(np.nan) returns 0.0 for some reason - I imagined it would return 'masked'.
Running the snippet of code I wrote at the beginning will create a blue squared block on matplotlib 2.2.0 (Windows) and will create graph with horizontal stripes on matplotlib 2.1.1 (Windows)
Activity
tacaswell commentedon Dec 8, 2017
Interesting that you do not see the 'fuzz' on linux. This is due to some instability in the interpolation over big constant regions near the clipping limits.
Duplicate of #8947
jklymak commentedon Dec 8, 2017
When you interpolate using "Gaussian" you are probably getting data that is "near" zero, but not quite due to floating point round off, which is different between machines. It doesn't show up as white because its not quite invalid...
I'm not actually sure why
imshowhas an interpolation keyword as it seems to cause no end of trouble. Having the user do the interpolation themsleves outside ofimshowwould get rid of a black box that is expected to work magically.arthur00 commentedon Dec 8, 2017
I've "solved" it by creating a custom colormap that defines 0 as white (which was my intention anyway), and by adding clip=True on the LogNorm. The artifacts are probably still there, but now at least they are the same color.
I am not familiar with the codebase of matplotlib, but I believe @jklymak has a point in that using imshow with interpolation does not give the user any chance to customize interpolation results. Interpolating before would allow fixing rounding errors.
@tacaswell The reason I do not see it in Linux is that the interpolation function does not work on the 'masked' area.
dstansby commentedon Apr 5, 2018
Is this still a problem in version
2.2?arthur00 commentedon Apr 9, 2018
I just checked against 2.2 and the artifacts are gone. There was another curious side-effect: the LogNorm would return 'bad' for value of 0, and now it seems to return a valid value, since my original code now prints an entirely blue squared plot with no white stripes. I reproduced the stripes by writing np.nan instead of 0, and verified artifacts are gone.
If LogNorm for 0 should have returned np.nan (and thus created the white stripes), a bug should be filed for that. But as for this particular bug, it has been resolved. Thanks!
tacaswell commentedon Apr 12, 2018
@arthur00 LogNorm returning valid values for 0 seems like a bug, can you open a new issue for that?
The reason
imshowneeds an interpolation kwarg is that the number and pitch of the pixels in the input image and the number and pitch of the pixels in the output image do not match so there will be interpolation (either up or down sampling). There is not a generic 'right' way to do this, so we expose a way for the user to change it.arthur00 commentedon Apr 12, 2018
LogNorm seems to be correctly returning 'masked' for 0, however the set_bad('white') does not seem to be working anymore. LogNorm(np.nan) returns 0.0 for some reason - I imagined it would return 'masked'.
Running the snippet of code I wrote at the beginning will create a blue squared block on matplotlib 2.2.0 (Windows) and will create graph with horizontal stripes on matplotlib 2.1.1 (Windows)
tacaswell commentedon Apr 12, 2018
what versions of numpy are you using in the two cases?
tacaswell commentedon Apr 12, 2018
arthur00 commentedon Apr 12, 2018
I have opened another bug to explore this issue: #11039
arthur00 commentedon Apr 12, 2018
Ok, I tried rerunning my original code and setting vmin/vmax, and now it worked but the artifacts are back.
I guess the artifacts dissapeared because np.nan was returning 0.0, not masked. The 'masked' values interpolation seem to be issue here.
Reopening this issue as well, but feel free to close if this is not a relevant bug.
timhoffm commentedon Jul 16, 2020
Cannot reproduce as of v3.3.0. Please reopen if the problem still persists.