gnuplot x直方图中的标签位置

时间:2014-04-04 15:53:30

标签: gnuplot histogram

我有以下数据:

t_4 24 3 0 0
t_6 37 4 0 0
t_8 51 4 2 0 

t_4 15 1 0 0
t_6 21 0 0 1
t_8 30 0 0 1

t_4 13 2 1 0
t_6 20 3 1 0
t_8 22 4 1 0

我尝试使用此修改版本的代码制作类似于此http://www.bmsc.washington.edu/people/merritt/gnuplot/stack+cluster.dem的直方图:

set style data histogram
set style histogram rowstacked
set style fill solid
set boxwidth 0.5
set key invert samplen 0.2
set key samplen 0.2
set bmargin 3
set offset 0,2,0,0

set title "number of multiple resonances"

plot newhistogram "1:j" lt 1, \
     'stack+cluster.dat' index 0 u 2:xtic(1) title "one", \
     '' index 0 u 3 title "two", \
     '' index 0 u 4 title "three", \
     '' index 0 u 5 title "four"

     newhistogram "2:j" lt 1, \
     'stack+cluster.dat' index 1 u 2:xtic(1) notitle, \
     '' index 1 u 3 notitle, \
     '' index 1 u 4 notitle, \
     '' index 1 u 5 notitle

      newhistogram "3:j" lt 1, \
     'stack+cluster.dat' index 1 u 2:xtic(1) notitle, \
     '' index 1 u 3 notitle, \
     '' index 1 u 4 notitle, \
     '' index 1 u 5 notitle

但这是我找到enter image description here

的输出

正如您所看到的问题出现在x标签名称newhistogram "1:j""2:j""3:j"中:我只能看到“1:j”并与“t_4”重叠。“

有人可以帮助我吗?

2 个答案:

答案 0 :(得分:6)

该脚本出错!所有命令必须属于单个plot命令。如您所知,脚本在第二个newhistogram之前终止。

接下来,您需要使用两个空白行分隔两个块,以便使用index参数对其进行处理(为此,请参阅数据文件中的注释) http://www.bmsc.washington.edu/people/merritt/gnuplot/stack+cluster.dat属于你所谈到的例子。)

通过这些更正,您可以获得以下脚本(另请注意title offset):

set style data histogram
set style histogram rowstacked title offset 0,-1
set style fill solid
set boxwidth 0.5
set key invert samplen 0.2
set key samplen 0.2
set bmargin 3
set offset 0,2,0,0

set title "number of multiple resonances"

plot newhistogram "1:j" lt 1, \
     'stack+cluster.dat' index 0 u 2:xtic(1) title "one", \
     '' index 0 u 3 title "two", \
     '' index 0 u 4 title "three", \
     '' index 0 u 5 title "four",\
     newhistogram "2:j" lt 1, \
     'stack+cluster.dat' index 1 u 2:xtic(1) notitle, \
     '' index 1 u 3 notitle, \
     '' index 1 u 4 notitle, \
     '' index 1 u 5 notitle,\
      newhistogram "3:j" lt 1, \
     'stack+cluster.dat' index 1 u 2:xtic(1) notitle, \
     '' index 2 u 3 notitle, \
     '' index 2 u 4 notitle, \
     '' index 2 u 5 notitle

结果(用4.6.5):

enter image description here

答案 1 :(得分:-2)

#cat subset1.csv
"subset1","close","43","20"
"subset1","open","53","40"
"subset1","partial","44","28"

#cat subset2.csv
"subset2","close","24","31",
"subset2","open","47","35",
"subset2","partial","44","28",

gnuplot的

set datafile separator "," 
set style data histogram
set style histogram rowstack gap 1
set style fill solid border -1
set boxwidth 0.5 relative

set xtics rotate by 45 offset -0.8,-4.3
set xlabel  offset 0, -2 
set bmargin 8

plot \
newhistogram "subset1" lt 1,\     
'subset1.csv' using 3:xticlabels(2) title "internal" linecolor rgb     "gray",\   
'subset1.csv' using 4:xticlabels(2) title "external" linecolor rgb    "white",\  
newhistogram "subset2" lt 1,\
'subset2.csv' using 3:xticlabels(2) title "" linecolor rgb "gray",\
'subset2.csv' using 4:xticlabels(2) title "" linecolor rgb "white"


#The bellow command is the same as the above but in one line one to avoid (\n) problems
# plot newhistogram "subset1" lt 1, 'subset1.csv' using 3:xticlabels(2)     title "internal" linecolor rgb "gray", 'subset1.csv' using 4:xticlabels(2)  title "external" linecolor rgb "white", newhistogram "subset2" lt 1, 'subset2.csv' using 3:xticlabels(2) title "" linecolor rgb "gray", 'subset2.csv' using 4:xticlabels(2) title "" linecolor rgb "white"

gnuplot output http://oi61.tinypic.com/nyxoh.jpg