我的文件第 6 列中有蛋白质分子量数据。有问题的列如下所示:
MW [kDa]
16.8214045562515
101.41770820613989
24.332255496943485
43.946599899844436
210.58276787970942
57.987597263605494
27.384315650885558
119.02857910337919
8.962938979036466
我想绘制一个直方图,我使用 Gnuplot 的平滑频率函数来完成它:
echo n=20 >$gnuplot #number of intervals
echo max=100 >> $gnuplot #max value
echo min=-0 >> $gnuplot #min value
echo width=\(max-min\)\/n >> $gnuplot #interval width
echo hist\(x,width\)=width*floor\(x\/width\)+width\/2.0 >> $gnuplot
echo plot \"$dataFile\" using \(hist\(\$6,width\)\)\:\(1.0\) smooth freq w boxes lc rgb\"blue\" notitle >> $gnuplot
如何在每个直方图条形顶部添加代表每个 bin 计数的数据标签?我似乎找不到办法做到这一点。
我首先将直方图数据绘制到表格中,然后使用该表格绘制直方图本身和标签。
检查以下示例。如果您有一个文件,例如'myData.dat'
,跳过随机数据生成行,而是添加行FILE = 'myData.dat'
并替换所有$Data
with FILE
。正如@Eldrad 在评论中提到的,使用绘图风格with labels
对于标签。查看help labels
and help table
.
Code:
### histogram with labeled bins
reset session
# create some random test data
set print $Data
do for [i=1:2000] {
print sprintf("%g",(invnorm(rand(0))+10)*20)
}
set print
stats $Data u 1 nooutput
xmin = STATS_min
xmax = STATS_max
N = 20
myWidth = (xmax-xmin)/N
bin(col) = myWidth*floor(column(col)/myWidth)+myWidth/2.
set key noautotitle
set style fill solid 0.3
set boxwidth myWidth
set grid x,y
set offsets graph 0,0,0.05,0 # l,r,t,b
set table $Histo
plot $Data u (bin(1)) smooth freq
unset table
plot $Histo u 1:2 w boxes lc rgb "blue", \
'' u 1:2:2 w labels offset 0,0.7
### end of code
Result:
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)