如何在gnuplot上的直方图条顶部显示y标签
我在gnuplot中设计了一个柱状图,但是由于值之间的巨大差异,y刻度需要在log2中。因此,为了提高绘图的可读性,我假装在每个条的顶部显示具体的值。这些值表示字节,因此我希望这些值也在log2中,并格式化为显示kb、Mb、。。。正如在y轴上所做的那样。 我怎样才能做到这一点 这是我当前使用的命令:如何在gnuplot上的直方图条顶部显示y标签,gnuplot,Gnuplot,我在gnuplot中设计了一个柱状图,但是由于值之间的巨大差异,y刻度需要在log2中。因此,为了提高绘图的可读性,我假装在每个条的顶部显示具体的值。这些值表示字节,因此我希望这些值也在log2中,并格式化为显示kb、Mb、。。。正如在y轴上所做的那样。 我怎样才能做到这一点 这是我当前使用的命令: set terminal postscript eps enhanced dash color "" 13 reset set datafile separator "," set title "
set terminal postscript eps enhanced dash color "" 13
reset
set datafile separator ","
set title "Bytes per Protocol"
set xlabel "Protocol"
set ylabel "Bytes" rotate by 90
set yrange [0:1342177280]
set logscale y 2
set format y '%.0s%cB'
set style data histogram
set boxwidth 0.5
set style fill solid
set xtics format ""
set grid ytics
set style data histogram
set style histogram clustered gap 2
set grid ytics
set tic scale 0
set size 1,0.9
set size ratio 0.5
set key autotitle columnhead
set output "ex_a_1_BIG.eps"
plot "ex_a_1_BIG.csv" using ($3):xtic(1) title "IN", \
'' using ($5):xtic(1) title "OUT", \
'' using 0:($3):($3) with labels center offset -2,1 notitle, \
'' using 0:($5):($5) with labels center offset 2,1 notitle
这是我要打印的csv的内容(我只需要输入和输出字节):
检查
帮助格式\u说明符和帮助gprintf
。下面是一个例子
有点不幸的是,在gnuplot中,1到999的前缀显然是单个空格,而不是空字符串。
例如,使用'%.1s%cB'
格式,这将导致1-999 B
的两个空格和其他空格,例如1 kB
。但是,如果您使用'%.1s%cB'
这将导致1-999 B有一个空间
而其他空间没有空间,例如100kB
。据我所知,正确答案是数字和单位之间有一个空格。我不确定是否有一个简单的解决办法
代码:
### prefixes
reset session
$Data <<EOD
1 1
2 12
3 123
4 1234
5 12345
6 123456
7 1234567
8 12345678
9 123456789
10 1234567890
11 12345678901
12 123456789012
13 1234567890123
EOD
set boxwidth 0.7
set style fill solid 1.0
set xtics 1
set yrange [0.5:8e13]
set multiplot layout 2,1
set logscale y # base of 10
set format y '%.0s %cB'
plot $Data u 1:2 w boxes lc rgb "green" notitle, \
'' u 1:2:(gprintf('%.1s %cB',$2)) w labels offset 0,1 not
set logscale y 2 # base of 2
set format y '%.0b %BB'
plot $Data u 1:2 w boxes lc rgb "red" notitle, \
'' u 1:2:(gprintf('%.1b %BB',$2)) w labels offset 0,1 not
unset multiplot
### end of code
但是对于ytics标签,我仍然没有主意。检查帮助格式\u说明符
和帮助gprintf
。下面是一个例子
有点不幸的是,在gnuplot中,1到999的前缀显然是单个空格,而不是空字符串。
例如,使用'%.1s%cB'
格式,这将导致1-999 B
的两个空格和其他空格,例如1 kB
。但是,如果您使用'%.1s%cB'
这将导致1-999 B有一个空间
而其他空间没有空间,例如100kB
。据我所知,正确答案是数字和单位之间有一个空格。我不确定是否有一个简单的解决办法
代码:
### prefixes
reset session
$Data <<EOD
1 1
2 12
3 123
4 1234
5 12345
6 123456
7 1234567
8 12345678
9 123456789
10 1234567890
11 12345678901
12 123456789012
13 1234567890123
EOD
set boxwidth 0.7
set style fill solid 1.0
set xtics 1
set yrange [0.5:8e13]
set multiplot layout 2,1
set logscale y # base of 10
set format y '%.0s %cB'
plot $Data u 1:2 w boxes lc rgb "green" notitle, \
'' u 1:2:(gprintf('%.1s %cB',$2)) w labels offset 0,1 not
set logscale y 2 # base of 2
set format y '%.0b %BB'
plot $Data u 1:2 w boxes lc rgb "red" notitle, \
'' u 1:2:(gprintf('%.1b %BB',$2)) w labels offset 0,1 not
unset multiplot
### end of code
但对于ytics标签,我仍然没有一个想法
myFmt(c) = column(c)>=1 && column(c)<1000 ? \
gprintf('%.1s%cB',column(c)) : gprintf('%.1s %cB',column(c))
plot $Data u 1:2 w boxes lc rgb "green" notitle, \
'' u 1:2:(myFmt(2)) w labels offset 0,1 not