0
$\begingroup$

Here is a small data sample:

data = {{{10.5438, -0.224956, -1.09651}, {10.5377, 0.252612, 
0.971822}, {10.636, 0.0170358, -0.961191}, {10.065, 
0.0826926, -4.27159}, {9.06832, 0.513978, -6.88496}, {6.82993, 
0.249625, -13.4183}, {3.41034, 0.966202, -27.087}, {-3.8472, 
0.832591, -24.9483}, {-7.14816, 0.244906, -13.1244}}, {{10.5593,
-0.235618, -1.05413}, {10.5793, 0.223809, 1.27232}, {10.8476,
-0.0543677, 0.775037}, {11.0111, -0.584972, 2.09497}, {12.1732,
-1.50977, 9.90628}, {14.1839, -6.03413, 5.51221}, {12.0181, 
-15.4799, -32.4912}, {0.322652, -23.8757, -82.276}, {-18.1188, 
-21.1508, -91.2322}}}

It contains the (x,y,z) coordinates of two 3D lines. My question is how to plot these two 3D lines together in the same plot (the points of each line should be connected)? Please take into account that the real data file contains more than 100 sub-lists, so the solution should not be applicable for only two sub-lists.

many thanks in advance!

$\endgroup$
4
$\begingroup$
Graphics3D[Line /@ data]

should work with your data.

or...

Graphics3D[{{Red, Line[data[[1]]]}, {Green, Line[data[[2]]]}}]

or best...

Graphics3D[MapThread[{#1, Line[#2]} &, {{Red, Green}, data}]]

For data having some arbitrary number of lines...

data = {{{0, 0, 0}, {1, 1, 2}, {3, 1, 2}}, 
   {{-5, 4, 3}, {-2, 6, 5}, {-8, 4, 2}, {6, 6, 1}}, 
   {{4, 4, 3}, {9, 2, 5}, {8, -3, 6}, {4, 7, 6}, {9, 1, 1}, {5, 5, 2}}};        
Graphics3D[
     MapThread[{#1, Line[#2]} &, 
     {Table[Hue[RandomReal[]], {Length[data]}], data}]]
$\endgroup$
  • $\begingroup$ It was much easier than I thought. Thanks! $\endgroup$ – Vaggelis_Z Sep 28 '15 at 17:20

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.