2008-11-29 147 views

回答

23
 
plot "data.dat" using 2: xtic(1) with histogram 

這裏data.dat文件包含表單

 
title 1 
title2 3 
"long title" 5 
95

簡單條形圖:

bar graph

set boxwidth 0.5 
set style fill solid 
plot "data.dat" using 1:3:xtic(2) with boxes 

data.dat文件:

0 label  100 
1 label2  450 
2 "bar label" 75 

如果您希望以不同風格你吧,你可以這樣做:

multi color bar graph

set style line 1 lc rgb "red" 
set style line 2 lc rgb "blue" 

set style fill solid 
set boxwidth 0.5 

plot "data.dat" every ::0::0 using 1:3:xtic(2) with boxes ls 1, \ 
    "data.dat" every ::1::2 using 1:3:xtic(2) with boxes ls 2 

如果你想爲每個條目做多的酒吧:

data.dat文件:

0  5 
0.5 6 


1.5 3 
2  7 


3  8 
3.5 1 

gnuplot的:

set xtics ("label" 0.25, "label2" 1.75, "bar label" 3.25,) 

set boxwidth 0.5 
set style fill solid 

plot 'data.dat' every 2 using 1:2 with boxes ls 1,\ 
    'data.dat' every 2::1 using 1:2 with boxes ls 2 

barchart_multi

如果你想成爲非常棘手,並使用一些巧妙的gnuplot的招數:

的Gnuplot有僞列可以作爲指標的顏色:

plot 'data.dat' using 1:2:0 with boxes lc variable 

barchart_multi2

此外,你可以使用一個功能來選擇你想要的顏色:

mycolor(x) = ((x*11244898) + 2851770) 
plot 'data.dat' using 1:2:(mycolor($0)) with boxes lc rgb variable 

barchart_multi3

注意:您必須添加一些其他基本命令才能獲得與示例圖像相同的效果。

+0

對於許多應用程序,使用「直方圖」繪圖樣式更加方便,特別是對於分組和堆棧值。 – Christoph 2015-02-01 14:18:18

8

我只想擴展最重要的答案,它使用GNUPlot爲絕對初學者創建條形圖,因爲我閱讀了答案,並且仍然從語法洪水中感到困惑。

我們從編寫GNUplot命令的文本文件開始。讓我們把它叫做commands.txt中:

一組項PNG

組輸出 「graph.png」

集boxwidth 0。5

集樣式填固體

情節 「data.dat文件」 使用1:3:xtic(2)與盒

「設置術語PNG」 將GNUPLOT設置爲輸出PNG文件和「set output」graph.png「」是要輸出到的文件的名稱。

接下來的兩行很自我解釋。第五行包含很多語法。

情節 「data.dat文件」 使用1:3:xtic(2)與盒

「data.dat文件」 是我們正在操作的數據文件。 「1:3」表示我們將data.dat的第1列用於x座標,data.dat的第3列用於y座標。 xtic()是一個負責編號/標記x軸的函數。因此,xtic(2)表示我們將使用data.dat的第2列作爲標籤。

「data.dat文件」 看起來像這樣:

0標籤100

1 LABEL2 450

2 「欄中標記」 75

要繪製的曲線圖,在終端中輸入「gnuplot commands.txt」。