4
$\begingroup$

I have four lists as given below:

 l1 = {r1 -> 0.1, r2 -> 0.3, r3 -> 0.1, r4 -> 1.0, r5 -> 0.3, 
   r6 -> 0.1};
l2 = {r1 -> 0.3, r2 -> 0.9, r3 -> 0.5, r4 -> 0.1, r5 -> 0.2, 
   r6 -> 0.2};
l3 = {r1 -> 0.4, r2 -> 0.1, r3 -> 0.2, r4 -> 0.2, r5 -> 0.7, 
   r6 -> 0.3};
l4 = {r1 -> 0.5, r2 -> 0.63, r3 -> 0.4, r4 -> 0.4, r5 -> 0.5, 
   r6 -> 0.4};

Is there an easy way to show how (r1, r2,r3,r4, r5) change respect to r6 ? I am in practice, dealing with large number of such lists, but the variables are just six.

$\endgroup$

4 Answers 4

4
$\begingroup$
Clear["Global`*"];
l1 = {r1 -> 0.1, r2 -> 0.3, r3 -> 0.1, r4 -> 1.0, r5 -> 0.3, 
   r6 -> 0.1};
l2 = {r1 -> 0.3, r2 -> 0.9, r3 -> 0.5, r4 -> 0.1, r5 -> 0.2, 
   r6 -> 0.2};
l3 = {r1 -> 0.4, r2 -> 0.1, r3 -> 0.2, r4 -> 0.2, r5 -> 0.7, 
   r6 -> 0.3};
l4 = {r1 -> 0.5, r2 -> 0.63, r3 -> 0.4, r4 -> 0.4, r5 -> 0.5, 
   r6 -> 0.4};

lists = {l1, l2, l3, l4};
plots = Transpose[{r6 /. lists, # /. lists}] & /@ {r1, r2, r3, r4, r5};
ListLinePlot[plots]

enter image description here

$\endgroup$
2
  • $\begingroup$ Thanks, @Syed, could you explain here this step in words : Transpose[{r6 /. lists, # /. lists}] & /@ {r1, r2, r3, r4, r5} $\endgroup$
    – User101
    May 29, 2023 at 7:58
  • $\begingroup$ Remove the semicolon at the end to see what plots looks like. Here /@ is the Map command. So we create tuples for each of the point to be plotted in the list changing with respect to r6. $\endgroup$
    – Syed
    May 29, 2023 at 8:04
6
$\begingroup$

You can also construct a TemporalData object from l:

l = Values @ {l1, l2, l3, l4};

td = TemporalData[Most /@ l, {Last /@ l},
   "MetaInformation" ->
    {"ComponentNames" -> {"col 1", "col 2", "col 3", "col 4", "col 5"}}];

ListLinePlot[td, PlotLegends -> td[ "ComponentNames"]]

enter image description here

$\endgroup$
4
$\begingroup$
l = Values @ {l1, l2, l3, l4};

ListLinePlot[Transpose @ Map[Thread @ {Last @ #, Most @ #} &] @ l, 
 PlotLegends -> Range[Length @ l]]

enter image description here

$\endgroup$
3
$\begingroup$

Do not use numbered variable names because it is not easy to use them. Better, put the data in an array like e.g.:

l0 = {r1, r2, r3, r4, r5, r6};
l=Table[{},4];
l[[1]] = 
  l0 /. {r1 -> 0.1, r2 -> 0.3, r3 -> 0.1, r4 -> 1.0, r5 -> 0.3, r6 -> 0.1};
l[[2]] = 
  l0 /. {r1 -> 0.3, r2 -> 0.9, r3 -> 0.5, r4 -> 0.1, r5 -> 0.2, r6 -> 0.2};
l[[3]] = 
  l0 /. {r1 -> 0.4, r2 -> 0.1, r3 -> 0.2, r4 -> 0.2, r5 -> 0.7, r6 -> 0.3};
l[[4]] = 
  l0 /. {r1 -> 0.5, r2 -> 0.63, r3 -> 0.4, r4 -> 0.4, r5 -> 0.5, r6 -> 0.4};

Then you can easily assemble the data for a ListPlot:

d = Table[{l[[j, 6]], l[[j, i]]}, {i, 5}, {j, 4}]
ListLinePlot[d]

enter image description here

$\endgroup$
2
  • $\begingroup$ Thanks, @Daniel Huber. When I run your code, it says: Set: Symbol l in part assignment does not have an immediate value. $\endgroup$
    – User101
    May 29, 2023 at 7:42
  • $\begingroup$ You are right, I forget to pre-assign l. I fixed it. $\endgroup$ May 29, 2023 at 7:55

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.