On Thursday, May 24, 2012, Umut Yildiz wrote:

> Dear All,
>
> I used to use griddata in order to make my contourmaps. However, after I
> updated
> my Python from 2.6 to 2.7 griddata is not working anymore.
>
> I tried some workarounds but no success.
>
> The countourmap that I produced before is here.
> http://dl.dropbox.com/u/17983476/matplotlib/contour_dT_workingbefore.png
>
> After the Python 2.7 update, it turns to the following.
> http://dl.dropbox.com/u/17983476/matplotlib/contour_dT_broken.png
>
> Here is the datafile.
> http://dl.dropbox.com/u/17983476/matplotlib/contour_dT.dat
>
> And the associated python script (which is also below).
> http://dl.dropbox.com/u/17983476/matplotlib/contour_dT.py
>
> The code that I was using before is here. I had to comment out #import
> griddata
> line because this is the only way that it continues. Is this a bug in
> griddata,
> or if there are new workarounds, I would be glad to know a new method to
> produce
> my contourplots again.
>
> Thanks a lot
>
> ----------------------------
> #! /usr/bin python
>
> import os
> import sys
> import math
> from math import *
> from numpy import *
> #import griddata
> from pylab import *
> from matplotlib.ticker import FormatStrFormatter
> params = {'axes.labelsize': 20,
>                'text.fontsize': 15,
>                'legend.fontsize': 14,
>                'xtick.labelsize': 20,
>                'ytick.labelsize': 20,
>                'text.usetex': True }
> rcParams.update(params)
>
> par1 = []
> par2 = []
> chis = []
>
> rfile = file('contour_dT.dat','r')
> line = rfile.readline()
> data = line.split()
>
> while len(data) >1:
>        par1.append(float(data[0]))
>        par2.append(float(data[1]))
>        chis.append(float(data[2]))
>        line = rfile.readline()
>        data = line.split()
>
> par1 = array(par1)
> par2 = array(par2)
> chis = array(chis)
>
> xi = linspace(3.2,7.8,50)
> yi = linspace(15,300,50)
> zi = griddata(par2,par1,chis,xi,yi)
> levels =
> [0.4,0.5,0.6,0.7,0.8,0.9,1.0,1.2,1.5,2,3,4,6,10,12,15,20,25,30,40,50]
> CS = contourf(xi,yi,zi,levels,cmap=cm.jet)
> CS2 = contour(CS, levels=CS.levels[::2],
>                        colors = 'r',
>                        hold='on')
>
> cbar = colorbar(CS)
> cbar.add_lines(CS2)
>
> savefig("contour_dT.png")
> show()
>
>
First, if you were importing griddata before like that, that it is quite
likely that it was some other module that was installed in your
python-2.6/site-packages directory that overrode numpy's griddata. When you
upgraded, that griddata module could not be found in
python-2.7/site-packages. Commenting it out allowed python to find pylab's
griddata.

Second, you really need to clean up your imports. There is no need for the
two math imports, or the numpy import (because the pylab import handles
that).

Oddly, though, your griddata import comes before the pylab import. I would
expect that the pylab griddata would have overridden the first griddata
import. And so there shouldn't have been a difference.

Did you happen to upgrade matplotlib and/or numpy as well?

Ben Root
------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and 
threat landscape has changed and how IT managers can respond. Discussions 
will include endpoint security, mobile security and the latest in malware 
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users

Reply via email to