8
$\begingroup$

A simple concept but I've not been able to solve it. I'm trying to create a stack of 2D plots in 3D space using Mathematica 9. This is not a parametric plot, but I'm creating it from an array of vectors (imported .csv file). The ListPlot3D function creates a filled mesh but what I want is this type of plot (created by HYRY in StackExchange: 'Matplotlib plot pulse propagation in 3d'):

example taken from StackExchange question: 'Matplotlib plot pulse propagation in 3d'

I have tried changing the function options for ListPlot3D and was going to create an array of plot images (.jpg) to stack in 3D, each one having an alpha value - but that would not be good. Any help is appreciated.

Thank you,

Marc

$\endgroup$
1
  • 1
    $\begingroup$ see: 77039 and topics linked in comments there. $\endgroup$
    – Kuba
    Jun 15, 2017 at 12:40

2 Answers 2

12
$\begingroup$

Here's one way, using Graphics3D and starting from a list of $x,y,z$ values for datapoints.

Mock data:

data = Flatten[Table[
  {x, y, PDF[MultinormalDistribution[{0, 0}, {{0.2, 0.1}, {0.1, 0.4}}],{x, y}]}, 
  {x, -2, 2, 0.01}, {y, -2, 2, 0.25}],1];

Group by y-value:

gb = GatherBy[data, #[[2]] &];

Some fancy styling (not necessary):

cLines = Transpose[{
  ColorData["BlueGreenYellow"] /@ Rescale[Range[Length[gb]]],
  Line /@ gb
}];

And plot (with some options to help the plot styling):

Graphics3D[
 {Thick, cLines},
 Axes -> True, Boxed -> False, BoxRatios -> {1, 1, 1}, 
 FaceGrids -> {{-1, 0, 0}, {0, 1, 0}, {0, 0, -1}}, 
 AxesLabel -> {"x", "y", "z"}, PlotRangePadding -> None]

enter image description here

$\endgroup$
1
  • $\begingroup$ Thank you - this is great! I did not think about reformatting the data first. $\endgroup$ Jun 15, 2017 at 13:19
11
$\begingroup$

You can also use ParametricPlot3D:

f[x_, y_] := Exp[-x^2 - y^2/(4 + x^2/4) + x y];
ParametricPlot3D[Table[{x, y, f[x, y]}, {y, -5, 5}], {x, -5, 5}, 
                 PlotRange -> All]

enter image description here ]

$\endgroup$
2
  • $\begingroup$ Thanks Yohbs - I'm trying to do this for an array of vectors (e.g. imported .csv) rather than for a list a parametric values. $\endgroup$ Jun 15, 2017 at 13:46
  • $\begingroup$ No problem. In retrospect I still think the easiest solution is simply using ListPlot3D with the Mesh option as detailed in the question @Kuba referred to. $\endgroup$
    – yohbs
    Jun 15, 2017 at 13:49

Not the answer you're looking for? Browse other questions tagged or ask your own question.