I am trying to use Mathematica to analyse some raw data. I’d like to be able to dynamically display the range of data I’m interested in using Manipulate and ListLinePlot, but the plot rendering is extremely slow. How can I speed it up?
Here are some additional details. An external text file stores the raw data: the first column is a timestamp, the second, third and fourth columns are data readings, for example:
1309555993069, -2.369941, 6.129157, 6.823794
1309555993122, -2.260978, 6.170018, 7.014479
1309555993183, -2.070293, 6.129157, 6.823794
1309555993242, -1.988571, 6.238119, 7.123442
A single data file contains up to 2·106 lines. To display, for example, the second column, I use:
x = Import["path/to/datafile"];
ListLinePlot[x[[All, {1, 2}]]]
The execution time of this operation is unbearably long. To display a variable range of data I tried to use Manipulate:
Manipulate[ListLinePlot[Take[x, numrows][[All, {1, 2}]]], {numrows, 1, Length[x]}]
This instruction works, but it quickly crawls when I try to display more than few thousand lines. How can I speed it up?
Some additional details:
- MATLAB displays the same amount of data on the same computer almost instantaneously, thus the raw data size shouldn’t be an issue.
- I already tried to turn off graphics antialiasing, but it didn’t impact rendering speed at all.
- Using
DataRangeto avoidTakedoesn’t help. - Using
MaxPlotPointsdistorts too much the plot to be useful. - Not using
TakeinManipulatedoesn’t help. - The rendering seems to take huge amount of time. Running
Timing[ListLinePlot[Take[x,100000][[All, {1, 2}]]]]returns0.33: this means that the evaluation ofTakeby itself is almost instantaneous, is the plot rendering that slows everything down. - I am running Mathematica on Ubuntu Linux 11.10 using the fglrx drivers. Forcing Mathematica to use mesa drivers didn’t help.
Any hint?
I haven’t tested extensively this on my machine (I have a Mac, so I can’t rule out Linux-specific issues). but a couple of points occur to me. The following was pretty quick for me, but obviously slower than if the data set was smaller. You are plotting hundreds of thousands of data points.
Manipulate, you are allowing the amount of data shown withTaketo vary arbitrarily. Try only incrementingnumrowsevery 100 or so points, so there is less to render.ContinuousAction->Falseoption (see documentation) (I see @Szabolcs had the same idea as I was typing.MaxPlotPoints, but instead try thePerformanceGoal ->"Speed"option. (see documentation)