0
$\begingroup$

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!

$\endgroup$
4
  • $\begingroup$ You want all of the x,y pairs with the same time value to be plotted on a separate plot? $\endgroup$ Dec 8, 2018 at 23:04
  • $\begingroup$ I'm hoping to plot the lines on the same graph, with each line being a different time. $\endgroup$
    – user61807
    Dec 8, 2018 at 23:08
  • $\begingroup$ 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? $\endgroup$ Dec 8, 2018 at 23:30
  • $\begingroup$ That would be ideal, yes! $\endgroup$
    – user61807
    Dec 8, 2018 at 23:38

1 Answer 1

0
$\begingroup$

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

$\endgroup$
4
  • $\begingroup$ 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? $\endgroup$
    – user61807
    Dec 9, 2018 at 1:52
  • $\begingroup$ @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]] $\endgroup$ Dec 9, 2018 at 2:17
  • $\begingroup$ 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! $\endgroup$
    – user61807
    Dec 9, 2018 at 3:59
  • $\begingroup$ @Jay Great. I would appreciate it if you could upvote and accept the answer. Thanks! $\endgroup$ Dec 9, 2018 at 4:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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