[SciPyuser] Simple plot problem
James A. Bednar
jbednar@inf.ed.ac...
Tue Feb 17 04:51:19 CST 2009
 Date: Tue, 17 Feb 2009 01:23:20 0800
 From: "Guilherme P. de Freitas" <guilherme@gpfreitas.com>
 Subject: [SciPyuser] Simple plot problem
 To: SciPy Users List <scipyuser@scipy.org>
 MessageID: <a193bbb50902170123j7ae27879n71d3521f7be2e878@mail.gmail.com>
 ContentType: text/plain; charset=ISO88591

 Hi everybody,

 I'm running Python 2.5.2 with EPD with Py2.5 4.0.30002

 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))


  I thought of matplotlib, mlab (from mayavi2), SymPy and PyX.

  Apparently matplotlib cannot do 3d plots. Is this correct? My
 version of matplotlib is 0.98.

  I could not plot 2 (the parametric line) with mlab. I am not sure
 I understood the syntax of mlab.plot3d, and the examples
 everywhere are too complicated for me to understand how it works.
 I tried "mlab.plot3d([0, 1], [2, 0], [0, 0])" and it gave me a
 short line, very small, that was in the interior of the positive
 quadrant of the xy plane. Imagine the line I wanted and shrink it
 80% to its midpoint, that's what I got.

  I tried SymPy. I could plot everything easily. However, I could
 not change thickness and color of curves. Didn't find anything in
 the documentation. Any ideas? By the way, setting colors of
 objects in both SymPy and Mlab seems to complicated for simple
 use. How do I make the object red, for example?

  PyX apparently has no 3d plotting capabilities. Is this correct?


 I could not find an example of a simple plot of a function f : R^2
 > R in any python tool, with explanations of how to change
 thickness, color, style and labels of plots. Ideally, labels should
 be rendered with TeX. There were all sorts of complicated examples,
 but nothing simple like what I needed. And no example simple enough
 that I could really understand what was going on for all the
 commands I needed. I will gladly write a short tutorial about it if
 there is a way to do this and I find out the solution.

 Now I will try GnuPlot, and if that does not work, Maple. But I'd
 like to do it with Python. Any help is appreciated.
I use matplotlib0.91.4, and I can do nice 3D wireframe plots using
the code below. However, I don't think that works in newer versions,
so I have stopped upgrading. The matplotlib docs tell how to change
colors, etc.
Jim
_______________________________________________________________________________
import pylab
from numpy import outer,arange,cos,sin,ones,zeros,array
from matplotlib import axes3d
def matrixplot3d(mat,title=None):
fig = pylab.figure()
ax = axes3d.Axes3D(fig)
# Construct matrices for r and c values
rn,cn = mat.shape
c = outer(ones(rn),arange(cn*1.0))
r = outer(arange(rn*1.0),ones(cn))
ax.plot_wireframe(r,c,mat)
ax.set_xlabel('R')
ax.set_ylabel('C')
ax.set_zlabel('Value')
if title: windowtitle(title)
pylab.show()
matrixplot3d(array([[0.1,0.5,0.9],[0.2,0.1,0.0]]))

The University of Edinburgh is a charitable body, registered in
Scotland, with registration number SC005336.
More information about the SciPyuser
mailing list