2
$\begingroup$

I am trying to plot a list of two sublists, each of length 5 to produce two curves:

aaa = {{0, 1, 2, 3, 4}, {5, 6, 7, 8, 9}};
imax = 5;

I tried two ways to no avail. These are:

MapThread[ListPlot[Transpose[{i, {i, 1, imax}, #}]]][
  aaa[[j]], {j, 1, imax}];

MapThread[ListPlot[Transpose[{i, {i, 1, imax}, aaa[[#]]}]]][j, {j, 1, 
  imax}]

Both attempts were ruled erroneous. Your help would be appreciated.

Edit

A short version of the list looks like the following:

{{552.792, 6.28145, 1.51948, 0.905935, 0.725876, 0.422672, 0.443358,
0.270075, 0.304024, 0.195848, 0.222525, 0.1511, 0.169572, 0.1206,
0.13256, 0.098111, 0.105207, 0.0805748, 0.0840317},{0.0662868, 0.0669424, 0.0541982, 0.0525879, 0.0436082, 0.0400327,
0.0340136, 0.0285805, 0.0250322, 0.0176771, 0.0163611, 0.0069072,
0.00756966, 0.00458268, 0.0144777, 2.00194, 3.82806, 7.9682, 24.8342}}

The goal is to produce two curves with these two sublists as the ordinate values of these two curves.

For the abscissa, it is a simple, equal spaced sequence, specifically,

{0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1., 1.1, 1.2, 1.3, 1.4,
1.5, 1.6, 1.7, 1.8, 1.9}

I hope this clarifies the problem.

$\endgroup$
8
  • $\begingroup$ does this give what you are trying to get: ListLinePlot[Transpose[{Range[imax], #}] & /@ aaa, PlotMarkers -> Automatic]? $\endgroup$
    – kglr
    Sep 13, 2020 at 22:27
  • 2
    $\begingroup$ If what kglr suggests gives you what you want then you may also be interested in ListLinePlot[aaa]. $\endgroup$
    – C. E.
    Sep 13, 2020 at 22:29
  • 1
    $\begingroup$ or, simply, ListLinePlot[aaa, PlotMarkers -> Automatic, PlotRange -> {{1, 5}, All}] $\endgroup$
    – kglr
    Sep 13, 2020 at 22:31
  • $\begingroup$ These various applications of ListLinePlot did not work. Perhaps, I made the wrong impression by suggesting the aaa represents two straight line. The List aaa is meant to be two sublists of arbitrary numbers, not necessarily straight lines. $\endgroup$
    – Z Ming Ma
    Sep 14, 2020 at 0:13
  • 2
    $\begingroup$ ListPlot[{{0, 1, 4, 9, 16}, {1, 1/2, 1/3, 1/4, 1/5}}, Joined -> True, Mesh -> All] $\endgroup$
    – cvgmt
    Sep 14, 2020 at 0:50

4 Answers 4

1
$\begingroup$

Using ListLogPlot might be more meaningful here.

data = {{552.792, 6.28145, 1.51948, 0.905935, 0.725876, 0.422672, 
        0.443358, 0.270075, 0.304024, 0.195848, 0.222525, 0.1511, 
        0.169572, 0.1206, 0.13256, 0.098111, 0.105207, 0.0805748, 
        0.0840317}, {0.0662868, 0.0669424, 0.0541982, 0.0525879, 
        0.0436082, 0.0400327, 0.0340136, 0.0285805, 0.0250322, 0.0176771, 
        0.0163611, 0.0069072, 0.00756966, 0.00458268, 0.0144777, 2.00194, 
        3.82806, 7.9682, 24.8342}};

ListLogPlot[Transpose[{Range[0.1, 1.9, 0.1], #}] & /@ data, PlotRange -> All, Joined -> True]

enter image description here

$\endgroup$
1
$\begingroup$
aaa = {{552.792, 6.28145, 1.51948, 0.905935, 0.725876, 0.422672, 
    0.443358, 0.270075, 0.304024, 0.195848, 0.222525, 0.1511, 
    0.169572, 0.1206, 0.13256, 0.098111, 0.105207, 0.0805748, 0.0840317}, 
   {0.0662868, 0.0669424, 0.0541982, 0.0525879, 
    0.0436082, 0.0400327, 0.0340136, 0.0285805, 0.0250322, 0.0176771, 
    0.0163611, 0.0069072, 0.00756966, 0.00458268, 0.0144777, 2.00194, 
    3.82806, 7.9682, 24.8342}};

1. You can use the option DataRange -> {.1, 1.9}:

ListLinePlot[aaa, DataRange -> {.1, 1.9}, 
 PlotMarkers -> Automatic, ClippingStyle -> False]

enter image description here

You can add the option PlotRange -> All to get

enter image description here

Better yet, add the option ScalingFunctions -> {None, "Log"} (or use ListLogPlot instead of ListLinePlot as suggested by Okkes) :

ListLinePlot[aaa, DataRange -> {.1, 1.9}, 
   ScalingFunctions -> {None, "Log"}, PlotMarkers -> Automatic]

enter image description here

2. Use MapIndexed to add the x coordinates:

ListLinePlot[MapIndexed[{#2[[1]]/10, #} &] /@ aaa, 
    PlotMarkers -> Automatic, ClippingStyle -> False]

enter image description here

3. Create a list of x coordinates and combine it with aaa using Transpose ( or Thread):

xxx = Range[Length[aaa[[1]]]] / 10;

ListLinePlot[Transpose[{xxx, #}] & /@ aaa, PlotMarkers -> Automatic, 
 ClippingStyle -> False]

enter image description here

$\endgroup$
1
$\begingroup$

Your showing example data was very helpful. Thank you

Try

aaa={{552.792, 6.28145, 1.51948, 0.905935, 0.725876, 0.422672, 0.443358,0.270075, 0.304024,
0.195848,0.222525, 0.1511, 0.169572, 0.1206,0.13256, 0.098111, 0.105207, 0.0805748, 0.0840317},
{0.0662868, 0.0669424, 0.0541982, 0.0525879, 0.0436082, 0.0400327,0.0340136, 0.0285805, 0.0250322,
0.0176771, 0.0163611, 0.0069072,0.00756966, 0.00458268, 0.0144777, 2.00194, 3.82806, 7.9682, 24.8342}};
abscissa=Range[1/10,19/10,1/10];(* use exact rationals to ensure correct number of entries*)
Show[
  ListPlot[Transpose[{abscissa,aaa[[1]]}],Joined->True],
  ListPlot[Transpose[{abscissa,aaa[[2]]}],Joined->True]]

or

ListPlot[{Transpose[{abscissa,aaa[[1]]}],Transpose[{abscissa,aaa[[2]]}]},Joined->True]

or

ListLinePlot[{Transpose[{abscissa,aaa[[1]]}],Transpose[{abscissa,aaa[[2]]}]}]

or, since you asked to use Map

ListPlot[Map[Transpose[{abscissa,#}]&,aaa],Joined->True]

or

ListLinePlot[Map[Transpose[{abscissa,#}]&,aaa]]

Please test this carefully to make certain I have made no mistakes.

$\endgroup$
1
$\begingroup$
xvals = Range[0.1, 1.9, 0.1];
yvals = {{552.792, 6.28145, 1.51948, 0.905935, 0.725876, 0.422672, 
   0.443358, 0.270075, 0.304024, 0.195848, 0.222525, 0.1511, 0.169572,
    0.1206, 0.13256, 0.098111, 0.105207, 0.0805748, 
   0.0840317}, {0.0662868, 0.0669424, 0.0541982, 0.0525879, 0.0436082,
    0.0400327, 0.0340136, 0.0285805, 0.0250322, 0.0176771, 0.0163611, 
   0.0069072, 0.00756966, 0.00458268, 0.0144777, 2.00194, 3.82806, 
   7.9682, 24.8342}};

Any of the following can be used, the most familiar being the last one:

data = Thread[{xvals, #}] & /@ yvals
data2 = MapThread[List, {xvals, #}] & /@ yvals
data3 = Transpose[{xvals, #}] & /@ yvals 

{{{0.1, 552.792}, {0.2, 6.28145}, {0.3, 1.51948}, {0.4, 0.905935}, {0.5, 0.725876}, {0.6, 0.422672}, {0.7, 0.443358}, {0.8, 0.270075}, {0.9, 0.304024}, {1., 0.195848}, {1.1, 0.222525}, {1.2, 0.1511}, {1.3, 0.169572}, {1.4, 0.1206}, {1.5, 0.13256}, {1.6, 0.098111}, {1.7, 0.105207}, {1.8, 0.0805748}, {1.9, 0.0840317}}, {{0.1, 0.0662868}, {0.2, 0.0669424}, {0.3, 0.0541982}, {0.4, 0.0525879}, {0.5, 0.0436082}, {0.6, 0.0400327}, {0.7, 0.0340136}, {0.8, 0.0285805}, {0.9, 0.0250322}, {1., 0.0176771}, {1.1, 0.0163611}, {1.2, 0.0069072}, {1.3, 0.00756966}, {1.4, 0.00458268}, {1.5, 0.0144777}, {1.6, 2.00194}, {1.7, 3.82806}, {1.8, 7.9682}, {1.9, 24.8342}}}

ListLinePlot[data, ScalingFunctions -> {None, "Log"}, Mesh -> All]

enter image description here

$\endgroup$

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.