Mathematica Stack Exchange is a question and answer site for users of Mathematica. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

First, I'm quite new to Mathematica so sorry in advance if some questions seem to be trivial.

I have a CSV-file which looks like this:


perc is a percentage between 0…1; l1 and l2 are numbers, diff is the difference between l1 and l2. Those are the first lines; the full set is ~150.000 lines long; with perc from 0 to 1.

I want to plot those data and WolframAlpha (and even GoogleDocs) do a good job here and I get a result like this (actually, this is not entirely correct; perc should be plotted on X, l1, l2 and diff on Y; I hope you know what I mean.

This, however, only works if my CSV is less than ~4000 rows. If it's bigger, WA fails and "does not know how to interpret the data"; same for Google Docs. So, I want to redo this in Mathematica, but I don't know how / it doesn't work.

First, I import my CSV:

data = Import["data.csv", "Table", "HeaderLines" -> 1]

But then I fail with ListPlot because I don't know what options it needs to plot the data correspondingly to WA.

share|improve this question
up vote 13 down vote accepted

If your data is Imported say in data then you can use data[[All,{1,2}]] to use the first column as x and the second as y value. Plotting all three data sets would be

ListPlot[{data[[All, {1, 2}]], data[[All, {1, 3}]], data[[All, {1, 4}]]}] 

If you want to print against row index, like in yopur figure you can use

ListPlot[{data[[All, 2]], data[[All, 3]], data[[All, 4]]}, Frame -> True,
  PlotRange -> {0, 1000}, FrameLabel -> {"row index", None}]


To make sure that you import the data correctly you have to enforce "CSV" format. Using the "Table" format will give you the following data:

data // FullForm

As you see each line is interpreted as String. Use

data = Import["data.csv", "CSV", "HeaderLines" -> 1]

instead. Now

data // FullForm

correctly gives a list of numerical list elements and the above ListPlot works.

share|improve this answer
Thanks for this, that sounds quite logical :) However, if I try the first command, I get back a Part::partw: Part {1,2} of {0.0053,456,21,435} does not exist. >> followed by the same for 1,3 and 1,4 and a further output stopped. (0.0053,456,21,435 is the first data row) – Martin Apr 24 '12 at 16:06
Use FullForm[data] to see what is gpoing on. See my edited answer. – Markus Roellig Apr 24 '12 at 22:53
Thanks a lot! Now it works. Great job. – Martin Apr 25 '12 at 6:18

ListPlot requires a list of {x,y} pairs for each data set. What Markus is showing is how to get that in the right format.

For styling, read through the options for PlotStyle and PlotMarkers.

For legends, you have several options:

  1. Try to use the PlotLegend Package (bleh)
  2. Roll your own with the help of MMA.SE
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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