1
$\begingroup$

I am trying to plot two NMR line graphs superimposed to show a before and after. I was able to successfully do it with excel files but the CSV files have been giving me trouble. This is my code. I tested the two import lines and it spits out a series of ordered pairs however the x and y values are not separated by commas.

 0911PECHGBISO = Import["/Users/Desktop/Lab Stuff/0911\Data/0911-PECH-GB-ISO2.csv",{"Data", ;; , ;;}];
0911PECHGB = Import["/Users/Desktop/Lab Stuff/0911\Data/0911-PECH-GB.csv", {"Data", ;; , ;;}];

ListLinePlot[{0911PECHGBISO, 0911PECHGB}, 



Frame ->  {{False, False}, {True, False}},
 PlotRange -> {{3, 5.5}, {-10000, 200000}}, 
 ScalingFunctions -> {"Reverse", "Linear"}, 
 FrameLabel -> {"Chemical Shift (ppm)"}, 
 PlotStyle -> {Directive[Blue, Thickness[0.001]], 
   Directive[Black, Thickness[0.001]]}, ImageSize -> Large, 
 LabelStyle -> {Black, FontSize -> 22}, FrameStyle -> Black, 
 AspectRatio -> 0.618, GridLines -> {{}, {0, 1.618}},
 PlotLegends -> 
  LineLegend[{Blue, Black}, {"After TCI", "Before TCI"}], 
 FrameTicks -> {{None, 
    None}, {LinTicks[3, 5.5, 1, 4, TickDirection -> Out, 
     DecimalDigits -> 1, TickLengthScale -> 3], None}}]

My output for one of the files is enter image description here

$\endgroup$
11
  • 1
    $\begingroup$ Unfortunately, no one is going to able to see any of your actual data because it's on your hard drive, and hidden inside the symbols you've defined. In general, if you don't get a plot, it's because what you're attempting to plot isn't a set of numeric quantities. To debug, try replacing plot with Table, and dump a few values out in the region of interest. The various options probably aren't a factor. If you want help, show a few values with Short or Take so users can see what your data looks like. Actually, if your data is returned as lists, you'll probably need to use something like $\endgroup$
    – user87932
    Oct 2, 2023 at 19:53
  • $\begingroup$ ..Transpose to convert the lists into a list of {x,y} pairs. $\endgroup$
    – user87932
    Oct 2, 2023 at 19:54
  • $\begingroup$ How would I go about transposing and not mess up the order of the list? $\endgroup$
    – Isabelle
    Oct 2, 2023 at 20:02
  • $\begingroup$ Are you saying that you have two lists, each of which is already a set of {{x1,y1},{x2,y2},...} pairs? If you plot just one at a time, do you get a valid plot? If so, then you just need to Join the lists together into one. Use Join[list1,list2] inside your plot function. I assumed the first was a list of x values, and the second a list of y values; for this case, you need to transpose, but not if they are already a set of x,y pairs. $\endgroup$
    – user87932
    Oct 2, 2023 at 20:20
  • 1
    $\begingroup$ That's a string with a tab character in it. Could you upload a sample of the CSV file so people can assist with the importing? $\endgroup$
    – MelaGo
    Oct 2, 2023 at 23:36

1 Answer 1

1
$\begingroup$

Maybe I'm missing something, but there is a glaring problem in your code:

0911PECHGBISO = Import[...]

An identifier cannot start with a number. You have essentially written

Times[0911, PECHGBISO] = Import[...]

I assume you have gotten an error message saying:

Tag Times in 0911 PECHGBISO is Protected.

And nothing has been set. This is apparent in your screenshot: In Short[0911PECHGB], the word PECHGB appear in blue. It's a symbol that's unknown to Mathematica, it hasn't been set to anything.

$\endgroup$
1
  • $\begingroup$ Yeah so fair sorry, it started with my initials which I removed for security purposes $\endgroup$
    – Isabelle
    Oct 3, 2023 at 14:31

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.