2014-02-24 53 views
1

這是很容易繪製X-Y數據點這樣gnuplot的,關於y軸和值文本圖表區

# X Y 
    1 2 
    2 4 
    4 1 
    ... 

與gnuplot的內部。

但是我想要繪製這樣

# Model  2010 2011 2012 2013 
    M1    10  15 
    M2   5 20 
    M3   10 10 20 

圖表對Y軸

^
    | 
M1|   10   15 
M2|  5 20 
M3|  10 10 20 
    +-----+-----+-----+-----+-----> 
     2010 2011 2012 2013 

文本我怎麼能做到這一點的數據點?

set xtics ("2010" 0, "2011" 1, "2012" 2, "2013" 3) 
set ytics ("M1" 0, "M2" 1, "M3" 2) 
plot 'data.txt' ?????? 
+0

是的,你可以設置這樣的抽動 - 你有沒有試過它,它不工作?請澄清。 – Schorsch

+0

我不知道我放在'plot'前面。這裏使用''的正確用法是什麼? – mahmood

回答

1

我的回答基於this suggestion how to mirror Matlab's spy function
但是,你必須重新格式化您的數據文件,看起來像這樣(保存爲data.dat):

NaN 10 NaN 15 
5 20 NaN NaN 
10 10 20 NaN 

這將有助於應繪製的元素(數字)和那些區分不應出現(NaN)。

這裏將產生你在你的問題勾勒情節代碼:

# the code will plot the numbers as labels: 
set style data labels 

# set up x- and y-coordinates based on the rows and columns 
xcoord(N) = (N) 
ycoord(N) = (column(0)+1) 

# define a symbol to be used as label: 
# every NaN will be empty (" "), 
# and everything not equal to NaN (ne), will be a string 
# of the actual element 
symbol(N) = strcol(N) ne "NaN" ? strcol(N) : " " 

# define the ranges, use reverse with the yrange 
set xrange [0:5] 
set yrange [0:4] reverse 

# set the tics (this is something you already had) 
set xtics ("2010" 1, "2011" 2, "2012" 3, "2013" 4) 
set ytics ("M1" 1, "M2" 2, "M3" 3) 

# the actual plot command 
# N will count through the number of columns 

plot for [N=1:4] 'data.dat' using (xcoord(N)):(ycoord(N)):(symbol(N)) w labels 

劇情,你會得到這個樣子的:

plot-demo

+0

是的,它完全有效。我已修改添加更多數據點,它是完美的。謝謝 – mahmood