Import data from .file and listlineplot

Hi All,

I have file data only contains x and y points and I would like to import all data and plot them..

This is what I did so far and it works fine.

list1 = Delete[
   Import["C:\\Users\\cinar\\Documents\\Thesis_Numerics\\epsilon\\\
epsilon_0 - Copy - Copy - Copy - Copy\\profile_shapes.0501", 
    "Table"], {{1}, {2}}];

list2 = Delete[
   Import["C:\\Users\\cinar\\Documents\\Thesis_Numerics\\epsilon\\\
epsilon_0 - Copy - Copy - Copy - Copy\\profile_shapes.0500", 
    "Table"], {{1}, {2}}];

 list3 = Delete[
   Import["C:\\Users\\cinar\\Documents\\Thesis_Numerics\\epsilon\\\
epsilon_0 - Copy - Copy - Copy - Copy\\profile_shapes.0499", 
    "Table"], {{1}, {2}}];

 list4 = Delete[
   Import["C:\\Users\\cinar\\Documents\\Thesis_Numerics\\epsilon\\\
epsilon_0 - Copy - Copy - Copy - Copy\\profile_shapes.0498", 
    "Table"], {{1}, {2}}];

list5 = Delete[
   Import["C:\\Users\\cinar\\Documents\\Thesis_Numerics\\epsilon\\\
epsilon_0 - Copy - Copy - Copy - Copy\\profile_shapes.0100", 
    "Table"], {{1}, {2}}];

ListLinePlot[{{list1}, list2, list3, list4, list5}]

I am using delete func. because first two data is blank.

I would like to plot them in one screen and don’t want to label like list1, list2 etc.,

Any suggestion?

Thanks in advance..

If you could show a small example of one of your file contents and all the files were similarly formatted then it might be possible to help answer this.
Just three or four lines of data clearly showing what characters separate each data item should be enough.

Hi,

This is a part of one of my file’s data. Type of file is .file. I am importing them from the source and plotting them, but I wanna plot other file on the same plot..

For example, this data is imported from profile_shape.0007 but I have other data files..
      .1256637061435917E+00 .2492014483294018E+01
      .1884955592153876E+00 .2488754499332517E+01
      .2513274122871835E+00 .2484223036756323E+01
      .3141592653589793E+00 .2478451658168460E+01
      .3769911184307752E+00 .2471479644190235E+01
      .4398229715025711E+00 .2463353118953901E+01
      .5026548245743669E+00 .2454124081384404E+01
      .5654866776461628E+00 .2443849388191504E+01
      .6283185307179586E+00 .2432589732592085E+01
      .6911503837897546E+00 .2420408658188671E+01
      .7539822368615504E+00 .2407371640925823E+01

What do you mean by plotting them on one screen?

Do you mean that you want to plot multiple data sets in the same graph? There are some examples of that in the documentation for ListLinePlot.

If possible, can you provide a simple example of your question using a small data set that you can paste in here? This would help us better understand your question.

You mentioned that the numbers in your data look like this:

1256637061435917E+00

What is the file format of the data you are importing? You must tell Import what the file format of the data is you are importing. If it isn’t a particular file format, then Import will not be able to import it properly. It will probably import it as a list of strings. Is Import importing your data as a list of strings?

Before you worry about plotting your numbers, you verify that they have been imported correctly and that you can use them as numbers. You should be able to add them and subtract them from each other for example.

Thank you for your example data file. I was able to use that to create three sample data files.
I did not tell Mathematica any data format and was able to successfully use this

ListLinePlot[{
  Delete[Import["profile_shape.0007"], {{1}, {2}}],
  Delete[Import["profile_shape.0008"], {{1}, {2}}],
  Delete[Import["profile_shape.0009"], {{1}, {2}}]
}]

to put all three plots together and not use list1, list2, list3.

You could use Drop instead of Delete

ListLinePlot[{
  Drop[Import["profile_shape.0007"], 2],
  Drop[Import["profile_shape.0008"], 2],
  Drop[Import["provile_shape.0009"], 2],
}]

and get the same result.

Please test this carefully to make certain I have no errors and it is plotting correctly.
If you need further assistance or changes then please describe what you need and I will try to provide a solution.


In[3]:= list1 = 
 Import["C:\\Users\\cinar\\Documents\\Thesis_Numerics\\epsilon\\\
epsilon_0\\profile_shapes.0020", "Table"]

Out[3]= {{0., 5.34074}, {0.06283, 5.34003}, {0.12566, 
  5.33792}, {0.1885, 5.33441}, {0.25133, 5.32954}, {0.31416, 
  5.32334}, {0.37699, 5.31586}, {0.43982, 5.30715}, {0.50265, 
  5.29727}, {0.56549, 5.28628}, {0.62832, 5.27426}, {0.69115, 
  5.26128}, {0.75398, 5.2474}, {0.81681, 5.2327}, {0.87965, 
  5.21725}, {0.94248, 5.20113}, {1.00531, 5.1844}, {1.06814, 
  5.16714}, {1.13097, 5.14941}, {1.19381, 5.13128}, {1.25664, 
  5.1128}, {1.31947, 5.09404}, {1.3823, 5.07506}, {1.44513, 
  5.05591}, {1.50796, 5.03665}, {1.5708, 5.01734}, {1.63363, 
  4.99803}, {1.69646, 4.97877}, {1.75929, 4.95962}, {1.82212, 
  4.94065}, {1.88496, 4.92189}, {1.94779, 4.90342}, {2.01062, 
  4.88529}, {2.07345, 4.86757}, {2.13628, 4.85032}, {2.19911, 
  4.8336}, {2.26195, 4.81749}, {2.32478, 4.80205}, {2.38761, 
  4.78737}, {2.45044, 4.7735}, {2.51327, 4.76052}, {2.57611, 
  4.74851}, {2.63894, 4.73754}, {2.70177, 4.72767}, {2.7646, 
  4.71897}, {2.82743, 4.71149}, {2.89027, 4.7053}, {2.9531, 
  4.70044}, {3.01593, 4.69694}, {3.07876, 4.69482}, {3.14159, 
  4.69412}, {3.20442, 4.69482}, {3.26726, 4.69694}, {3.33009, 
  4.70044}, {3.39292, 4.7053}, {3.45575, 4.71149}, {3.51858, 
  4.71897}, {3.58142, 4.72767}, {3.64425, 4.73754}, {3.70708, 
  4.74851}, {3.76991, 4.76052}, {3.83274, 4.7735}, {3.89557, 
  4.78737}, {3.95841, 4.80205}, {4.02124, 4.81749}, {4.08407, 
  4.8336}, {4.1469, 4.85032}, {4.20973, 4.86757}, {4.27257, 
  4.88529}, {4.3354, 4.90342}, {4.39823, 4.92189}, {4.46106, 
  4.94065}, {4.52389, 4.95962}, {4.58673, 4.97877}, {4.64956, 
  4.99803}, {4.71239, 5.01734}, {4.77522, 5.03665}, {4.83805, 
  5.05591}, {4.90088, 5.07506}, {4.96372, 5.09404}, {5.02655, 
  5.1128}, {5.08938, 5.13128}, {5.15221, 5.14941}, {5.21504, 
  5.16714}, {5.27788, 5.1844}, {5.34071, 5.20113}, {5.40354, 5.21725},
  {5.46637, 5.2327}, {5.5292, 5.2474}, {5.59203, 5.26128}, {5.65487, 
  5.27426}, {5.7177, 5.28628}, {5.78053, 5.29727}, {5.84336, 
  5.30715}, {5.90619, 5.31586}, {5.96903, 5.32334}, {6.03186, 
  5.32954}, {6.09469, 5.33441}, {6.15752, 5.33792}, {6.22035, 
  5.34003}, {6.28319, 5.34074}}

In[4]:= list2 = 
 Import["C:\\Users\\cinar\\Documents\\Thesis_Numerics\\epsilon\\\
epsilon_0\\profile_shapes.0021", "Table"]

Out[4]= {{0., 5.39249}, {0.06283, 5.39178}, {0.12566, 
  5.38966}, {0.1885, 5.38616}, {0.25133, 5.38128}, {0.31416, 
  5.37508}, {0.37699, 5.3676}, {0.43982, 5.35889}, {0.50265, 
  5.34901}, {0.56549, 5.33802}, {0.62832, 5.32599}, {0.69115, 
  5.313}, {0.75398, 5.29912}, {0.81681, 5.28442}, {0.87965, 
  5.26897}, {0.94248, 5.25285}, {1.00531, 5.23612}, {1.06814, 
  5.21886}, {1.13097, 5.20112}, {1.19381, 5.18298}, {1.25664, 
  5.1645}, {1.31947, 5.14574}, {1.3823, 5.12676}, {1.44513, 
  5.10761}, {1.50796, 5.08834}, {1.5708, 5.06903}, {1.63363, 
  5.04971}, {1.69646, 5.03045}, {1.75929, 5.0113}, {1.82212, 
  4.99232}, {1.88496, 4.97356}, {1.94779, 4.95509}, {2.01062, 
  4.93696}, {2.07345, 4.91923}, {2.13628, 4.90198}, {2.19911, 
  4.88526}, {2.26195, 4.86914}, {2.32478, 4.8537}, {2.38761, 
  4.83901}, {2.45044, 4.82514}, {2.51327, 4.81216}, {2.57611, 
  4.80015}, {2.63894, 4.78917}, {2.70177, 4.7793}, {2.7646, 
  4.7706}, {2.82743, 4.76312}, {2.89027, 4.75693}, {2.9531, 
  4.75206}, {3.01593, 4.74856}, {3.07876, 4.74645}, {3.14159, 
  4.74574}, {3.20442, 4.74645}, {3.26726, 4.74856}, {3.33009, 
  4.75206}, {3.39292, 4.75693}, {3.45575, 4.76312}, {3.51858, 
  4.7706}, {3.58142, 4.7793}, {3.64425, 4.78917}, {3.70708, 
  4.80015}, {3.76991, 4.81216}, {3.83274, 4.82514}, {3.89557, 
  4.83901}, {3.95841, 4.8537}, {4.02124, 4.86914}, {4.08407, 
  4.88526}, {4.1469, 4.90198}, {4.20973, 4.91923}, {4.27257, 
  4.93696}, {4.3354, 4.95509}, {4.39823, 4.97356}, {4.46106, 
  4.99232}, {4.52389, 5.0113}, {4.58673, 5.03045}, {4.64956, 
  5.04971}, {4.71239, 5.06903}, {4.77522, 5.08834}, {4.83805, 
  5.10761}, {4.90088, 5.12676}, {4.96372, 5.14574}, {5.02655, 
  5.1645}, {5.08938, 5.18298}, {5.15221, 5.20112}, {5.21504, 
  5.21886}, {5.27788, 5.23612}, {5.34071, 5.25285}, {5.40354, 
  5.26897}, {5.46637, 5.28442}, {5.5292, 5.29912}, {5.59203, 
  5.313}, {5.65487, 5.32599}, {5.7177, 5.33802}, {5.78053, 
  5.34901}, {5.84336, 5.35889}, {5.90619, 5.3676}, {5.96903, 
  5.37508}, {6.03186, 5.38128}, {6.09469, 5.38616}, {6.15752, 
  5.38966}, {6.22035, 5.39178}, {6.28319, 5.39249}}

In[5]:= ListLinePlot[{list1, list2}, 
 PlotLegends -> {"list1", "last profile"}]


This is the list I am getting after I import them.

Yes.

What is the problem?

Do they not plot as I showed?

ListLinePlot[{
  Drop[Import["profile_shape.0007"], 2],
  Drop[Import["profile_shape.0008"], 2],
  Drop[Import["provile_shape.0009"], 2],
}]

This works perfectly and get rid of labeling them list1, list2 etc. But I have say 200 file and I do not want to import them file by file

Can I import them 1 to 200 in one time?

@sean clarke, format is file, but I can open them with either excel or notepad program

Ah… Now I understand.

You want “string hacking”

ListLinePlot[
 Map[Drop[Import[#],2]&,Table["profile_shape." <> StringTake["000" <> ToString[i], -4], {i, 1, 200}]]
 ]

You create the file name using ToString and <> which is also called StringJoin and StringTake so that you can create the needed leading zero digits.
This gives you a list of 200 file names as strings.
Then you use Map to give each file name to Import.
The result is 200 imports.
And then ListLinePlot.

Try this and see if it works.
If you need more help with string hacking then describe exactly what the names must be

Yes, I found something like that on web but I could not modify it. Let me try yours..

Since first two entry of all data is blank, I need drop them. So, where should I put Drop code…

If all your data files are in a single folder or directory then you could look at SetDirectory in the help system.
Use that to choose the working directory. Then use FileNames to get the list of all files in that directory.
The result should be the same as my more complicated Table gives.

Perhaps that would be easier for you to do.

I apologize for forgetting your drop. I edited to include the Drop now. Refresh page to see.

This is what I did

ListLinePlot[
 Map[Drop[Import[#], 2] &, 
  Table["C:\\Users\\cinar\\Documents\\Thesis_Numerics\\epsilon\\\
epsilon_0\\profile_shapes." <> 
    StringTake["000" <> ToString[i], -4], {i, 1, 21}]]]

since my first folder contains 21 file, I replaced 200 by 21. but it only shows two graph

this is my orijinal file path

“C:\\Users\\cinar\\Documents\\Thesis_Numerics\\epsilon\\epsilon_0\\\
profile_shapes.0001”

where am I doing wrong? I feel like I am almost there (:

what -4 stans for?

First check that the file names are correctly generated.
What does this show?

FullForm[Table["C:\\Users\\cinar\\Documents\\Thesis_Numerics\\epsilon\\epsilon_0\\profile_shapes."<>StringTake["000"<>ToString[i],-4],{i,1,21}]]

-4 takes the last four characters.

This is trying to generage the numbers with the correct number of leading zeros when Mathematica does not usually want to include leading zeros.

List["C:\\Users\\cinar\\Documents\\Thesis_Numerics\\epsilon\\epsilon_0\\profile_shapes.0001","C:\\Users\\cinar\\Documents\\Thesis_Numerics\\epsilon\\epsilon_0\\profile_shapes.0002","C:\\Users\\cinar\\Documents\\Thesis_Numerics\\epsilon\\epsilon_0\\profile_shapes.0003","C:\\Users\\cinar\\Documents\\Thesis_Numerics\\epsilon\\epsilon_0\\profile_shapes.0004","C:\\Users\\cinar\\Documents\\Thesis_Numerics\\epsilon\\epsilon_0\\profile_shapes.0005","C:\\Users\\cinar\\Documents\\Thesis_Numerics\\epsilon\\epsilon_0\\profile_shapes.0006","C:\\Users\\cinar\\Documents\\Thesis_Numerics\\epsilon\\epsilon_0\\profile_shapes.0007","C:\\Users\\cinar\\Documents\\Thesis_Numerics\\epsilon\\epsilon_0\\profile_shapes.0008","C:\\Users\\cinar\\Documents\\Thesis_Numerics\\epsilon\\epsilon_0\\profile_shapes.0009","C:\\Users\\cinar\\Documents\\Thesis_Numerics\\epsilon\\epsilon_0\\profile_shapes.0010","C:\\Users\\cinar\\Documents\\Thesis_Numerics\\epsilon\\epsilon_0\\profile_shapes.0011","C:\\Users\\cinar\\Documents\\Thesis_Numerics\\epsilon\\epsilon_0\\profile_shapes.0012","C:\\Users\\cinar\\Documents\\Thesis_Numerics\\epsilon\\epsilon_0\\profile_shapes.0013","C:\\Users\\cinar\\Documents\\Thesis_Numerics\\epsilon\\epsilon_0\\profile_shapes.0014","C:\\Users\\cinar\\Documents\\Thesis_Numerics\\epsilon\\epsilon_0\\profile_shapes.0015","C:\\Users\\cinar\\Documents\\Thesis_Numerics\\epsilon\\epsilon_0\\profile_shapes.0016","C:\\Users\\cinar\\Documents\\Thesis_Numerics\\epsilon\\epsilon_0\\profile_shapes.0017","C:\\Users\\cinar\\Documents\\Thesis_Numerics\\epsilon\\epsilon_0\\profile_shapes.0018","C:\\Users\\cinar\\Documents\\Thesis_Numerics\\epsilon\\epsilon_0\\profile_shapes.0019","C:\\Users\\cinar\\Documents\\Thesis_Numerics\\epsilon\\epsilon_0\\profile_shapes.0020","C:\\Users\\cinar\\Documents\\Thesis_Numerics\\epsilon\\epsilon_0\\profile_shapes.0021"]

It shows my files path in order..

So those appear to be the 21 file names, each with 4 digits after the last .
This is good.
Now do you have exactly those 21 file names in your epsilon_0 folder?

Since only two files plot can you find one of the files that does not plot.
Is the content of that file correct so that it should plot?
Is the range of numbers perhaps different in the file that does not plot?

Yes, I have exactly those 21 file names in my epsilon_0 folder

I guess we need to import them Table form

I will bet money that Table form will not help.

Show me this

pairs = Partition[Flatten[
Map[Drop[Import[#], 2] &, Table["C:\\Users\\cinar\\Documents\\Thesis_Numerics\\epsilon\\\
epsilon_0\\profile_shapes." <> StringTake["000" <> ToString[i], -4], {i, 1, 21}]]], 2];
x = pairs[[All, 1]];
y = pairs[[All, 2]];
{Min @@ x, Max @@ x, Min @@ y, Max @@ y}

That is your Map and Drop and Import without change.
This only looks at your minimum and maximum values for x and y.

I am guessing this may show your data is outside the range being plotted.
If that is true then I will tell ListLinePlot to use a larger range to see all points.