How to specify x-axis in List when using Mathemati

2019-07-20 17:34发布

I have imported a csv file into a list with this stmt:

data1 = Take[Import["D:\\_reports\\optim_5_60_b_2.csv", "CSV"],   5]

Which gives:

{{178, 8, 9, 1}, {152, 2, 8, 1}, {378, 8, 9, 2},
 {343, 3, 7.5`, 2}, {143, 3, 7.5`, 1}}

I would like to create a plot where the x-axis is based on the first field:

178,152,378,343,143,373,743,352

And the plot creates a line for each subsequent field, so the 2nd field is:

8,2,8,3,3,3,3,2

This would be the first line on the y-axis, the other y-axis values would be plotted in the same manner. I would like the first y-plot to be plotted in red, and the second in blue, and the third in green.

3条回答
Lonely孤独者°
2楼-- · 2019-07-20 18:16

And an alternative version:

data = {{178, 8, 9, 1}, {152, 2, 8, 1}, {378, 8, 9, 2},
   {343, 3, 7.5, 2}, {143, 3, 7.5, 1}};

x = data[[All, 1]];

ListLinePlot[
 Transpose[
  Sort[MapThread[Function[xpt, {xpt, #} & /@ #2][#1] &,
    {x, Rest /@ data}]]], PlotStyle -> {Red, Blue, Green},
 PlotMarkers -> {Automatic, 10}, AxesOrigin -> {Min@x, Automatic}]

enter image description here

Similarly, but easier to read:

ListLinePlot[
 Transpose[
  Sort[Table[Map[{data[[i, 1]], #} &, Rest[data[[i]]]],
    {i, Length[data]}]]], PlotStyle -> {Red, Blue, Green},
 PlotMarkers -> {Automatic, 10}, AxesOrigin -> {Min@x, Automatic}]
查看更多
兄弟一词,经得起流年.
3楼-- · 2019-07-20 18:18

You can do :

data1 = {{178, 8, 9, 1}, {152, 2, 8, 1}, {378, 8, 9, 2}, {343, 3, 7.5,
2}, {143, 3, 7.5, 1}};

tobeplotted =  With[{LocalX = data1[[All, 1]]}, 
   Transpose[{LocalX, #}] & /@ Transpose[data1[[All, 2 ;;]]]]

ListPlot[tobeplotted, PlotStyle -> {Red, Blue, Green},  PlotMarkers -> {Automatic, 10}]

plot

查看更多
爷、活的狠高调
4楼-- · 2019-07-20 18:33

I propose this:

dat = {{178, 8, 9, 1}, {152, 2, 8, 1}, {378, 8, 9, 2},
       {343, 3, 7.5`, 2}, {143, 3, 7.5`, 1}};

ListLinePlot[
 Thread[Thread@{#, {##2}} & @@@ Sort@dat],
 PlotStyle -> {Red, Blue, Green}
]

Mathematica graphics

查看更多
登录 后发表回答