2017-04-18 52 views
2

我有以下data.dat文件集群条形图

A B C D E 
1 24 24 1 5.06326e-05 
1 12 12 2 9.82645e-05 
1 6 6 4 0.000178653 
1 3 3 8 0.000326006 
2 48 24 1 2.92298e-05 
2 24 12 2 6.06926e-05 
2 12 6 4 0.000102249 
2 6 3 8 0.000184589 

,我想生成使用E列数据和对AD列数据的群集柱状图。 A是群集编号,D为每个群集重复。我设法去接近最终的解决方案,我用

p "data.dat" u 5:key(1) 

获得 enter image description here

不过虽然数据是正确的,集群没有得到很好的后可见。有没有一种方法可以在不改变数据格式的情况下使用集群来绘制这个图?

回答

1

我会说这也取决于你想处理的一般输入。在该列D始终包含的2每个簇连续功率的情况下,人们可能会倾向于与boxes绘图样式手动构造的框:

set terminal pngcairo enhanced 
set output 'fig.png' 

#if your data file contains the header line with A, B, C, D, E 
set key autotitle columnhead 

set boxwidth 0.5 
set style fill solid 

f=6 
w=0.5 

unset key 
set style fill empty 

unset xtics 
set ytics out nomirror 

set format y '%.2f' 
set label at graph 0,1 "{/Symbol \264}10^{3}" offset character 0.75,-1 
plot \ 
    'data.dat' u ($1*f*w + log($4)/log(2)*w):($5/1e-3) w boxes lc rgb 'dark-red', \ 
    '' u ($1*f*w + log($4)/log(2)*w):(0):4 w labels offset 0, char 1 

这里,变量w指定与一个基本的期望框。每个方框的位置计算为整个集群的偏移量$1*f*w加上特定方框log($4)/log(2)*w的偏移量。如果栏D包含数字1,2,4,8等,则log($4)/log(2)给出该框在对应群集内的“位置”。结果是: enter image description here

或者,另一个假设可能是每个簇具有相同数量的框G。然后脚本可能看起来像:

set terminal pngcairo enhanced 
set output 'fig.png' 

#if your data file contains the header line with A, B, C, D, E 
set key autotitle columnhead 

set boxwidth 0.5 
set style fill solid 

f=6 
w=0.5 
G=4 

unset key 
set style fill empty 

unset xtics 
set ytics out nomirror 

set format y '%.2f' 
set label at graph 0,1 "{/Symbol \264}10^{3}" offset character 0.75,-1 
plot \ 
    'data.dat' u (int($0/G)*f*w + (int($0)%G)*w):($5/1e-3) w boxes lc rgb 'dark-red', \ 
    '' u (int($0/G)*f*w + (int($0)%G)*w):(0):4 w labels offset 0, char 1 

的簇号为int($0/G)使用特殊的列数0(给在输入数据文件中的从零开始的行数)来计算。以类似的方式,int($0)%G产生其集群内特定框的位置。