Message Boards Message Boards

0
|
4711 Views
|
31 Replies
|
1 Total Likes
View groups...
Share
Share this post:

Import data from .file and listlineplot

Posted 11 years ago
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..
POSTED BY: selahittin cinar
31 Replies
Man this helps huge!!! and save time. You save my life..   I am plotting 250 files in a second emoticonemoticon
POSTED BY: selahittin cinar
Posted 11 years ago
Your first file is y=1 and this is almost hidden by your x axis at y=1.
If that is not important to see then it does not matter.
Otherwise look at PlotRange to tell a plot what y range to use.

I am very glad we were able to solve your problem.
I hope it works for you in the future.

You can edit your very large post of x,y values to delete those points.
I must have made some error in what I asked you to do. I was expecting to
see a single line of minX, maxX, minY, maxY and not thousands of lines.
I apologize for my error. I am glad that even with my errors you were successful.
POSTED BY: Bill Simpson


This is the all 21 files graph  Awesome!!!

onece again thank you so much..
POSTED BY: selahittin cinar
yep, it is done

thank you so much for your help..
POSTED BY: selahittin cinar

This is first 8 files graph   (:
POSTED BY: selahittin cinar
Posted 11 years ago
So this is done?

Wonderful. Finished.
POSTED BY: Bill Simpson
I figure it out.
ListLinePlot[
Map[Drop[Import[#, "Table"], 2] &,
  Table["C:\\Users\\cinar\\Documents\\Thesis_Numerics\\epsilon\\\
epsilon_0\\profile_shapes." <>
    StringTake["000" <> ToString[i], -4], {i, 1, 8}]]]
I just add "Table" in Import
POSTED BY: selahittin cinar
Posted 11 years ago
Well then something I am doing differently from you, because I do not have your files and cannot get your files and must manually translate back and forth because this forum software has never allowed people to hand each other data files, is breaking this.

If I add this
, PlotRange -> {0, 6}
as a last argument to your ListLinePlot so that it will show that your first plot file is almost exactly equal to 1 for all points and is almost hidden by the plot axis

Then I see the first 8 or 9 of your plots when I ask it to do 9 plots.

I can't get your files. You can't get my files. We are both half blind because of the forum software limitations.

Can you describe exactly what problem you have now? I do not see only 3 plots. I must be doing something different from you.
POSTED BY: Bill Simpson
By the way, data comes from Fotran output, dont know that matters
POSTED BY: selahittin cinar
 In[5]:= list1 =
  Drop[Import[
    "C:\\Users\\cinar\\Documents\\Thesis_Numerics\\epsilon\\epsilon_0\\\
 profile_shapes.0020", "Table"], 2]
 
 Out[5]= {{0., 5.34074}, {0.0628319, 5.34003}, {0.125664,
   5.33792}, {0.188496, 5.33441}, {0.251327, 5.32954}, {0.314159,
   5.32334}, {0.376991, 5.31586}, {0.439823, 5.30715}, {0.502655,
   5.29727}, {0.565487, 5.28628}, {0.628319, 5.27426}, {0.69115,
  5.26128}, {0.753982, 5.2474}, {0.816814, 5.2327}, {0.879646,
  5.21725}, {0.942478, 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}}
This works fine
POSTED BY: selahittin cinar
Posted 11 years ago
Look at your file number 9. It has spaces "E + 01" and this is not "E+01" like other files.
This makes Mathematica fail.

I am working. I will refresh this message when I find more problems.

Files 9,10,11,...21 all have spaces "E + 01".
These make Mathematica fail.
Can you remove those spaces and try again

I am working. I will refresh this message when I find more problems.
POSTED BY: Bill Simpson
ok
POSTED BY: selahittin cinar
Posted 11 years ago
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.
POSTED BY: Bill Simpson
Yes, I have exactly those 21 file names in my  epsilon_0 folder

I guess we need to import them Table form
POSTED BY: selahittin cinar
Posted 11 years ago
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?
POSTED BY: Bill Simpson
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..
POSTED BY: selahittin cinar
Posted 11 years ago
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.
POSTED BY: Bill Simpson
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?
POSTED BY: selahittin cinar
Posted 11 years ago
I apologize for forgetting your drop. I edited to include the Drop now. Refresh page to see.
POSTED BY: Bill Simpson
Posted 11 years ago
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.
POSTED BY: Bill Simpson
Since first two entry of all data is blank, I  need drop them. So, where should I put Drop code...
POSTED BY: selahittin cinar
Yes, I found something like that on web but I could not modify it. Let me try yours..
POSTED BY: selahittin cinar
Posted 11 years ago
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
POSTED BY: Bill Simpson
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?
POSTED BY: selahittin cinar
Posted 11 years ago
Yes.

What is the problem?

Do they not plot as I showed?
POSTED BY: Bill Simpson
 
 
 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.
POSTED BY: selahittin cinar
Posted 11 years ago
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.
POSTED BY: Bill Simpson
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.
POSTED BY: Sean Clarke
@sean clarke,  format is file, but I can open them with either excel or notepad program
POSTED BY: selahittin cinar
  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
POSTED BY: selahittin cinar
Posted 11 years ago
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.
POSTED BY: Bill Simpson
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract