I have a problem that arose when I tried to run the gridding irregularly
spaced data demo on the wiki
http://www.scipy.org/Cookbook/Matplotlib/Gridding_irregularly_spaced_data

When I run the attached script, which sets one value of an array to nan, masks the array where there are nan, and tries to plot it using contour(), I get the following errors:

/usr/lib/python2.4/site-packages/numpy/core/ma.py:604: UserWarning: Cannot automatically convert masked array to numeric because data
    is masked in one or more locations.
  warnings.warn("Cannot automatically convert masked array to "\
Traceback (most recent call last):
  File "masked_nan.py", line 18, in ?
    contour(x, y, z)
File "/usr/lib/python2.4/site-packages/matplotlib/pylab.py", line 1754, in contour
    ret =  gca().contour(*args, **kwargs)
File "/usr/lib/python2.4/site-packages/matplotlib/axes.py", line 4092, in contour
    return ContourSet(self, *args, **kwargs)
File "/usr/lib/python2.4/site-packages/matplotlib/contour.py", line 429, in __init__
    x, y, z = self._contour_args(*args)        # also sets self.levels,
File "/usr/lib/python2.4/site-packages/matplotlib/contour.py", line 614, in _contour_args
    lev = self._autolev(z, 7)
File "/usr/lib/python2.4/site-packages/matplotlib/contour.py", line 517, in _autolev
    zmargin = (zmax - zmin) * 0.001 # so z < (zmax + zmargin)
TypeError: unsupported operand type(s) for -: 'str' and 'str'

I am using
>>> numpy.__version__
'1.0'
>>> matplotlib.__version__
'0.87.7'

Is there a way to use contour() and plot arrays whose elements may be nan?

Thanks,
Paul
import matplotlib
import numpy
import numpy.core.ma as ma
from pylab import *

a = linspace(0, 1, 3)
b = linspace(0, 1, 3)

x, y = meshgrid(a, b)

z = x + y

z[0][0] = numpy.nan

z = ma.masked_where(numpy.isnan(z), z)
contour(x, y, z)
show()
-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys - and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users

Reply via email to