1

I am trying to plot some results using a contourf plot. The X, Y, and Z data are all 2d numpy arrays. I thought it was as simple as passing those arrays to the contourf function. However, I get a an error:

TypeError: 'list' object is not callable

when I execute my code and i am not sure why. As shown I can get an imshow plot of the Z data but the subsequent contourf plot fails

import matplotlib.pyplot as plt
import numpy as np

def lowpass_resp(frq, tau, expon):
    return 1/np.sqrt(1+(2.0*np.pi*frq*tau)**expon)

def getcoef(rh, typ, bas, ex):
    if typ == 'L':
        coef = bas + ex*rh
    else:
        coef = bas*np.exp(rh*ex)
    return coef   

Q = [('E', 2.1989, 0.0138,  'L', 1.6139, 0.0196),
     ('E', 4.8791, 0.003,   'L', 2.0646, 0.0058),
     ('E', 4.1166, 0.0069,  'L', 2.4588, 0.0011),
     ('E', 4.103, 0.0123,   'L', -21.513, 0.4472),
     ('L', -1.3328, 0.1462, 'L', -22.194, 0.459),
     ('L', 3.0807, 0.0407,  'L', 2.2316, 0.0065),
     ('E', 0.0184, 0.0627,  'L', 3.4733, -0.0205),
     ('E', 0.0527, 0.0454,  'L', 3.2077, -0.0133),
     ('E', 0.1319, 0.0555,  'L', 0.7569, 0.027)]


frq =  np.arange(-50,10)/10.0
frq = 10**frq
rhx = np.arange(10,110, 10)

frq,rhx = np.meshgrid(frq,rhx)

adt = np.dtype=[('tau_type', 'S1'), ('tau_base', 'f'), ('tau_gain', 'f'),('exp_type', 'S1'), ('exp_base', 'f'), ('exp_gain', 'f')]

qcoef = np.array([x for x in Q],dtype=adt)

ix = 0
bcoef = getcoef(rhx, qcoef['tau_type'][ix], qcoef['tau_base'][ix], qcoef['tau_gain'][ix] )
ecoef = getcoef(rhx, qcoef['exp_type'][ix], qcoef['exp_base'][ix], qcoef['exp_gain'][ix] )
tf = lowpass_resp(frq, bcoef, ecoef)

plt.figure()
plt.imshow(tf)
plt.show()

plt.figure()
plt.contourf(frq,rhx,tf)
plt.show()

The full trace is as below:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\Python27\lib\site-packages\spyderlib\widgets\externalshell\sitecustomize.py", line 685, in runfile
    execfile(filename, namespace)
  File "C:\Python27\lib\site-packages\spyderlib\widgets\externalshell\sitecustomize.py", line 71, in execfile
    exec(compile(scripttext, filename, 'exec'), glob, loc)
  File "C:/Users/rclement/Dropbox/Code/python/junktest.py", line 69, in <module>
    plt.contourf(frq,rhx,tfc)
  File "C:\Python27\lib\site-packages\matplotlib\pyplot.py", line 2718, in contourf
    ret = ax.contourf(*args, **kwargs)
  File "C:\Python27\lib\site-packages\matplotlib\axes\_axes.py", line 5340, in contourf
    return mcontour.QuadContourSet(self, *args, **kwargs)
  File "C:\Python27\lib\site-packages\matplotlib\contour.py", line 1429, in __init__
    ContourSet.__init__(self, ax, *args, **kwargs)
  File "C:\Python27\lib\site-packages\matplotlib\contour.py", line 875, in __init__
    self._process_args(*args, **kwargs)
  File "C:\Python27\lib\site-packages\matplotlib\contour.py", line 1442, in _process_args
    x, y, z = self._contour_args(args, kwargs)
  File "C:\Python27\lib\site-packages\matplotlib\contour.py", line 1512, in _contour_args
    self.zmax = ma.maximum(z)
  File "C:\Python27\lib\site-packages\numpy\ma\core.py", line 5954, in __call__
    return self.reduce(a)
  File "C:\Python27\lib\site-packages\numpy\ma\core.py", line 5971, in reduce
    target = target.filled(self.fill_value_func(target)).view(type(target))
  File "C:\Python27\lib\site-packages\numpy\ma\core.py", line 3496, in filled
    fill_value = _check_fill_value(fill_value, self.dtype)
  File "C:\Python27\lib\site-packages\numpy\ma\core.py", line 401, in _check_fill_value
    ndtype = np.dtype(ndtype)
TypeError: 'list' object is not callable
1

1 Answer 1

1

In this line:

adt = np.dtype=[('tau_type', 'S1'), ...

you have re-defined np.dtype to be a list rather than the intended function. Change this line to

adf = [('tau_type', 'S1'), ...

and the error will go away.

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks, worked. Guess I shouldn't work so late at night.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.