Trying to reproduce the problem from this question, I’ve found I can’t plot even a simplest contour plot.
Here is a simplified version of a (hopefelly) relevant example from the gallery
#!/usr/bin/env python
import matplotlib
import numpy as np
import matplotlib.cm as cm
import matplotlib.mlab as mlab
import matplotlib.pyplot as plt
delta = 0.025
x = np.arange(-3.0, 3.0, delta)
y = np.arange(-2.0, 2.0, delta)
X, Y = np.meshgrid(x, y)
#Z1 = mlab.bivariate_normal(X, Y, 1.0, 1.0, 0.0, 0.0)
#Z2 = mlab.bivariate_normal(X, Y, 1.5, 0.5, 1, 1)
# difference of Gaussians
Z = 10.0 * np.exp(X-Y) #(Z2 - Z1)
plt.figure()
CS = plt.contour(X,Y,Z)
plt.show()
which gives me this:
Traceback (most recent call last):
File "./contour.py", line 19, in <module>
CS = plt.contour(X,Y,Z)
File "/usr/local/lib/python2.6/dist-packages/matplotlib/pyplot.py", line 2188, in contour
ret = ax.contour(*args, **kwargs)
File "/usr/local/lib/python2.6/dist-packages/matplotlib/axes.py", line 7316, in contour
return mcontour.QuadContourSet(self, *args, **kwargs)
File "/usr/local/lib/python2.6/dist-packages/matplotlib/contour.py", line 1106, in __init__
ContourSet.__init__(self, ax, *args, **kwargs)
File "/usr/local/lib/python2.6/dist-packages/matplotlib/contour.py", line 720, in __init__
self._process_colors()
File "/usr/local/lib/python2.6/dist-packages/matplotlib/contour.py", line 954, in _process_colors
self.set_clim(self.vmin, self.vmax)
File "/usr/local/lib/python2.6/dist-packages/matplotlib/cm.py", line 248, in set_clim
self.changed()
File "/usr/local/lib/python2.6/dist-packages/matplotlib/contour.py", line 841, in changed
self.to_rgba(self.cvalues, alpha=self.alpha)]
File "/usr/local/lib/python2.6/dist-packages/matplotlib/cm.py", line 214, in to_rgba
x = self.cmap(x, alpha=alpha, bytes=bytes)
File "/usr/local/lib/python2.6/dist-packages/matplotlib/colors.py", line 520, in __call__
cbook._putmask(xa, xa==1.0, np.nextafter(xa.dtype.type(1),
AttributeError: 'module' object has no attribute 'nextafter'
The errors do not depend on whether I stick to the original ‘difference of Gaussians’ or try plotting just an exponential, as in the code snipped above.
Am I missing something trivial?
In case it’s relevant, I’m using matplotlib 1.1.0 on Ubuntu 10.04
No you are not doing anything wrong. You need to upgrade Numpy. I had the same issue, and following an update to Numpy 1.6.1, things worked smoothly.
With Lucid Lynx (Ubuntu 10.04), you have access to numpy 1.3.0. The missing
nextafterfunction is only available following numpy 1.4 (Thanks to DSM).