Mathematica 9 is now available
Services & Resources / Wolfram Forums / MathGroup Archive
-----

MathGroup Archive 2001

[Date Index] [Thread Index] [Author Index]

Search the Archive

RE: ListPlot vs ListPlot3D

  • To: mathgroup at smc.vnet.net
  • Subject: [mg28935] RE: [mg28884] ListPlot vs ListPlot3D
  • From: "Wolf, Hartmut" <Hartmut.Wolf at t-systems.de>
  • Date: Sat, 19 May 2001 22:27:52 -0400 (EDT)
  • Sender: owner-wri-mathgroup at wolfram.com

Please see below:

> -----Original Message-----
> From:	Otto Linsuain [SMTP:linsuain+ at andrew.cmu.edu]
To: mathgroup at smc.vnet.net
> Sent:	Thursday, May 17, 2001 10:23 AM
> To:	mathgroup at smc.vnet.net
> Subject:	[mg28884] ListPlot vs ListPlot3D
> 
> 
> Dear Mathematica experts, I was wondering if there is a way of plotting
> a 3D graph using a rectangular array of z-values USING THE CORRESPONDING
> VALUES OF X AND Y.
> 
> Here is what I mean:
> 
> with a 2D plot, one can do:
> 
> ListPlot[ {y1,y2,y3,.........yn} ]  and this will give a graph of the
> points
> 
> {y1,1} ,{y2,2}, {y3,3},....{yn,n}, i.e. it will use the integers
> 1,2,3,...n as the x values.
> 
> One can, however, write
> 
> ListPlot[ { {x1,y1}, {x2,y2}, {x3,y3}, ... {xn,yn} }]
> 
> and get a graph with user-specified values for x and y. 
> 
> There doesn't seem to be an analogous thing for ListPlot3D. The values
> of x and y seem to be always {1,1}, {1,2},{2,1},{2,2},.......{n,n}
> 
> Any ideas? Thanks in advance. Otto Linsuain.
> 
[Hartmut Wolf]  

Otto,

let me make up an example: Let's assume we have a regular, but not evenly
spaced grid for xy-values:

xgrid=Table[Pi*Sin[x],{x,0,Pi/2,Pi/2/14}];
ygrid=Table[Pi/2*Sin[y],{y,-Pi/2,Pi/2, Pi/14}];
xygrid=Outer[List,xgrid,ygrid];

and z-values for say function Sin[x]*Cos[y] sampled at the grid.

tt=Apply[Sin[#1]Cos[#2]& ,xygrid,{2}]//N;

If we plot it with ListPlot3D we certainly get a distorted view

gg=ListPlot3D[Transpose[tt]]

- SurfaceGraphics -

What we have to do, is to shift the integer grid of ListPlot3D to the real,
true xy-Grid of the problem. We cannot do that with SurfaceGraphics, so we
convert that to a Graphics3D object.

gg1=Graphics3D[gg];

Show[gg1];

So far display is unchanged, but now we can put the points onto the real
grid: 

gg2=gg1/.Polygon[points_] :>
      Polygon[points/. {x_,y_,z_} :> xgrid[[Round[x]]],
              ygrid[[Round[y]]],z}]

- Graphics3D -

Show[gg2]

- Graphics3D -

Compare that with

Plot3D[Sin[x]Cos[y],{x,0,Pi},{y,-Pi/2,Pi/2}]

- SurfaceGraphics -

and we watch the same 3D-shape, however at different grids. So we have got
the "real" plot, sampled at our own regular, yet not-equally spaced grid by
only use of the original data. And the axes come out correctly too.

This method of transformation also may be used to get a more dense sampling
at regions of special interest (e.g. at rapid variation). The grid still has
to stay regular though.


-- Hartmut



  • Prev by Date: Re: Mathematica graphics/fonts and Tex
  • Next by Date: Re: Re: OOP in Mathematica
  • Previous by thread: Re: ListPlot vs ListPlot3D
  • Next by thread: 2001 Mathematica Developer Conference