【问题标题】:Draw two pointlines in a histogram (gnuplot)?在直方图中绘制两条点线(gnuplot)?
【发布时间】:2013-07-03 14:56:47
【问题描述】:

我想通过gnuplot在一个直方图中画两条点线,结果图不是我想要的。实际上,我希望两条点线(粉红色的和浅绿色的)中的点对齐两种类型的柱子的中心,所以浅绿色的保持静止,而粉红色的稍微向右移动,就像黑色的一样画好了。

“test.dat”如下:

1 10 15 8 22 2 11 19 7 21 3 9 14 7 19 4 10 21 8 23 5 9 17 9 21

和“plt”文件:

set style data histogram
unset key 
set yrange[0:12]
set y2range[0:25]

plot "test.dat" using 2:xticlabel(1) axis x1y1,\
"test.dat" using 3:xticlabel(1) axis x1y2 with linespoints,\
"test.dat" using 4:xticlabel(1) axis x1y1,\
"test.dat" using 5:xticlabel(1) axis x1y2 with linespoints

【问题讨论】:

    标签: gnuplot


    【解决方案1】:

    我的答案基于this contribution,它使用方框而不是直方图。好处是,您可以确切地知道这些框的放置位置,您可以将其用于线图。

    代码如下:

    dx=1.
    n=2.
    total_box_width_relative=0.25
    gap_width_relative=0.1
    d_width=(gap_width_relative+total_box_width_relative)*dx/n  
    set boxwidth total_box_width_relative/n relative  
    set style fill transparent solid 0.5 noborder
    
    plot "test.dat" u ($1):2 w boxes lc rgb"green" notitle,\    
         "test.dat" u ($1+d_width):4 w boxes lc rgb"red" notitle,\
         "test.dat" u ($1):3 w linespoints notitle,\              
         "test.dat" u ($1+d_width):5 w linespoints notitle        
    
    set yrange [0:15]
    replot
    

    对代码的一些解释:

    • dx 应根据您的数据文件选择,否则框的间距将关闭。
    • 框的数据集数量由n 给出
    • total_box_width_relativegap_width_relative 控制框的轴向间距和间距
    • 两个set ... 命令控制框的外观
    • 在绘图命令中,您现在必须分开:您使用原始第一列数据调用一组框和线:($1),但是,对于第二组框和相应的线,您选择定义的轴向偏移量:($1+d_width) - 这将确保线图中的数据点与框对齐
    • 可能需要包含set yrange 命令

    情节将如下所示:

    注意
    我根据您提供的数据更改了线图的数据。这样做只是为了使点更靠近框并说明效果。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-06-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多