1

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

2
  • 1
    To help narrow it down, the code works for me on Ubuntu 11.10 with matplotlib 1.0.1.
    – Hooked
    Feb 8, 2012 at 18:35
  • 2
    I would consider changing the title of your question. It had nothing to do with contour plots. It's a good question to ask, and someone else might have the same issue. Something like "Error running matplotlib: AttributeError: 'module' object has no attribute 'nextafter'"
    – Yann
    Feb 8, 2012 at 18:41

1 Answer 1

2

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 nextafter function is only available following numpy 1.4 (Thanks to DSM).

2
  • 2
    I've just checked, and the nextafter function is missing from numpy 1.3.0 and present in numpy 1.4.1 and beyond, so I bet the numpy version is 1.3.0.
    – DSM
    Feb 8, 2012 at 18:45
  • hey, there's rep enough for everyone. :-)
    – DSM
    Feb 8, 2012 at 19:01

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.