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

Smit, Christine E. (GSFC-610.2)[TELOPHASE CORP] christine.e.smit at nasa.gov
Thu Nov 19 16:47:10 EST 2015


That looks interesting. It's definitely what we are currently trying to
do. Thank you for mentioning it.

On 11/19/15, 3:26 PM, "Warren Weckesser" <warren.weckesser at gmail.com>
wrote:

>On 11/19/15, Smit, Christine E. (GSFC-610.2)[TELOPHASE CORP]
><christine.e.smit at nasa.gov> wrote:
>> Thanks! I have. https://github.com/matplotlib/matplotlib/issues/5520
>>
>
>
>FYI:  If you want to write a numpy array directly to a PNG file, you
>can use numpngw:
>
>* github: https://github.com/WarrenWeckesser/numpngw
>* pypi: https://pypi.python.org/pypi/numpngw/
>
>
>Warren
>
>(Christine, sorry for the double email.  I forgot to "reply all".)
>
>> From: Jens Nielsen
>><jenshnielsen at gmail.com<mailto:jenshnielsen at gmail.com>>
>> Date: Thursday, November 19, 2015 at 9:34 AM
>> To: csmit <christine.e.smit at nasa.gov<mailto:christine.e.smit at nasa.gov>>,
>> Nathan Goldbaum <nathan12343 at gmail.com<mailto:nathan12343 at gmail.com>>
>> Cc: "matplotlib-users at python.org<mailto:matplotlib-users at python.org>"
>> <matplotlib-users at python.org<mailto:matplotlib-users at python.org>>
>> Subject: Re: [Matplotlib-users] odd behavior with 'nearest'
>>interpolation
>>
>> It seem like this is a genuine bug but I am not sure how to fix it. Can
>>you
>> submit a bug report at Github so we are sure that this is captured? At
>> github you can attach pictures
>>
>> Best Jens
>>
>>
>> On Thu, 19 Nov 2015 at 14:25 Smit, Christine E. (GSFC-610.2)[TELOPHASE
>>CORP]
>> <christine.e.smit at nasa.gov<mailto:christine.e.smit at nasa.gov>> wrote:
>> Yes. It works with 'none.' The problem is that sometimes we need to
>>create
>> images with low inflation factors. So, our data is nxm data points and
>>we
>> want a 2nx2m image or a 3nx3m image. We're currently getting around
>>this bug
>> by using 'none' to create an nxm image and then using imagemagick's
>>convert
>> to resize.
>>
>> From: Jens Nielsen
>><jenshnielsen at gmail.com<mailto:jenshnielsen at gmail.com>>
>> Date: Wednesday, November 18, 2015 at 6:28 AM
>> To: Nathan Goldbaum
>><nathan12343 at gmail.com<mailto:nathan12343 at gmail.com>>,
>> csmit <christine.e.smit at nasa.gov<mailto:christine.e.smit at nasa.gov>>
>> Cc: "matplotlib-users at python.org<mailto:matplotlib-users at python.org>"
>> <matplotlib-users at python.org<mailto:matplotlib-users at python.org>>
>> Subject: Re: [Matplotlib-users] odd behavior with 'nearest'
>>interpolation
>>
>> 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<mailto: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<mailto: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<mailto:Matplotlib-users at python.org>
>> https://mail.python.org/mailman/listinfo/matplotlib-users
>>
>>
>> _______________________________________________
>> Matplotlib-users mailing list
>> Matplotlib-users at python.org<mailto:Matplotlib-users at python.org>
>> https://mail.python.org/mailman/listinfo/matplotlib-users
>>



More information about the Matplotlib-users mailing list