gnuplot - 如何将数据标签添加到 Gnuplot 直方图(平滑频率)?
问题描述
我的文件第 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
为FILE
. 正如评论中提到的@Eldrad,使用with labels
标签的绘图样式。检查help labels
和help table
。
代码:
### 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
结果:
推荐阅读
- javascript - 作为参数发送的变量更改父函数中的值
- r - 删除重复 id 和条件的子集
- google-cloud-platform - GCP 与 Terraform 的集成
- javascript - 为什么 Background 0 会使 P5.JS 中的文本消失?
- scheme - R7RS-small:quasiquoted 表达式的等价性
- android - Flutter ssh2 2.2.3 包构建错误(ssh2:compileDebugJavaWithJavac)
- python - 如何编写类似 django orm 的模块?
- python - 从/向 HDFS 读取/写入数据
- python - 在Python中获取除此行以外的组中的平均值
- python - IndexError: 使用 pandas 将单个 excel 行导出到 JSON 文件时,索引 1 超出轴 0 的范围,大小为 1