1
$\begingroup$

I have three ListPlots given by

`ListPlot[Table[{x, Sin[x]}, {x, 0, 2 \[Pi], 0.1}]]
ListPlot[Table[{x, Cos[x]}, {x, 0, 2 \[Pi], 0.1}]]
ListPlot[Table[{x, Exp[ x]}, {x, 0, 2 \[Pi], 0.1}]]`

I want to display all the three in a single 3D Plot with (say) x=axis showing x, y-axis showing curve number: 1 for Sin[x], 2 for Cos[x] and 3 for Exp[x], and z-axis displaying the functions themselves. Please help.

$\endgroup$

1 Answer 1

2
$\begingroup$
funcs = {Sin, Cos, Exp};
tbl = Table[Table[{x, i, funcs[[i]][x]}, {x, 0, 2 π, 0.1}], {i, 3}];

ListPointPlot3D[tbl, BoxRatios -> 1, PlotLegends -> funcs]

enter image description here

$\endgroup$
3
  • 1
    $\begingroup$ An alternative: tbl = MapIndexed[Map[Insert[First[#2], 2], #1] &, Table[{x, funcs[x]}, {funcs, {Sin, Cos, Exp}}, {x, 0, 2 π, 0.1}]] $\endgroup$ Commented Jan 29, 2020 at 6:24
  • $\begingroup$ Thanks, is it possible to start the Ticks from 0 in the plot. I mean instead of 1.0, 1.5, 2.0, 2.5,3.0 marking the axis, can be have 0.0, 0.5, 1.0,1.5,2.0? $\endgroup$
    – Rob
    Commented Jan 29, 2020 at 6:41
  • 1
    $\begingroup$ @Rob, you only need to shift. Spot the difference: tbl = MapIndexed[Map[Insert[First[#2] - 1, 2], #1] &, Table[{x, funcs[x]}, {funcs, {Sin, Cos, Exp}}, {x, 0, 2 π, 0.1}]]. If you wish to stick with kglr's approach: tbl = Table[Table[{x, i - 1, funcs[[i]][x]}, {x, 0, 2 π, 0.1}], {i, 3}]. $\endgroup$ Commented Jan 29, 2020 at 6:45

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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