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

Nathan Goldbaum nathan12343 at gmail.com
Tue Nov 17 17:38:10 EST 2015


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
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/matplotlib-users/attachments/20151117/dcc347ec/attachment.html>


More information about the Matplotlib-users mailing list