[SciPy-user] How to draw a 3D graphic of a function?
Joshua Lippai
discerptor at gmail.com
Mon Apr 14 13:27:52 EDT 2008
I can't import matplotlib.axes3d using a 0.98pre SVN build. Here's my output:
In [3]: from matplotlib import axes3d
---------------------------------------------------------------------------
ImportError Traceback (most recent call last)
/Users/Josh/<ipython console> in <module>()
/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/site-packages/matplotlib/axes3d.py
in <module>()
14 from axes import Axes
15 import cbook
---> 16 from transforms import unit_bbox
17
18 import numpy as npy
ImportError: cannot import name unit_bbox
On Sun, Apr 13, 2008 at 12:22 AM, James A. Bednar <jbednar at inf.ed.ac.uk> wrote:
> | Date: Fri, 11 Apr 2008 15:02:03 +0200
> | From: Gael Varoquaux <gael.varoquaux at normalesup.org>
>
> |
> | On Fri, Apr 11, 2008 at 08:57:50PM +0800, zhang chi wrote:
> | > I want to draw a matrix of 100 X 100, its elements are the values of a function.
> |
> | I suppose you want to map the value of your matrix to the altitude of a
> | surface?
> |
> | You can do this with Mayavi2. Have a look at the user guide,
>
> As shown below, you can also do this with matplotlib, which more
> people will probably have installed. There was a suggestion that I add
> this to the matplotlib cookbook, but I still haven't gotten a chance
> to do so...
>
> Jim
>
> | Date: Tue, 02 Oct 2007 04:56:56 -0400
> | From: Joe Harrington <jh at physics.ucf.edu>
> |
> | Or, you could just do it with matplotlib...
> |
> | http://physicsmajor.wordpress.com/2007/04/22/3d-surface-with-matplotlib/
> |
> | This was the first hit on a google search for "matplotlib surface". I
> | tested it and it works in 0.90.1.
>
> Interesting! I couldn't find any documentation at all, but after some
> hacking on that script I was able to make matplotlib 0.90.1 plot a
> wireframe surface for a 2D numpy array, so I thought it could be
> useful to include the code (below).
>
> Note that the original example uses plot_surface instead of
> plot_wireframe, but I've found plot_surface to be quite buggy, with
> plots disappearing entirely much of the time, while plot_wireframe has
> been reliable so far. There is also contour3D, though that doesn't
> look very useful yet. Hopefully these 3D plots will all be polished
> up a bit and made public in a new matplotlib release soon!
>
> 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.
>
>
>
> _______________________________________________
> SciPy-user mailing list
> SciPy-user at scipy.org
> http://projects.scipy.org/mailman/listinfo/scipy-user
>
More information about the SciPy-User
mailing list