[Matplotlib-users] odd behavior with 'nearest' interpolation

Jens Nielsen jenshnielsen at gmail.com
Wed Nov 18 06:28:21 EST 2015


I can confirm this. The issue is notable with a dpi lower than 10 or so and
seems to get worse as it is lowered towards 1.
Can you try plotting the image with interpolation='none' If I do that I get
the correct behaviour. 'none' is probably the correct setting if you wish
to match
image matrix 1to1 to png coords anyway.

@nathan The image in the notebook is plotted with a different dpi and works
correctly.

best Jens

On Tue, 17 Nov 2015 at 22:38 Nathan Goldbaum <nathan12343 at gmail.com> wrote:

> This seems to be working ok for me:
> https://gist.github.com/faa6b4008a8e3db68f46
>
> On Tue, Nov 17, 2015 at 4:22 PM, Smit, Christine E. (GSFC-610.2)[TELOPHASE
> CORP] <christine.e.smit at nasa.gov> wrote:
>
>> Hi! I am using matplotlib v 1.4.3 with Python 2.7.10 :: Anaconda 2.4.0
>> (64-bit).
>>
>> What I am doing here is creating a 7x7 pixel image from a 7x7 matrix. I
>> expect to see one pixel per data point, but that's not what I'm seeing.
>> Instead of a diagonal make up of single pixels, I get an odd 2x2 pixel blob
>> in the middle of the correct one pixel diagonal.
>>
>>
>> ---------------------------------------------------------------------------
>> import numpy as np
>> import matplotlib.pylab as plt
>>
>>
>> if __name__ == "__main__":
>>     n = 7
>>     data = np.identity(n, float)
>>
>>     # Create an nxn size figure with no frame
>>     fig = plt.figure(figsize=(n, n), frameon=False)
>>
>>     # make the axes to the edge of the figure
>>     ax = plt.Axes(fig, [0.0, 0.0, 1.0, 1.0])
>>     # turn the axes off
>>     ax.set_axis_off()
>>     # add the axes to this figure
>>     fig.add_axes(ax)
>>     # show the data. Don't do any interpolation.
>>     ax.imshow(data, interpolation='nearest', origin='lower',aspect='auto')
>>     # Save the figure at 1 dot per inch, which should mean 1 data point
>> per
>>     # pixel
>>     fig.savefig("image.png", dpi=1)
>>
>>
>> ---------------------------------------------------------------------------
>>
>> Since I'm not sure that if I can attach the png image I get, here is a
>> ppm version of the image I get (between the ------). Save this image.ppm
>> minus the dashes and you should be able to open it in something like gimp.
>>
>>
>> ---------------------------------------------------------------------------
>> P3
>> # CREATOR: GIMP PNM Filter Version 1.1
>> 7 7
>> 255
>> 0
>> 0
>> 127
>> 0
>> 0
>> 127
>> 0
>> 0
>> 127
>> 0
>> 0
>> 127
>> 0
>> 0
>> 127
>> 0
>> 0
>> 127
>> 127
>> 0
>> 0
>> 0
>> 0
>> 127
>> 0
>> 0
>> 127
>> 0
>> 0
>> 127
>> 0
>> 0
>> 127
>> 0
>> 0
>> 127
>> 127
>> 0
>> 0
>> 0
>> 0
>> 127
>> 0
>> 0
>> 127
>> 0
>> 0
>> 127
>> 0
>> 0
>> 127
>> 127
>> 0
>> 0
>> 127
>> 0
>> 0
>> 0
>> 0
>> 127
>> 0
>> 0
>> 127
>> 0
>> 0
>> 127
>> 0
>> 0
>> 127
>> 0
>> 0
>> 127
>> 127
>> 0
>> 0
>> 127
>> 0
>> 0
>> 0
>> 0
>> 127
>> 0
>> 0
>> 127
>> 0
>> 0
>> 127
>> 0
>> 0
>> 127
>> 127
>> 0
>> 0
>> 0
>> 0
>> 127
>> 0
>> 0
>> 127
>> 0
>> 0
>> 127
>> 0
>> 0
>> 127
>> 0
>> 0
>> 127
>> 127
>> 0
>> 0
>> 0
>> 0
>> 127
>> 0
>> 0
>> 127
>> 0
>> 0
>> 127
>> 0
>> 0
>> 127
>> 0
>> 0
>> 127
>> 127
>> 0
>> 0
>> 0
>> 0
>> 127
>> 0
>> 0
>> 127
>> 0
>> 0
>> 127
>> 0
>> 0
>> 127
>> 0
>> 0
>> 127
>> 0
>> 0
>> 127
>>
>> ---------------------------------------------------------------------------
>>
>> Thanks.
>> Christine
>>
>> _______________________________________________
>> Matplotlib-users mailing list
>> Matplotlib-users at python.org
>> https://mail.python.org/mailman/listinfo/matplotlib-users
>>
>>
> _______________________________________________
> Matplotlib-users mailing list
> Matplotlib-users at python.org
> https://mail.python.org/mailman/listinfo/matplotlib-users
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/matplotlib-users/attachments/20151118/133c6249/attachment-0001.html>


More information about the Matplotlib-users mailing list