# Plot an arbitrary data column vs another column [closed]

v1v2 = {{-10, 8.04, 8.046, 0.006}, {-9, 9.021,
7.37, -1.6510000000000007}, {-8, 6.756, 8.527,
1.770999999999999}, {-7, 8.058, 6.178, -1.88}, {-6, 5.625,
7.635, 2.01}, {-5, 5.326, 7.626, 2.3000000000000007}, {-4,
5.013, 7.5, 2.487}, {-3, 4.68, 7.319,
2.6390000000000002}, {-2, 7.121, 7.19,
0.06899999999999995}, {-1, 6.914, 6.919,
0.004999999999999893}, {0, 3.504, 5.468, 1.964}, {1, 3.08,
4.831, 1.7510000000000003}, {2, 2.284, 4.396, 2.112}, {3,
1.928, 4.201, 2.2729999999999997}, {4, 1.928, 4.201,
2.2729999999999997}, {5, 1.596, 4.018,
2.4219999999999997}, {6, 1.286, 3.847, 2.561}, {0.995,
3.686, 2.691}, {0.724, 3.531, 2.8070000000000004}, {0.469,
3.387, 2.918}, {0.23, 3.249, 3.019}};


How can I plot an arbitrary column versus another arbitrary column. For example the third column, vs the first column: {{-10,8.046},{-9,7.37},{-8,8.527}...}

• ListLinePlot[v1v2[[All,{1,3}]]] – andre314 Jan 14 '18 at 6:46

### Edit

Here a function that will do it.

plotFrom2Col[data_, xCol_, yCol_, opts : OptionsPattern[]] :=
Module[{pts},
pts = Extract[#, {{xCol}, {yCol}}] & /@ data;
ListLinePlot[pts,
Epilog -> {Red, AbsolutePointSize[5], Point[pts]},
opts]]


Then with

data =
{{-10, 8.04, 8.046, 0.006}, {-9, 9.021, 7.37, -1.65}, {-8, 6.756, 8.527, 1.7701},
{-7, 8.058, 6.178, -1.88}, {-6, 5.625, 7.635, 2.01}, {-5, 5.326, 7.626, 2.3},
{-4, 5.013, 7.5, 2.487}, {-3, 4.68, 7.319, 2.639,}, {-2, 7.121, 7.19, 0.069},
{-1, 6.914, 6.919, 0.005}, {0, 3.504, 5.468, 1.964}, {1, 3.08, 4.831, 1.751},
{2, 2.284, 4.396, 2.112}, {3, 1.928, 4.201, 2.273}, {4, 1.928, 4.201, 2.273},
{5, 1.596, 4.018, 2.422}, {6, 1.286, 3.847, 2.561}, {7, 0.995, 3.686, 2.691},
{8, 0.724, 3.531, 2.807}, {9, 0.469, 3.387, 2.918}, {10, 0.23, 3.249, 3.019}};

plotFrom2Col[data, 1, 3]


plotFrom2Col accepts plot options

plotFrom2Col[data, 3, 2, PlotStyle -> Dashed, Frame -> True]


### Update

I got to thinking it would be a good idea to make showing the data points optional rather than mandatory as it is above. As usual there are multiple ways to modify plotFrom2Col to provide this additional capability. I experimented with two different ways and finally decided that the following is the better of the two.

Clear[plotFrom2Col]
plotFrom2Col[data_, xCol_, yCol_, showPts : (True | False) : True,
opts : OptionsPattern[]] :=
Module[{pts, opseq},
pts = Extract[#, {{xCol}, {yCol}}] & /@ data;
opseq =
If[showPts,
{Epilog -> {Red, AbsolutePointSize[5], Point[pts]}, opts},
{opts}];
ListLinePlot[pts, opseq]]


Default usage.

plotFrom2Col[data, 1, 3]


ListLinePlot options may be given.

plotFrom2Col[data, 1, 3, PlotStyle -> Dashed]


The default epilog may be suppressed.

plotFrom2Col[data, 1, 3, False, PlotStyle -> Dashed]

The default epilog may be overridden.

plotFrom2Col[data, 1, 3, False,
PlotStyle -> Dashed,
Epilog -> {Text["Column 3 plotted\nagainst column 1", Scaled[{.2, .3}]]}]


The data points can be shown without the plot.

plotFrom2Col[data, 1, 3, PlotStyle -> None, Frame -> True, Axes -> False]


Here is a Dataset approach:

ds = Dataset[v1v2];

ds[ListLinePlot, {1, 3}]


(* 3rd against first column *)

data13 = Transpose[{v1v2[[All, 1]], v1v2[[All, 3]]}];

ListLinePlot[data13, FrameLabel -> {"col 1", "col 3"}, Frame -> True,
Epilog -> {PointSize[Large], Red, Point[data]}]


You can use Apply to extract the columns you want (here, 3 and 1) and place them a new list that can be entered as input to ListLinePlot.

data13 = Apply[{#1, #3} &, v1v2, 1];

ListLinePlot[data13, FrameLabel -> {"col 1", "col 3"}, Frame -> True,
Epilog -> {PointSize[Large], Red, Point[data13]}]


This is easily modified to work with rows:

data13r = Apply[{#1, #3} &, v1v2] // Transpose;

ListLinePlot[data13r, FrameLabel -> {"row 1", "row 3"}, Frame -> True,
Epilog -> {PointSize[Large], Red, Point[data13r]}]