聚类堆积直方图的每个类别和每个条的标签

时间:2014-08-06 19:27:49

标签: plot gnuplot histogram stacked

下面是创建聚簇堆叠直方图的gnuplot代码。

set terminal postscript eps enhanced 14
set datafile separator ";"
set output 'stacked_boxes.eps'
set auto x
set yrange [0:30]
set xtics 1
set style fill solid border -1
num_of_categories=2
set boxwidth 0.3/num_of_categories
dx=0.2
offset=-0.1
ddx=0.2
set key off
plot 'data.explorer0.csv' using ($1+offset):($3+$4) title "explorer0(sync)" linecolor rgb "#cc0000" with boxes, \
     ''                   using ($1+offset):3 title "explorer0(wait)" linecolor rgb "#ff0000" with boxes, \
     'data.explorer1.csv' using ($1+offset+dx):($3+$4) title "explorer1(sync)" linecolor rgb "#cc0000" with boxes, \
     ''                   using ($1+offset+dx):3 title "explorer1(wait" linecolor rgb "#ff0000" with boxes, \
     'data.collector0.csv' using ($1+dx+ddx):($3+$4) title "collector0(post)" linecolor rgb "#00cc00" with boxes, \
     ''                   using ($1+dx+ddx):3 title "collector0(poll)" linecolor rgb "#00ff00" with boxes, \
     'data.collector1.csv' using ($1+dx+ddx+dx):($3+$4)  linecolor rgb "#00cc00" with boxes, \
     ''                   using ($1+dx+ddx+dx):3 notitle linecolor rgb "#00ff00" with boxes here

如何为每个栏和每个类别创建标签?四个酒吧一起成为一个类别。设类别为(c0,c1,c2),每类别的条形为(e0,e1,c0,c1)。

可以使用以下数据文件重现该图:

data.explorer0.csv:

#level;explorerid;sync;wait;etc
"0";"e0";"2";"2"
"2";"e0";"4";"4"
"4";"e0";"6";"6"

data.explorer1.csv:

#level;explorerid;sync;wait;etc
"0";"e1";"7";"5"
"2";"e1";"6";"10"
"4";"e1";"5";"5"

data.collector0.csv:

#level;collectorid;sync;wait;etc
"0";"c0";"2";"2"
"2";"c0";"4";"4"
"4";"c0";"6";"6"

data.collector1.csv:

#level;collectorid;sync;wait;etc
"0";"c1";"5";"5"
"2";"c1";"8";"10"
"4";"c1";"9";"5"

stacked clustered plot

1 个答案:

答案 0 :(得分:1)

我找到了您的脚本的来源:Gnuplot Histogram Cluster (Bar Chart) with One Line per Category :)我曾考虑过在该答案中提及的solution 2之类的解决方案,但这并不适用于红色和绿色相互叠加,加上堆叠数据。

您发布的脚本只需要很少的修改。为了将第二列中包含的标签作为xticklabels,您可以使用xtic语句中的using函数。

类别标签只能与set labels一起明确放置。标签的x坐标以第一个x轴为单位给出,y值以字符为单位的绝对值给出。此外,您需要手动增加底部边距以为类别标签腾出空间,这不会在自动边距计算中计算。这是通过set bmargin 3完成的,它将底部边距设置为三个字符高度。

这是修改过的脚本

set terminal postscript eps enhanced 14
set datafile separator ";"
set output 'stacked_boxes.eps'
set auto x
set yrange [0:30]
set xtics 1 nomirror
set style fill solid border -1
num_of_categories=2
set boxwidth 0.3/num_of_categories
dx=0.2
offset=-0.1
ddx=0.2
set key off

set bmargin 3
set label center "cat0" at first 0+offset/2+dx+ddx/2, char 1
set label center "cat1" at first 2+offset/2+dx+ddx/2, char 1
set label center "cat2" at first 4+offset/2+dx+ddx/2, char 1

plot 'data.explorer0.csv' using ($1+offset):($3+$4):xtic(2) title "explorer0(sync)" linecolor rgb "#cc0000" with boxes, \
     ''                   using ($1+offset):3 title "explorer0(wait)" linecolor rgb "#ff0000" with boxes, \
     'data.explorer1.csv' using ($1+offset+dx):($3+$4):xtic(2) title "explorer1(sync)" linecolor rgb "#cc0000" with boxes, \
     ''                   using ($1+offset+dx):3 title "explorer1(wait" linecolor rgb "#ff0000" with boxes, \
     'data.collector0.csv' using ($1+dx+ddx):($3+$4):xtic(2) title "collector0(post)" linecolor rgb "#00cc00" with boxes, \
     ''                   using ($1+dx+ddx):3 title "collector0(poll)" linecolor rgb "#00ff00" with boxes, \
     'data.collector1.csv' using ($1+dx+ddx+dx):($3+$4):xtic(2)  linecolor rgb "#00cc00" with boxes, \
     ''                   using ($1+dx+ddx+dx):3 notitle linecolor rgb "#00ff00" with boxes

及其输出使用gnuplot 4.6.5:

enter image description here