matlab vs pylab png output

Hello,
I have a problem saving png files created from data with missing values.
The matlab and pylab outputs are very different... pylab resolution is poorer !?

the saving commands from matlab and python are similar:

matlab:
>>print -dpng -r80 test_matlab.png

python:
>>pylab.savefig('test_pylab.png',dpi=80)

look at the examples:
http://neptuno.fis.ua.pt/tmp/comp.html

Can I get the pylab output with the quality of test_matlab.png?
Thank you

mma

Without seeing any code or knowing anything about your matplotlib
version -- it is hard to help.

  http://matplotlib.sourceforge.net/faq/troubleshooting_faq.html#report-a-problem

JDH

···

On Tue, Jan 13, 2009 at 12:16 PM, Martinho MA <mma@...1770...> wrote:

Hello,
I have a problem saving png files created from data with missing values.
The matlab and pylab outputs are very different... pylab resolution is
poorer !?

the saving commands from matlab and python are similar:

matlab:
>>print -dpng -r80 test_matlab.png

python:
>>pylab.savefig('test_pylab.png',dpi=80)

look at the examples:
http://neptuno.fis.ua.pt/tmp/comp.html

Can I get the pylab output with the quality of test_matlab.png?

Perhaps the interpolation needs to be set to ‘nearest’?

···

On Tue, Jan 13, 2009 at 3:33 PM, John Hunter <jdh2358@…287…> wrote:

On Tue, Jan 13, 2009 at 12:16 PM, Martinho MA <mma@…1770…> wrote:

Hello,

I have a problem saving png files created from data with missing values.

The matlab and pylab outputs are very different… pylab resolution is

poorer !?

the saving commands from matlab and python are similar:

matlab:

print -dpng -r80 test_matlab.png

python:

pylab.savefig(‘test_pylab.png’,dpi=80)

look at the examples:

http://neptuno.fis.ua.pt/tmp/comp.html

Can I get the pylab output with the quality of test_matlab.png?

Without seeing any code or knowing anything about your matplotlib

version – it is hard to help.

http://matplotlib.sourceforge.net/faq/troubleshooting_faq.html#report-a-problem

JDH


This SF.net email is sponsored by:

SourcForge Community

SourceForge wants to tell your story.

http://p.sf.net/sfu/sf-spreadtheword


Matplotlib-users mailing list

Matplotlib-users@lists.sourceforge.net

https://lists.sourceforge.net/lists/listinfo/matplotlib-users

the script used and data file are at:
http://neptuno.fis.ua.pt/tmp/comp.html

the script is very simple, just:

from numpy import savez,load, ma
import pylab
data = load('data.npz')
lon = data['lon']
lat = data['lat']
sst = data['sst']
mask = data['mask']

sst=ma.masked_where(mask,sst)

pylab.pcolor(lon,lat,sst)
pylab.xlim([-12.5,-5.5])
pylab.ylim([34.5,45.5])
pylab.clim([12, 18])
pylab.savefig('filename.png')

The matplotlib version is:
In [2]: print matplotlib.__version__
0.98.3

The python version is:
In [5]: print sys.version
2.5.2 (r252:60911, Aug 1 2008, 00:37:21)
[GCC 4.3.1 20080507 (prerelease) [gcc-4_3-branch revision 135036]]

The machine is openSUSE 11.0 (X86-64):
>>uname -a
Linux c5 2.6.25.18-0.2-default #1 SMP 2008-......

I tried in windows xp, latest enthought python (python 2.5.2; EPD Py25 4.1.30101 (r252:60911, Dec 19 2008 ...)
and the output is similar (to linux python)
http://neptuno.fis.ua.pt/tmp/test_EPD.png

Thanks for the help
mma

John Hunter wrote:

···

On Tue, Jan 13, 2009 at 12:16 PM, Martinho MA <mma@...1770...> wrote:
  

Hello,
I have a problem saving png files created from data with missing values.
The matlab and pylab outputs are very different... pylab resolution is
poorer !?

the saving commands from matlab and python are similar:

matlab:
>>print -dpng -r80 test_matlab.png

python:
>>pylab.savefig('test_pylab.png',dpi=80)

look at the examples:
http://neptuno.fis.ua.pt/tmp/comp.html

Can I get the pylab output with the quality of test_matlab.png?
    
Without seeing any code or knowing anything about your matplotlib
version -- it is hard to help.

  http://matplotlib.sourceforge.net/faq/troubleshooting_faq.html#report-a-problem

JDH

Martinho MA wrote:

the script used and data file are at:
http://neptuno.fis.ua.pt/tmp/comp.html

The blocks (quadrilaterals) defined by your data grid are quite a bit smaller than the png-file pixels, so perhaps it is not surprising that matlab and mpl (via Agg) might be using different strategies to decide when to color a pixel in the image. How do you decide which one is a better representation of the data? What sort of downsampling algorithm do you want? (Not that you have a choice, short of writing your own code to generate the image from the data.)

You can get closer to the Matlab result by adding to your pcolor call the kwargs antialiased=False, edgecolor='none'. It still looks like Agg is using a rule along the lines of "if there is any part of a patch in this pixel, color it", and maybe Matlab is taking the opposite approach. The Cairo renderer appears to be doing the same thing as Agg, and not to be respecting the antialiased kwarg; but I have not checked this very carefully.

Instead of using pcolor, you can get a very similar result *much* faster by using:

pylab.pcolormesh(lon, lat, sst, antialiased=False)

Eric