Are there any python libraries that will let me plot z = f(x,y) where z is represented as the color in a densely rasterized image (as opposed to the color of a bunch of scat
To give credit where it's due: this is only a slight variation on Andre Holzner's answer. Please upvote him if you must!
import pylab
def f(x, y):
return pylab.cos(x) + pylab.sin(y)
xx = pylab.linspace(-5, 5, 100)
yy = pylab.linspace(-5, 5, 100)
zz = pylab.zeros([len(xx), len(yy)])
for i in xrange(len(xx)):
for j in xrange(len(yy)):
zz[j, i] = f(xx[i], yy[j])
pylab.pcolor(xx, yy, zz)
pylab.show()
The syntax is perhaps easier to read with the strict minimum of array dimensions and indices. It relies on the following point (quoted from the doc).
If either or both of X and Y are 1-D arrays or column vectors, they will be expanded as needed into the appropriate 2-D arrays, making a rectangular grid.