0

按照这个问题的答案:Histogram using gnuplot? 以及我创建此脚本的其他一些来源:

set terminal postscript eps enhanced color
set title "Histogram\_CreatesFile"

colour1="#00A0ff"
colour2="navy"
colour3="#ffA000"
colour4="#800000"
set output 'Histogram_CreatesFile.eps'
set yrange [0:]
set style fill solid 0.8 border -1
bin_width = 0.2
set boxwidth bin_width
bin_number(x) = floor(x/bin_width)
rounded(x) = bin_width * ( bin_number(x) + 0.5 )
plot 'Histogram_CreatesFile.txt' using (rounded($1)):(1) smooth frequency with boxes lc rgb colour1 notitle

我有一个测试数据文件:

0
0.2
0.4
0.41

一切都很漂亮,但我在第一个栏的左侧得到了一个奇怪的空白空间: 在此处输入图像描述

当我不知道先验数据文件中的值是什么时(即它可能从0以外的其他值开始),如何使图表从第一个条开始?

4

1 回答 1

2

在我看来,该stats命令可能会在这里帮助您。

set terminal postscript eps enhanced color
set title "Histogram\_CreatesFile"

colour1="#00A0ff"
colour2="navy"
colour3="#ffA000"
colour4="#800000"
set output 'Histogram_CreatesFile.eps'
set yrange [0:]
set style fill solid 0.8 border -1
bin_width = 0.2
set boxwidth bin_width
bin_number(x) = floor(x/bin_width)
rounded(x) = bin_width * ( bin_number(x) + 0.5 )

stats 'Histogram_CreatesFile.txt' using (rounded($1)) nooutput
set xrange [STATS_min-bin_width/2.:]

plot 'Histogram_CreatesFile.txt' using (rounded($1)):(1) smooth frequency with boxes lc rgb colour1 notitle

stats在 gnuplot4.6(?) 中添加。在此之前,我一直用于这些事情的技巧是绘制到虚拟终端并从特殊的只读变量中获取最小值GPVAL_X_MINstats虽然它更干净,更强大,但现在应该使用当前稳定版本是 4.6。

于 2013-05-17T13:35:10.403 回答