[SciPy-user] Simple plot problem

Gael Varoquaux gael.varoquaux at normalesup.org
Tue Feb 17 04:46:11 EST 2009


On Tue, Feb 17, 2009 at 01:23:20AM -0800, Guilherme P. de Freitas wrote:
> I need to plot three simpe things, in 3d, domain is x, y in [0,3] x
> [0,3:

> 1. the graph of the function f(x,y) = x**(0.3) * y**(0.7)
> 2. the parametric straight line (x, 2 - 2*x, 0)  for x in [0,1]
> 3. the parametric curve (x, 2 - 2*x, f(x, 2 - 2*x))

Here is some code that probably does what you want. Use the keyword
arguments of the plotting functions to change the different properties
(such as linewidth) of the objects created):

################################################################################
import numpy as np
from enthought.mayavi import mlab

x, y = np.mgrid[0:3:100j, 0:3:100j]
def f(x, y):
    return x**(0.3) * y**(0.7)
mlab.surf(x, y, f)

x = np.linspace(0, 1, 100)
mlab.plot3d(x, 2-2*x, np.zeros_like(x))
mlab.plot3d(x, 2 - 2*x, f(x, 2 - 2*x))
mlab.show()
################################################################################

I would interested in figuring out what posed problem in the
documentation, and how things could be improved. The trick is to create
arrays to evaluate the functions on: x and y. For a surface, you need to
create a 2D array, in other words a grid of x and y varying in the 2
directions. This is what the mgrid function does. Maybe a note about
mgrid in the documentation relative to plotting surface could help?

HTH,

Gaël



More information about the SciPy-User mailing list