How to draw a 3D graphic of a function?

classic Classic list List threaded Threaded
12 messages Options
Reply | Threaded
Open this post in threaded view
|

How to draw a 3D graphic of a function?

zhang chi
hi
   I want to draw a matrix of 100 X 100, its elements are the values of a function.

Is there a package to draw the graphic in scipy?

_______________________________________________
SciPy-user mailing list
[hidden email]
http://projects.scipy.org/mailman/listinfo/scipy-user
Reply | Threaded
Open this post in threaded view
|

Re: How to draw a 3D graphic of a function?

Gael Varoquaux
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,
https://svn.enthought.com/enthought/attachment/wiki/MayaVi/user_guide.pdf?format=raw
section "simple scripting with mlab", or "mlab reference" to see if you
find what you want.

If you need help installing Mayavi2, give me more details on your
platform.

Cheers,

Gaƫl
_______________________________________________
SciPy-user mailing list
[hidden email]
http://projects.scipy.org/mailman/listinfo/scipy-user
Reply | Threaded
Open this post in threaded view
|

Re: How to draw a 3D graphic of a function?

zunzun
In reply to this post by zhang chi
DISLIN (http://www.mps.mpg.de/dislin/) works well for surface plots, and comes with Python wrappers.  Free for non-commercial use.  I use it to draw surface plots on my curve and fitting web site http://zunzun.com - although I would rather use something else, DISLIN works and I can afford it (free for my use).

     James

On Fri, Apr 11, 2008 at 7:57 AM, zhang chi <[hidden email]> wrote:
hi
   I want to draw a matrix of 100 X 100, its elements are the values of a function.

Is there a package to draw the graphic in scipy?

_______________________________________________
SciPy-user mailing list
[hidden email]
http://projects.scipy.org/mailman/listinfo/scipy-user



_______________________________________________
SciPy-user mailing list
[hidden email]
http://projects.scipy.org/mailman/listinfo/scipy-user
Reply | Threaded
Open this post in threaded view
|

Re: How to draw a 3D graphic of a function?

Zachary Pincus-2
In reply to this post by zhang chi
Hello,

You could use PIL to write the matrix out as an image and open it in  
an external viewer (the TIFF format supports 32-bit floating point  
data, and at least ImageJ can open these files fine), or use  
matplotlib to plot the matrix as an image, or use Gnuplot / gnuplot.py  
to display a wireframe/surface view of the matrix.

This list is of course very incomplete, and none of the packages are  
in scipy. No matter though -- most are easy to get and install, and  
are quite useful. It's certainly worth the time to learn matplotlib  
and/or Gnuplot.

Zach


On Apr 11, 2008, at 8:57 AM, zhang chi wrote:
> hi
>    I want to draw a matrix of 100 X 100, its elements are the values  
> of a function.
>
> Is there a package to draw the graphic in scipy?
> _______________________________________________
> SciPy-user mailing list
> [hidden email]
> http://projects.scipy.org/mailman/listinfo/scipy-user

_______________________________________________
SciPy-user mailing list
[hidden email]
http://projects.scipy.org/mailman/listinfo/scipy-user
Reply | Threaded
Open this post in threaded view
|

Re: How to draw a 3D graphic of a function?

Benedikt Koenig
In reply to this post by zhang chi
I recommend the PyX package, which is great for 2D plotting but can also
handle simple 3D plots as the one you are describing.
www.pyx.sourceforge.net/examples/3dgraphs/index.html

Cheers,
bene


Am Freitag, den 11.04.2008, 20:57 +0800 schrieb zhang chi:
> hi
>    I want to draw a matrix of 100 X 100, its elements are the values
> of a function.
>
> Is there a package to draw the graphic in scipy?
> _______________________________________________
> SciPy-user mailing list
> [hidden email]
> http://projects.scipy.org/mailman/listinfo/scipy-user

_______________________________________________
SciPy-user mailing list
[hidden email]
http://projects.scipy.org/mailman/listinfo/scipy-user
Reply | Threaded
Open this post in threaded view
|

Re: How to draw a 3D graphic of a function?

lorenzo bolla
The link should be:
http://pyx.sourceforge.net/examples/3dgraphs/index.html
L.

On Fri, Apr 11, 2008 at 3:10 PM, BK <[hidden email]> wrote:
I recommend the PyX package, which is great for 2D plotting but can also
handle simple 3D plots as the one you are describing.
www.pyx.sourceforge.net/examples/3dgraphs/index.html

Cheers,
bene


Am Freitag, den 11.04.2008, 20:57 +0800 schrieb zhang chi:
> hi
>    I want to draw a matrix of 100 X 100, its elements are the values
> of a function.
>
> Is there a package to draw the graphic in scipy?
> _______________________________________________
> SciPy-user mailing list
> [hidden email]
> http://projects.scipy.org/mailman/listinfo/scipy-user

_______________________________________________
SciPy-user mailing list
[hidden email]
http://projects.scipy.org/mailman/listinfo/scipy-user



--
Lorenzo Bolla
[hidden email]
http://lorenzobolla.emurse.com/
_______________________________________________
SciPy-user mailing list
[hidden email]
http://projects.scipy.org/mailman/listinfo/scipy-user
Reply | Threaded
Open this post in threaded view
|

Re: How to draw a 3D graphic of a function?

James A. Bednar
In reply to this post by Gael Varoquaux
|  Date: Fri, 11 Apr 2008 15:02:03 +0200
|  From: Gael Varoquaux <[hidden email]>
|  
|  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 <[hidden email]>
|  
|  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
[hidden email]
http://projects.scipy.org/mailman/listinfo/scipy-user
Reply | Threaded
Open this post in threaded view
|

Re: How to draw a 3D graphic of a function?

Jerry-40
In reply to this post by zhang chi

On Apr 11, 2008, at 5:57 AM, zhang chi wrote:

> hi
>    I want to draw a matrix of 100 X 100, its elements are the  
> values of a function.
>
> Is there a package to draw the graphic in scipy?
>
The PLplot library http://plplot.sourceforge.net/ is extremely good  
and easy to use. It is also typically in the 98th or 99th percentile  
in downloads on sourceforge and the developers are very active with  
adding new bindings and features. (Don't be put off by the rather  
dated looking example plots.)

Jerry
_______________________________________________
SciPy-user mailing list
[hidden email]
http://projects.scipy.org/mailman/listinfo/scipy-user
Reply | Threaded
Open this post in threaded view
|

Re: How to draw a 3D graphic of a function?

Joshua Lippai
In reply to this post by James A. Bednar
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 <[hidden email]> wrote:

> |  Date: Fri, 11 Apr 2008 15:02:03 +0200
>  |  From: Gael Varoquaux <[hidden email]>
>
> |
>  |  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 <[hidden email]>
>  |
>  |  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
>  [hidden email]
>  http://projects.scipy.org/mailman/listinfo/scipy-user
>
_______________________________________________
SciPy-user mailing list
[hidden email]
http://projects.scipy.org/mailman/listinfo/scipy-user
Reply | Threaded
Open this post in threaded view
|

Re: How to draw a 3D graphic of a function?

James A. Bednar
|  From: Joshua Lippai
|  Date: Apr 14 10:27:52 2008 -0700
|  
|  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

That sounds like something to report to the matplotlib list.  I just
checked on the latest released version of matplotlib (0.91.2), and it
still works on that version.

Jim

|  On Sun, Apr 13, 2008 at 12:22 AM, James A. Bednar <[hidden email]> wrote:
|  > |  Date: Fri, 11 Apr 2008 15:02:03 +0200
|  >  |  From: Gael Varoquaux <[hidden email]>
|  >
|  > |
|  >  |  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 <[hidden email]>
|  >  |
|  >  |  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
|  >  [hidden email]
|  >  http://projects.scipy.org/mailman/listinfo/scipy-user
|  >

--
The University of Edinburgh is a charitable body, registered in
Scotland, with registration number SC005336.

_______________________________________________
SciPy-user mailing list
[hidden email]
http://projects.scipy.org/mailman/listinfo/scipy-user
Reply | Threaded
Open this post in threaded view
|

Re: How to draw a 3D graphic of a function?

Johann Cohen-Tanugi-2
I think that the whole 3D part of matplotlib is now broken. There are
discussions but not a lot of work yet as to how to get this
functionnality back. Might be via VTK....
best,
J.

James A. Bednar wrote:

> |  From: Joshua Lippai
> |  Date: Apr 14 10:27:52 2008 -0700
> |  
> |  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
>
> That sounds like something to report to the matplotlib list.  I just
> checked on the latest released version of matplotlib (0.91.2), and it
> still works on that version.
>
> Jim
>
> |  On Sun, Apr 13, 2008 at 12:22 AM, James A. Bednar <[hidden email]> wrote:
> |  > |  Date: Fri, 11 Apr 2008 15:02:03 +0200
> |  >  |  From: Gael Varoquaux <[hidden email]>
> |  >
> |  > |
> |  >  |  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 <[hidden email]>
> |  >  |
> |  >  |  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
> |  >  [hidden email]
> |  >  http://projects.scipy.org/mailman/listinfo/scipy-user
> |  >
>
>  
_______________________________________________
SciPy-user mailing list
[hidden email]
http://projects.scipy.org/mailman/listinfo/scipy-user
Reply | Threaded
Open this post in threaded view
|

Re: How to draw a 3D graphic of a function?

Ondrej Certik
On Tue, Apr 15, 2008 at 10:02 AM, Johann Cohen-Tanugi
<[hidden email]> wrote:
> I think that the whole 3D part of matplotlib is now broken. There are
>  discussions but not a lot of work yet as to how to get this
>  functionnality back. Might be via VTK....


There is a GSoC application for SymPy to integrating it's nice 3D
plotting capabilities to matplotlib. In the meantime, you can try it
out ourself, as described here:

http://code.google.com/p/sympy/wiki/PlottingModule

Ondrej
_______________________________________________
SciPy-user mailing list
[hidden email]
http://projects.scipy.org/mailman/listinfo/scipy-user