2012-08-27 15 views
2

我已經導入的CSV文件與此語句列表:如何在使用Mathematicia和ListPlot時在列表中指定x軸?

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-情節以紅色繪製,第二個以藍色繪製,第三個以綠色繪製。

+0

謝謝。有什麼方法可以繪製一條線而不是點? – John

回答

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 -> {[email protected], 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 -> {[email protected], Automatic}] 
+1

這是我遇到的實際問題,在另一篇文章http://stackoverflow.com/questions/12151575/how-to-plot-2-lines-and-spcify-that-the-first-column-in-list -is-the-x-axis我使用Excel來修改x軸中使用的值。原帖是在http://stackoverflow.com/questions/12144428/how-to-specify-x-axis-in-list-when-using-mathematicia-and-listplot我想我沒有正確地問問題。非常感謝您的文章,正是我所需要的。 – John

+0

是的,他們似乎是非常類似的問題。 –

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

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[[email protected]{#, {##2}} & @@@ [email protected]], 
PlotStyle -> {Red, Blue, Green} 
] 

Mathematica graphics

相關問題