# Plot the complete dataset as listplots

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

A(1),B(1),A(2),B(2),A(3),B(3),A(4),B(4),A(5),B(5)
1,2,4,5,6,4,7,8,9,0
5,3,2,5,5,2,3,1,8,3
7,3,8,3,2,2,3,4,5,6
9,8,7,2,5,3,6,7,8,9


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

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?

Consider the following:

data = ImportString[
"A(1),B(1),A(2),B(2),A(3),B(3),A(4),B(4),A(5),B(5)
1,2,4,5,6,4,7,8,9,0
5,3,2,5,5,2,3,1,8,3
7,3,8,3,2,2,3,4,5,6
];

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


• 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. Commented Feb 8, 2021 at 2:44
• @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. Commented Feb 8, 2021 at 4:01
• Here is my original dataset and the problem I am trying to solve: mathematica.stackexchange.com/questions/239583/… Commented Feb 8, 2021 at 4:02
• @Indeterminate OK I see. I think you may have oversimplified here a bit. I've added an answer to that question. Commented Feb 8, 2021 at 4:10

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

ds = SemanticImportString[
"A(1),B(1),A(2),B(2),A(3),B(3),A(4),B(4),A(5),B(5)
1,2,4,5,6,4,7,8,9,0
5,3,2,5,5,2,3,1,8,3
7,3,8,3,2,2,3,4,5,6
9,8,7,2,5,3,6,7,8,9"];
(*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]


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,
labels];
Legended[dsllp, Placed[legend, Automatic]]
Legended[dslcpp, Placed[legend, Automatic]]