我的问题是有没有办法在gnuplot中制作horizontal直方图? 以下是直方图的组成数据集:
sample M N O P Q R S T Total
A 39.17 8.33 11.07 8.57 22.20 22.93 1.47 1.13 114.87
B 61.68 15.53 16.23 15.55 35.68 36.35 2.32 2.23 185.58
C 30.20 7.35 7.55 7.48 16.90 17.50 1.18 1.10 89.25
D 12.57 5.18 4.98 5.77 9.88 8.18 0.67 0.83 48.07
E 36.80 9.00 11.07 9.43 21.43 22.63 0.93 1.03 112.33
F 62.05 15.57 15.95 15.70 35.68 36.63 2.27 2.47 186.32
G 30.23 7.33 7.55 7.48 17.10 17.68 1.10 1.25 89.70
H 12.97 4.87 5.22 5.18 10.37 7.90 0.98 0.70 48.18
I 17.67 12.80 9.40 5.67 32.47 18.53 1.13 0.63 98.30
J 72.30 13.70 17.43 15.43 30.62 38.43 2.25 2.43 192.60
K 25.70 7.58 12.45 4.60 19.30 18.88 1.10 0.80 90.40
L 16.15 3.80 3.53 10.43 7.27 8.80 0.88 1.10 51.97
我调整了here的代码来绘制直方图:
set terminal png font "Times-Roman,9"
set output 'sample.png'
set border 3 front linetype -1 linewidth 1.000
set boxwidth 0.85 absolute
set style fill solid 1.00 border lt -1
set grid nopolar
set grid noxtics nomxtics ytics nomytics noztics nomztics \
nox2tics nomx2tics noy2tics nomy2tics nocbtics nomcbtics
set grid layerdefault linetype 0 linewidth 1.000, linetype 0 linewidth 1.000
set key outside right top vertical Left reverse noenhanced autotitles columnhead nobox
set key invert samplen 4 spacing 1 width 0 height 0
set style histogram rowstacked title offset character 0, 0, 0
set datafile missing '-'
set style data histograms
#set style histogram gap 1
set xtics border in scale 0,0 nomirror rotate by -45 offset character 0, 0, 0 autojustify
set xtics norangelimit font ",8"
set xtics ()
#set noytics
set ylabel "% of total"
set yrange [ 0 : 100 ] #noreverse nowriteback
plot 'sample.txt' using (100.*$2/$10):xtic(1) t column(2), for [i=3:9] '' using (100.*column(i)/column(10)) title column(i)
这给了我:
gnuplot中是否有办法让它横向移动?
答案 0 :(得分:1)
这是一个很老的问题,但仍然没有答案。
正如@Christoph所建议的那样,绘图样式boxxyerror
是一种解决方法。
但是,到目前为止,我还没有看到示例代码,例如在gnuplot演示页面上。
据我所知,gnuplot 5.2.8和5.4可能仍然没有绘图样式的水平堆叠直方图(如果我错了,请纠正我)。
实际上,不需要列“总计”,因为gnuplot可以自动进行总计。
代码:(gnuplot> = 5.2)
### horizontal stacked histogram
reset session
$Data <<EOD
sample M N O P Q R S T Total
A 39.17 8.33 11.07 8.57 22.20 22.93 1.47 1.13 114.87
B 61.68 15.53 16.23 15.55 35.68 36.35 2.32 2.23 185.58
C 30.20 7.35 7.55 7.48 16.90 17.50 1.18 1.10 89.25
D 12.57 5.18 4.98 5.77 9.88 8.18 0.67 0.83 48.07
E 36.80 9.00 11.07 9.43 21.43 22.63 0.93 1.03 112.33
F 62.05 15.57 15.95 15.70 35.68 36.63 2.27 2.47 186.32
G 30.23 7.33 7.55 7.48 17.10 17.68 1.10 1.25 89.70
H 12.97 4.87 5.22 5.18 10.37 7.90 0.98 0.70 48.18
I 17.67 12.80 9.40 5.67 32.47 18.53 1.13 0.63 98.30
J 72.30 13.70 17.43 15.43 30.62 38.43 2.25 2.43 192.60
K 25.70 7.58 12.45 4.60 19.30 18.88 1.10 0.80 90.40
L 16.15 3.80 3.53 10.43 7.27 8.80 0.88 1.10 51.97
EOD
set xlabel "% of total"
set xrange [0:103]
set yrange [:] reverse
set offsets 0,0,0.5,0.5
set style fill solid 1.0
set key out
ColCount = 8
myBoxwidth = 0.8
plot for [col=2:ColCount+1] $Data u col:0: \
(total=(sum [i=2:ColCount+1] column(i)),(sum [i=2:col-1] column(i)/total*100)): \
((sum [i=2:col] column(i))/total*100): \
($0-myBoxwidth/2.):($0+myBoxwidth/2.):ytic(1) w boxxyerror ti columnhead(col)
### end of code
结果:
代码:(gnuplot 4.6的版本,OP提出问题的时间)。结果与上面类似,文件Data.dat
中的数据)
### horizontal stacked histogram, version for gnuplot 4.6
reset
FILE = "Data.dat"
set xlabel "% of total"
set xrange [0:103]
set yrange [:] reverse
set offsets 0,0,0.5,0.5
set style fill solid 1.0
set key out
ColCount = 8
myBoxwidth = 0.8
plot for [col=2:ColCount+1] FILE u col:0: \
(total=(sum [i=2:ColCount+1] column(i)),(sum [i=2:col-1] column(i)/total*100)): \
((sum [i=2:col] column(i))/total*100): \
($0-myBoxwidth/2.):($0+myBoxwidth/2.):ytic(1) w boxxyerror ti columnhead(col)
### end of code