On Mon, 10 Apr 2006 10:54:25 -0500 > John Hunter <jdhunter@...4...> wrote:
> Hi all, Given a set of points (x_i,y_i,z_i) is it possible
> to plot y_i versus x_i with a varying color corresponding to
> the magnitude of z_i ? Nils
We can't do this in 3D, but you can do it in 2D with a pseudo color
plot. If your z-y data do not lie on a grid, you need to interpolate
them onto a grid first
http://www.scipy.org/Wiki/Cookbook/Matplotlib/Gridding_irregularly_spaced_data
JDH
-------------------------------------------------------
This SF.Net email is sponsored by xPML, a groundbreaking scripting language
that extends applications into web and mobile media. Attend the live webcast
and join the prime developer group breaking into this new coding territory!
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=110944&bid=241720&dat=121642
_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
matplotlib-users List Signup and Options
Hi John,
Thank you for your hint. I tried the script
/usr/bin/python irregular.py --verbose-helpful
matplotlib data path /usr/lib/python2.4/site-packages/matplotlib/mpl-data
$HOME=/home/nwagner
loaded rc file /home/nwagner/matplotlibrc
matplotlib version 0.88
verbose.level helpful
interactive is False
platform is linux2
numerix numarray 1.5.1
font search path ['/usr/lib/python2.4/site-packages/matplotlib/mpl-data']
CONFIGDIR=/home/nwagner/.matplotlib
loaded ttfcache file /home/nwagner/.matplotlib/ttffont.cache
backend GTKAgg version 2.5.3
import linsolve.umfpack -> failed: No module named _umfpack
/usr/lib/python2.4/site-packages/numpy/core/ma.py:601: 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 "\
/usr/lib/python2.4/site-packages/numarray/numarraycore.py:383: UserWarning: __array__ returned non-NumArray instance
_warnings.warn("__array__ returned non-NumArray instance")
Traceback (most recent call last):
File "irregular.py", line 40, in ?
plot_data(xi,yi,zi)
File "irregular.py", line 14, in plot_data
pcolor(xi,yi,zim,shading='interp',cmap=cm.gray)
File "/usr/lib/python2.4/site-packages/matplotlib/pylab.py", line 1913, in pcolor
ret = gca().pcolor(*args, **kwargs)
File "/usr/lib/python2.4/site-packages/matplotlib/axes.py", line 2519, in pcolor
C = compress(ravel(mask==0),ravel(ma.filled(C[0:Nx-1,0:Ny-1])))
File "/usr/lib/python2.4/site-packages/numarray/ma/MA.py", line 832, in __getitem__
if self._data.rank == 0:
AttributeError: 'numpy.ndarray' object has no attribute 'rank'
How can I resolve this problem ?
Nils
------------------------------------------------------------------------
from numpy import *
from pylab import *
from scipy.sandbox.delaunay import *
import numpy.core.ma as ma
def plot_nodes(tri):
for nodes in tri.triangle_nodes:
fill(x[nodes],y[nodes],'b')
show()
def plot_data(xi,yi,zi):
zim = ma.masked_where(isnan(zi),zi)
figure(figsize=(8,8))
pcolor(xi,yi,zim,shading='interp',cmap=cm.gray)
contour(xi,yi,zim,cmap=cm.jet)
show()
if __name__ == '__main__':
N = 10000
aspect = 1.0
# Data
x = randn(N)/aspect
y = randn(N)
z = rand(N)
# Grid
xi, yi = mgrid[-5:5:100j,-5:5:100j]
# triangulate data
tri = Triangulation(x,y)
# interpolate data
interp = tri.nn_interpolator(z)
zi = interp(xi,yi)
# or, all in one line
# zi = Triangulation(x,y).nn_interpolator(z)(xi,yi)
plot_data(xi,yi,zi)