简体   繁体   English

如何使用 gnuplot 绘制带有标签的 plot 历史图

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

I have two small datafiles我有两个小数据文件

one

11  365.4
12  659.2

and one和一个

11  432.1
12  882.4

I try to plot those as a histogram with labels我尝试将 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                                                                                                         

But the labels are way off但是标签离我们很远

Image showing plot图片显示 plot

// GH // 生长激素

The histogram plotting style is implicitly using the pseudocolumn 0 (check help pseudocolumns ) as x-coordinate.直方图绘图样式隐含地使用伪列 0(检查help pseudocolumns列)作为 x 坐标。 So, you have to place your label at column(0) or ($0) with some x-offset, eg ($0-0.15) in the one and other direction.因此,您必须将 label 放置在column(0)($0)处,并在一个方向和另一个方向上进行一些 x 偏移,例如($0-0.15) And some offset in y-direction, eg via offset 0,0.7 .以及 y 方向的一些偏移量,例如通过offset 0,0.7

Script:脚本:

### 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

Result:结果:

在此处输入图像描述

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM