I have several files what i would like to plot at once, they are .dat files and they have names as a numerical sequence from 1 to 4 (they are about a hundred but for the example 4 are ok) so i use

Do[ {p = Import["F:\P3 S2 L3\" <> ToString[i] <> "a.dat", "Table"]; 
     ListPlot[{p}, Joined -> True, PlotRange -> {{0, 1000}, {0, All}}, 
              PlotStyle -> {Blue}]},
{i, 1, 4}]

but i dont have any result



  • 3
    $\begingroup$ Do does not produce any output, use Table instead. $\endgroup$ – rcollyer Mar 5 '15 at 15:38
  • $\begingroup$ @GregorioMartinez Can you plot even a single plot? $\endgroup$ – David G. Stork Mar 5 '15 at 17:18
  • 1
    $\begingroup$ just put Print@ListPlot.. in your loop if there are hundreds and you just want to display the plots individually. $\endgroup$ – george2079 Mar 6 '15 at 0:57

Create Data and export so we can have working files.

data = Table[{i, Sin[ a i]}, {a, 3}, {i, 0, 2 Pi, 0.1}];
Export[StringJoin[ToString[#], "a.dat"], data[[#, All]]] & /@ 

Proceed to read the data now:

p = Import[StringJoin[ToString[#], "a.dat"]] & /@ Range[3];


ListPlot[Evaluate[p], Joined -> True]

enter image description here

Graph the charts independently:

 ListPlot[p[[#, All]], Joined -> True, 
    PlotLabel -> StringJoin[ToString[#], "a.dat"]] & /@ 

enter image description here

| improve this answer | |
  • $\begingroup$ Thanks, but i want the graphs to be independent each one in a different coordinated plane also, i already have the data in separated files. $\endgroup$ – Gregorio Martinez Mar 6 '15 at 11:01
  • $\begingroup$ If you look at the code you'll see it is reading separated files.(the first section of code creates separated files to use in the answer as no actual data has been provided. $\endgroup$ – Zviovich Mar 6 '15 at 11:58
  • $\begingroup$ Yes the files are different but all the plotted graphs are in the same coordinated plane since you used the p variable to call the data string. what i want is to have each sinusoidal in an independent figure Thanks a lot for your answers $\endgroup$ – Gregorio Martinez Mar 6 '15 at 12:38
  • $\begingroup$ Check the changes $\endgroup$ – Zviovich Mar 6 '15 at 13:52

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.