I have a lot experience with traditional programming languages, but almost none with mathematica. I have data that I've transformed and saved to a file in the format

{x,y,time}

{x,y,time}

...

Where x and y are the data I want on the x and y axis, and "time" is a timestamp where each dataset should be its own line. The only "interesting" part of the data is that they're all incredibly small numbers, so they look like "1.00E-010" along the y-axis and I don't know if this will be a problem.

I've tried to use ReadList and then ArrayReshape, but I honestly don't have a good idea as to what I'm doing. Any help, or just a direction to look in, would be huge.

For the record I can modify the formatting of the file somewhat if it's helpful.

Thanks!

New contributor
Jay is a new contributor to this site. Take care in asking for clarification, commenting, and answering. Check out our Code of Conduct.
  • You want all of the x,y pairs with the same time value to be plotted on a separate plot? – Rohit Namjoshi yesterday
  • I'm hoping to plot the lines on the same graph, with each line being a different time. – Jay yesterday
  • So you want a single plot with all of the x,y pairs that have the same time value assigned a different color or label on the plot? – Rohit Namjoshi yesterday
  • That would be ideal, yes! – Jay yesterday
up vote 0 down vote accepted

Assuming you want a single plot with all of the x,y pairs that have the same time value assigned a different color / label then it would be easier if the format of the data is just CSV, remove the curly braces.

rawData = Import["~/data.csv", "CSV"];
groupedData = MapAt[Most, GroupBy[rawData, Last], {All, All}];
ListLinePlot[Values[groupedData], PlotLegends -> Keys[groupedData]]

May have to be changed depending on the format of time

  • It looks like that would work, but I've left it running for over an hour and it's still trying to resolve. The file is about 50,000 lines with 3 columns which doesn't seem excessive for a modern computer. Is there any reason mathematica would hang so hard on this? – Jay yesterday
  • @Jay That seems excessively long. I would abort evaluation and check if the data was imported correctly. Length[groupedData] is the number of distinct time values. Is it what you expect? If not then something is wrong with the grouping. What exactly is the format of the time column? You can also try plotting a small subset of the values and make sure it looks right. ListLinePlot[Take[Values[groupedData], 10], PlotLegends -> Take[Keys[groupedData], 10]] – Rohit Namjoshi yesterday
  • Simply moving the directory to something else and then putting it back fixed the error. I don't know why it was being a problem. Thank you so much for all your help! – Jay yesterday
  • @Jay Great. I would appreciate it if you could upvote and accept the answer. Thanks! – Rohit Namjoshi yesterday

Your Answer

Jay is a new contributor. Be nice, and check out our Code of Conduct.

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.