3d plotting question

Hi Belinda,

I've been playing with 3D plots and scatter plots in the past few days
and I've been able to get them working. You should be able to pass in
a c=<color> parameter as you would for a normal 2d scatter plot. I've
been doing this and it's working for me.


I'm on Mac OS X 4.8.9, running Python 2.4.4, using Matplotlib 0.87.7 w/TkAgg (I might be using Wx, but would have to get a problem w/my machine's and all the students' lab machines wx libraries updated).

When I try using the c='r' parameter, I run into problems. I also tried c='red'. One big problem for me is that which kwargs can be used where and what values they can take on is not well documented.

For instance, in plot3d (as opposed to plot3D) you can pass the typical Matplotlib 'r.-' string and it just works. But in plot_wireframe, for example, it appears you must use different kwargs (for instance, linestyle='solid' and color='<some RGB value>'). I am not sure about these notions, b/c I've had to deduce them from the code and various google-based snippets.

That's why I'm asking for more guidance about the various kwarg usages.

Is there any good place to find more cohesive info online? The most useful place I could find seemed to be in matplotlib's collections.py, an __init__ function's documentation (that's where I deduced, for instance, the linestyle and RGB color info). If there isn't such a place, someone should probably modify the matplotlib 3d cookbook. I'd be willing to do that but I'd first need to have a better understanding about the various functions' kwargs :-).

I'll append a case I used to generate an error, as well as the error reporting below. I'm also not quite sure how to use the errors that are reported to help me track down where the problems might be, so if anyone has some advice on that, it might help me better help myself in the future.

As always, thx,


Example Code:


import copy
import pylab as P
import matplotlib.axes3d as P3
def test() :
     [X,Y] = P.meshgrid(P.linspace(-3,3,7),P.linspace(-3,3,7))
     Z = copy.deepcopy(X)
     Z1 = copy.deepcopy(X)
     for i in xrange(len(X)) :
         for j in xrange(len(X[0])) :
             Z[i][j] = X[i][j]*Y[i][j]
             Z1[i][j] = X[i][j]*Y[i][j] - 5
     fig = P.figure()
     ax = P3.Axes3D(fig)

In [213]: T.test()
exceptions.AttributeError Traceback (most recent call last)

/Users/bthom/belinda/mills/aicourse/material/week12/lec/examples/<ipython console>

/Users/bthom/belinda/mills/aicourse/material/week12/lec/examples/threeDa.py in test()
      11 Z1[i][j] = X[i][j]*Y[i][j] - 5
      12 P.close('all')
      13 fig = P.figure()
      14 ax = P3.Axes3D(fig)
---> 15 ax.Plot3D(ravel(X),ravel(Y),ravel(Z),c='red')

/Library/Frameworks/Python.framework/Versions/2.4/lib/python2.4/site-packages/matplotlib/axes3d.py in __getattr__(self, k)
     661 def __getattr__(self, k):
--> 662 return getattr(self.wrapped,k)
     664 def __setattr__(self, k,v):

AttributeError: Axes3DI instance has no attribute 'Plot3D'
> /Library/Frameworks/Python.framework/Versions/2.4/lib/python2.4/site-packages/matplotlib/axes3d.py(662)__getattr__()
     661 def __getattr__(self, k):
--> 662 return getattr(self.wrapped,k)