簡體   English   中英

如何使用 gnuplot 繪制帶有標簽的 plot 歷史圖

[英]How to use gnuplot to plot history graph with labels

我有兩個小數據文件

11  365.4
12  659.2

和一個

11  432.1
12  882.4

我嘗試將 plot 那些作為帶有標簽的直方圖

gnuplot <<EOF                                                                                               
                                                                                                            
set output 'house-energy.png'                                                                               
set terminal png size 800,400 font "Arial,10"                                                               
                                                                                                            
                                                                                                            
set boxwidth 0.7 relative                                                                                   
set grid ytics linestyle 0                                                                                  
set style fill solid 0.20 border                                                                            
                                                                                                            
set style data histogram                                                                                    
#set style histogram columnstacked                                                                          
#set style histogram rowstacked                                                                             
                                                                                                            
set title "Energy"                                                                                          
set xlabel "Month"                                                                                          
set ylabel "kWh"                                                                                            
set yrange [0:2000]                                                                                         
                                                                                                            
plot 'file1.dat' u 2: xtic(1) with histogram lc rgb "#0045FF" title "Energy house total", \     
     '' using 1:(\$2):(\$2) with labels notitle font ",10" , \                                              
     'file2.dat' u 2: xtic(1) with histogram lc rgb "#004500" title "Labb", \                          
     '' using 1:(\$2):(\$2) with labels notitle  font ",10"                                                 
                                                                                                            
EOF                                                                                                         

但是標簽離我們很遠

圖片顯示 plot

// 生長激素

直方圖繪圖樣式隱含地使用偽列 0(檢查help pseudocolumns列)作為 x 坐標。 因此,您必須將 label 放置在column(0)($0)處,並在一個方向和另一個方向上進行一些 x 偏移,例如($0-0.15) 以及 y 方向的一些偏移量,例如通過offset 0,0.7

腳本:

### histogram with labels
reset session

$Data1 <<EOD
11  365.4
12  659.2
EOD

$Data2 <<EOD
11  432.1
12  882.4
EOD

set boxwidth 0.7 relative
set grid ytics linestyle 0
set style fill solid 0.20 border

set style data histogram
set title "Energy"
set xlabel "Month"
set ylabel "kWh"
set yrange [0:2000]
set key noautotitle

plot $Data1 u 2:xtic(1)     w histogram lc rgb "#0045FF" title "Energy house total", \
         '' u ($0-0.15):2:2 w labels font ",10" offset 0,0.7, \
     $Data2 u 2             w histogram lc rgb "#004500" title "Labb", \
         '' u ($0+0.15):2:2 w labels font ",10" offset 0,0.7
### end of script

結果:

在此處輸入圖像描述

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM