Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

I have several data files which contain columns of data. All my files follow the same format data001.out, data002.out, ... , data00n.out. I want to import and plot all of them simultaneously. In particular, I use only the first two columns of the data files for my plot. I wrote this simple Mathematica code:

SetDirectory["..."];

dataAll = {};

Do[
   data = ReadList["data00" <> ToString[NumberForm[i, 2, NumberPadding 
   -> {"0", ""}]] <> ".out", Number, 
   RecordLists -> True];
   pdata = Table[{data[[j, 1]], data[[j, 2]]}, {j, 1, Length[data]}];
   AppendTo[dataAll, Flatten[pdata]];
  , {i, 1, 50}
]   

S0 = ListPlot[dataAll, Frame -> True, FrameLabel -> {"x", "y"}, 
RotateLabel -> False, PlotStyle -> {Black, PointSize[0.01]}, 
PlotRange -> All, ImageSize -> 500]

I am wondering, if there is a simpler or even more correct way to perform this task. Perhaps, the Do loop needs improvement.

I noticed that the PlotStyle in ListPlot does not apply to all points of the dataAll list. Even if I determine the color (black) and the size, the output contains several colors ans sizes. Where is the mistake?

Many thanks in advance!

share|improve this question
    
Duplicate: mathematica.stackexchange.com/q/3165/5 –  rm -rf Jan 22 '13 at 17:13
    
@rm-rf The first issue is solved. However, the second issue regarding the global PlotStyle remains unsolved. –  Vaggelis_Z Jan 22 '13 at 17:27
    
Well, then please edit your question and focus only on that. Do not ask multiple, unrelated questions in a single post. Also, your example is not reproducible... you allude to a set of data*.out files that reside on your disk and we have no way of knowing what's in them and what the issues with your plot are. Please include a minimal example that users can copy-paste-evaluate to see your problem. Use simple functions like Sin[x] or RandomReal if a random list would suffice. –  rm -rf Jan 22 '13 at 17:33
2  
If you want all the points to be black and equal size, then define the plot style in this way: PlotStyle -> {{Black, PointSize[0.01]}}. Note the extra {} brackets. Without those, Mathematica cycles between black and automatically chosen colors with the size defined by PointSize. –  VLC Jan 22 '13 at 17:38
2  
@belisarius Done, although I'm not sure that this question deserves to be kept open. –  VLC Jan 22 '13 at 20:47
show 5 more comments

1 Answer 1

up vote 3 down vote accepted

When you plot several list of points and you want to define the same style for all the points you have to take care of how you insert the style in the PlotStyle option.

data = Table[RandomReal[{0, 1}, 10] + i, {i, 8}];
ListPlot[data, PlotStyle -> {Black, PointSize[.02]}]

enter image description here

In this case, the PlotStyle was not defined properly. Mathematica interprets this input as apply Black to the first list of points, apply PointSize[.02] to the second list; if there are more lists, cycle between the two styles.

To apply both options to all lists of points, you need to enclose the options between additional curly brackets. In this case Mathematica applies both the color and the size to the first list of points and then re-cycles these options for all the other lists of points.

ListPlot[data, PlotStyle -> {{Black, PointSize[.02]}}]

enter image description here

If you need to define separate styles for different lists of plots, you need to insert a list of lists containing the style options, and remember that Mathematica will always cycle through this list.

ListPlot[data, 
    PlotStyle -> {{Black, PointSize[.02]}, {Red, PointSize[.02]}}]

enter image description here

share|improve this answer
add comment

Your Answer

 
discard

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.