[Matplotlib-users] odd behavior with 'nearest' interpolation
Smit, Christine E. (GSFC-610.2)[TELOPHASE CORP]
christine.e.smit at nasa.gov
Tue Nov 17 17:22:28 EST 2015
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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/matplotlib-users/attachments/20151117/9da59709/attachment.html>
More information about the Matplotlib-users
mailing list