使用Mathematicia和ListPlot时如何在List中指定x轴?

时间:2012-08-27 14:53:56

标签: wolfram-mathematica

我已将csv文件导入到具有此stmt的列表中:

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

给出了:

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

我想创建一个图表,其中x轴基于第一个字段:

  

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

该图为每个后续字段创建一条线,因此第二个字段为:

  

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

这将是y轴上的第一行,其他y轴值将以相同的方式绘制。我希望第一个y-plot用红色绘制,第二个用蓝色绘制,第三个用绿色绘制。

3 个答案:

答案 0 :(得分:2)

另一个版本:

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

同样,但更容易阅读:

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}]

答案 1 :(得分:1)

你可以这样做:

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

答案 2 :(得分:0)

我建议:

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