1
$\begingroup$

I have a array and I want to plot it in 3d space by ListPointPlot3D function.

list = {{1, 2, 3, 4, 5}, {2, 2, 2, 2, 2}};
ListPointPlot3D[list]

The result is as following enter image description here

But I want to the two points lines combined. enter image description here

If I plot in 2d space, it works well by ListPlot, but I don't know how to solve it in 3D space.

$\endgroup$
3
$\begingroup$

Add the x and y coordinates:

list = {{1, 2, 3, 4, 5}, {2, 2,    2, 2, 2}};
list2 = Thread[{1, Range @ Length @ #, #}] & /@ list;
ListPointPlot3D[list2, BaseStyle -> PointSize[Large]]

enter image description here

Alternatively, use MapIndexed to transform input data into lists of {x,y,z} triples:

list3 = MapIndexed[{1, #2[[2]], #} &, list, {2}];
list2 == list3
True
| improve this answer | |
$\endgroup$
0
$\begingroup$

One can use Iterator in the "GeneralUtilities`" package to advance through the colors:

Needs@"GeneralUtilities`";
cyclicListIterator[input_List] := 
 GeneralUtilities`NewIterator[cyclicListIterator,
  {i = 0, n = Length[input], list = input}, list[[Mod[++i, n, 1]]]]

colors = "DefaultPlotStyle" /. (Method /. 
       Charting`ResolvePlotTheme[Automatic, ListPointPlot3D]) // 
    cyclicListIterator;
ListPointPlot3D[{#}, PlotStyle -> Read[colors]] & /@ list // Show
 

enter image description here

Note: The Iterator[] for the colors needs to be reset after each use. One could use With[{colors = ...}, ListPointPlot3D...].

The same thing but with old-style MapThread:

colors = "DefaultPlotStyle" /. (Method /. 
     Charting`ResolvePlotTheme[Automatic, ListPointPlot3D]);
MapThread[
  ListPointPlot3D[{#}, PlotStyle -> #2] &,
  {list, PadRight[colors, Length@list, colors]}
  ] // Show
(* same figure as immediately above *)
| improve this answer | |
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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