0
$\begingroup$

I have a dat file which contains a large amount of points. I can able to view the values from the dat file in mathematica but I don't make a plot column 3 vs 2 graph from the dat file. Can anyone help me to plot this graph. Here is the view of my dat file:

enter image description here

$\endgroup$
  • 2
    $\begingroup$ 1. Import it. 2. Wrangle the data, that is, get it in some format one of the *Plot* functions can handle. 3. Plot it. $\endgroup$ – user6014 Nov 13 '18 at 3:25
  • 1
    $\begingroup$ What have you tried so far? $\endgroup$ – user6014 Nov 13 '18 at 3:25
  • 1
    $\begingroup$ Well, I think it about more data re-structure than data visualization. $\endgroup$ – Αλέξανδρος Ζεγγ Nov 13 '18 at 5:10
  • 2
    $\begingroup$ Please provide a small data (text) sample in the post, which will help testing and providing solutions that much easier. Take a look at Import and related functions as well in the online help. $\endgroup$ – Yves Klett Nov 13 '18 at 7:52
1
$\begingroup$

Let's create a fake dataset and save it.

data0 = Table[{x, Sin[x], Cos[x]}, {x, 0.0, 2.0 Pi, Pi/5}];
Export["data.dat", data0]

This is how you export data to a file.

Now the data.dat has 3 column. To make it look like your file, I open it in a text editor and add something

# something
0.0000000000000000  0.000000000000000   1.00000000000000
0.6283185307179586  0.5877852522924731  0.8090169943749475
1.2566370614359172  0.9510565162951535  0.30901699437494745
1.8849555921538759  0.9510565162951536  -0.30901699437494734
2.5132741228718345  0.5877852522924732  -0.8090169943749473
3.141592653589793   1.2246467991473532e-16  -1.000000000
3.7699111843077517  -0.587785252292473  -0.8090169943749476
4.39822971502571    -0.9510565162951535 -0.30901699437494756
5.026548245743669   -0.9510565162951536 0.30901699437494723
5.654866776461628   -0.5877852522924734 0.8090169943749473
6.283185307179586   -2.4492935982947064e-16 1.0000000000000000
  1. Import data
data = Import["data.dat"];
  1. Exclude the first line
data1 = data[[2 ;; -1]];

It means take the data from 2nd line to last line.

  1. Plot
ListLinePlot[data1[[All, {1, 2}]]]

plot 2nd column against 1st column ({1,2})

ListLinePlot[data1[[All, {3, 2}]]]

plot 2nd column against 3rd column ({3,2}).

$\endgroup$
  • 1
    $\begingroup$ data[[2;;]] also works instead of data[[2 ;; -1]]. $\endgroup$ – Gladaed Nov 13 '18 at 13:04
  • 1
    $\begingroup$ Or Rest[data] also would work if preferred. $\endgroup$ – Thies Heidecke Nov 13 '18 at 13:14
  • $\begingroup$ It's working!! Thanks a lot for your kind help. $\endgroup$ – M Cosmo Nov 15 '18 at 12:48

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.