I have imported as a csv file and converted to a Dataset. The data is in the following csv format


Now I imported the data using

ds = Import["data.csv", "Dataset", HeaderLines -> 1]

Now basically I want to plot $B(i)$ v/s $A(i)$ for different $i$'s on the same plot. I can do that for 1 $i$ using

ds[ListLinePlot, {"A(1)", "B(1)"}]

And I get the following curve enter image description here

Now, I want to do the same for all $i$'s and plot them on the same plot. I know I can probably just write them each down but my original dataset (not shown here) is quite large. So I want to automate it for all $i$. Any easy way to execute such a command?


2 Answers 2


Consider the following:

data = ImportString[
          9,8,7,2,5,3,6,7,8,9", HeaderLines -> 1

  Transpose /@ Partition[Transpose[data], 2],
  PlotLegends -> Range[5]

enter image description here

  • $\begingroup$ Is there any other way to do it without partition? Let's say I want to run a loop over i, because in my original dataset there are some other values such as C(i) in the dataset as well. $\endgroup$ Commented Feb 8, 2021 at 2:44
  • $\begingroup$ @Indeterminate Explicit loops are almost never the answer in MMA. The Partition approach would work without change for however main pairs of values you have in your dataset, there's no need to change it. If it doesn't work when you try, please show the structure of the actual dataset you have. $\endgroup$
    – MarcoB
    Commented Feb 8, 2021 at 4:01
  • $\begingroup$ Here is my original dataset and the problem I am trying to solve: mathematica.stackexchange.com/questions/239583/… $\endgroup$ Commented Feb 8, 2021 at 4:02
  • $\begingroup$ @Indeterminate OK I see. I think you may have oversimplified here a bit. I've added an answer to that question. $\endgroup$
    – MarcoB
    Commented Feb 8, 2021 at 4:10

Here is another possible way if you want to stay within the dataset framework.

ds = SemanticImportString[
(*Create list of B versus A pairs*)
xypairs = Partition[ds // First // Keys // Normal, 2];
(*Standard ListLinePlot*)
dsllp = ds[Transpose /* Values /* ListLinePlot, xypairs]
(* Marco's ListCurvePathPlot *)
dslcpp = ds[Transpose /* Values /* ListCurvePathPlot, xypairs]

No legend plots

I did not find a way to add legends directly, so I had to manually add them as shown below:

(*Use standard color list 97*)
colors = ColorData[97, "ColorList"][[;; Length@xypairs]];
labels = Style[StringTemplate["`2` vs `1`"][##], 14] & @@@ xypairs;
legend = LineLegend[Directive[#, AbsoluteThickness[2]] & /@ colors, 
Legended[dsllp, Placed[legend, Automatic]]
Legended[dslcpp, Placed[legend, Automatic]]

Plots with legends


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.