1

I have the following example:

x = {1, 2, 3, 4}
y = {{1, 2, 3, 4}, {2, 3, 4, 5}, {3, 4, 5, 6}, {4, 5, 6, 7}}

Now I can plot:

ListPlot[{Transpose[{x, y[[1]]}], Transpose[{x, y[[2]]}], 
  Transpose[{x, y[[3]]}], Transpose[{x, y[[4]]}]}]

enter image description here

How can this be simplified?

mrz
  • 11,686
  • 2
  • 25
  • 81

1 Answers1

2

If you want to simplify generating the input these are simpler ways:

x = Range[4];
y = Partition[ Range[7], 4, 1];

then you can use Inner:

z = Inner[List, x, y, List];

and finally

ListPlot[z] 

Instead of playing with Partition and Range you can generate the input of ListPlot with Table:

z = Table[{i, i + k - 1}, {k, 4}, {i, 4}];

or even better with Array:

z = Array[{#2, #2 + #1 - 1} &, {4, 4}]

The simplest approach would make use of the Front - end shorthands for Transpose (esc tr esc) (see e.g. Add a vector to a list of vectors) and Map (/@) e.g.

enter image description here

Artes
  • 57,212
  • 12
  • 157
  • 245