# How to map functions twice?

I would like to plot multiple lists. The table looks like

a={{1,2,3,0,0,0,0,0,0},{1,2,3,0,0,1,0,0,0},{1,2,3,0,0,0,2,0,0},...,{1,2,3,0,0,0,0,3,0}}


I want to plot the elements from 4 to end with index*step as x-axis. For the first line

ListPlot[{# step,a[[1,#]]}& /@ Range[4, Length[a[[1]]]


If I would like to plot all the rows in the same plot, looks I have to change the a[[1,#]] to a[[#2,#]] and map again with Range[Length[a]]

How could I do that?

• I assume your list of data is a. I think you're trying to do ListPlot[a[All,4;;]]? Apr 4, 2017 at 14:15
• ... or ListPlot[Drop[a, None, 3]]. Apr 4, 2017 at 14:16
• Thanks above two comments. Actually, I have to change the question a little bit, the x-axis is not index. It is index times a constant. That is why I use map here. Any ideas? Apr 4, 2017 at 14:22
• Add DataRange -> step {4, Length[a[[1]]]} to evanb's comment Apr 4, 2017 at 14:25

The easiest way is to use the evanb's comment above and just add the option for DataRange:

ListPlot[a[[;;, 4 ;;]], DataRange -> step {4, Length[First@a]}]


This will plot your data without an explicit x coordinate, but you specify the x-axis range with DataRange. If you really need to generate a list of pairs of coordinates, you can do this:

ListPlot[Thread[{step Range[4, Length[First@a]], #[[4 ;;]]}] & /@ a]


For step=20:

Here's how I would do it using combination of MapThread and Map.

a = {{1, 2, 3, 0, 0, 0, 0, 0, 0}, {1, 2, 3, 0, 0, 1, 0, 0, 0}, {1, 2,
3, 0, 0, 2, 0, 0, 0}, {1, 2, 3, 0, 0, 0, 0, 0, 1}};


Assuming step is say 0.1, we will generate list of x-co-ordinates

    step = 0.1;
xlist = step*Range[4, Length[a[[1]]]];


Now using MapThread and Map, we can generate pairs.

pairs = Flatten[MapThread[{#1, #2} &, {xlist, #[[4 ;;]]}] & /@ a, 1]


This will generate output

{{0.4, 0}, {0.5, 0}, {0.6, 0}, {0.7, 0}, {0.8, 0}, {0.9, 0}, {0.4,
0}, {0.5, 0}, {0.6, 1}, {0.7, 0}, {0.8, 0}, {0.9, 0}, {0.4,
0}, {0.5, 0}, {0.6, 2}, {0.7, 0}, {0.8, 0}, {0.9, 0}, {0.4,
0}, {0.5, 0}, {0.6, 0}, {0.7, 0}, {0.8, 0}, {0.9, 1}}


which you can use as input to ListPlot

ListPlot[pairs, PlotStyle -> Directive[PointSize[Large]]]


Hope this is helpful. One advantage of MapThread is it could be easily generalized to include more lists (say if you want to plot points in 3D).