如何绘制带有断开的 x 轴和字符串标签的直方图?
How to draw a histogram with broken x-axis and string labels?
我正在尝试绘制 x 轴断开的直方图。我从这个post中学到了基本的解决方案。
但是,我的直方图的 x 轴基于字符串,而不是数字。是这样的:
set terminal pdf
set output "test-bar.pdf"
set boxwidth 1.0 absolute
set style fill solid 1 border 0
set datafile separator ','
set style data histograms
set xtics nomirror rotate by -45
set ylabel 'Normalized Overhead (%)'
set grid ytics
set yrange [0:10]
plot 'test-bar.csv' using 2:xtic(1) lc rgb "#1E90FF" title ''
数据是这样列出的:
expand , 8.63390441828
cut , 6.84657194596
sync , 6.03615235627
fold , 4.22117995557
nl , 3.54228486647
truncate , 2.66222961714
tr , 2.38357169059
stty , 2.28166797757
users , 2.04211869831
factor , 1.81517270821
tac , 1.790947574
uniq , 1.78799489138
mv , 1.75054704603
mktemp , 1.72228202368
dircolors , 1.6974169738
现在剧情是这样的:
如果我想利用 broken axis
功能,例如,在 stty
和 users
之间插入断线,我该怎么做?
我够清楚了吗?谢谢。
虽然您使用数据文件中的 xtic 标签,但 xtics 位于整数 x 值处,从 0
开始。现在,您不能在绘制直方图时直接设置任意 x 值。您必须使用 newhistogram at ...
将直方图的第二部分进一步向右移动:
split = 8
plot 'test-bar.csv' using 2:xtic(1) every ::0::(split-1) lt 1,\
newhistogram at split+1,\
'' using 2:xtic(1) every ::split lt 1
上边界和下边界以及断轴符号的绘制如您链接的 post 所示完成。一个可能的完整脚本可以是
set terminal pdf
set output "test-bar.pdf"
set boxwidth 0.5 absolute
set style fill solid 1 border 0
set datafile separator ','
set style data histograms
set style histogram rowstacked
set xtics nomirror rotate by -45
set ylabel 'Normalized Overhead (%)'
set grid ytics
set yrange [0:10]
unset key
set border 2+8
set linetype 1 lc rgb "#1E90FF"
split=8
dx = 0.125
dy = 0.03
do for [i=0:1] {
set arrow 1+i from graph 0,graph i to first split-dx,graph i lt -1 nohead
set arrow 3+i from first split+dx,graph i to graph 1,graph i lt -1 nohead
set arrow 5+i from first split-2*dx,graph i-dy to first split,graph i+dy lt -1 nohead
set arrow 7+i from first split,graph i-dy to split+2*dx,graph i+dy lt -1 nohead
}
plot 'test-bar.csv' using 2:xtic(1) every ::0::(split-1) lt 1,\
newhistogram at split+1,\
'' using 2:xtic(1) every ::split lt 1
或者,如果您不添加或堆叠更多列,您可以使用 boxes
绘图样式,它允许您使用正常的数值轴。
我正在尝试绘制 x 轴断开的直方图。我从这个post中学到了基本的解决方案。
但是,我的直方图的 x 轴基于字符串,而不是数字。是这样的:
set terminal pdf
set output "test-bar.pdf"
set boxwidth 1.0 absolute
set style fill solid 1 border 0
set datafile separator ','
set style data histograms
set xtics nomirror rotate by -45
set ylabel 'Normalized Overhead (%)'
set grid ytics
set yrange [0:10]
plot 'test-bar.csv' using 2:xtic(1) lc rgb "#1E90FF" title ''
数据是这样列出的:
expand , 8.63390441828
cut , 6.84657194596
sync , 6.03615235627
fold , 4.22117995557
nl , 3.54228486647
truncate , 2.66222961714
tr , 2.38357169059
stty , 2.28166797757
users , 2.04211869831
factor , 1.81517270821
tac , 1.790947574
uniq , 1.78799489138
mv , 1.75054704603
mktemp , 1.72228202368
dircolors , 1.6974169738
现在剧情是这样的:
如果我想利用 broken axis
功能,例如,在 stty
和 users
之间插入断线,我该怎么做?
我够清楚了吗?谢谢。
虽然您使用数据文件中的 xtic 标签,但 xtics 位于整数 x 值处,从 0
开始。现在,您不能在绘制直方图时直接设置任意 x 值。您必须使用 newhistogram at ...
将直方图的第二部分进一步向右移动:
split = 8
plot 'test-bar.csv' using 2:xtic(1) every ::0::(split-1) lt 1,\
newhistogram at split+1,\
'' using 2:xtic(1) every ::split lt 1
上边界和下边界以及断轴符号的绘制如您链接的 post 所示完成。一个可能的完整脚本可以是
set terminal pdf
set output "test-bar.pdf"
set boxwidth 0.5 absolute
set style fill solid 1 border 0
set datafile separator ','
set style data histograms
set style histogram rowstacked
set xtics nomirror rotate by -45
set ylabel 'Normalized Overhead (%)'
set grid ytics
set yrange [0:10]
unset key
set border 2+8
set linetype 1 lc rgb "#1E90FF"
split=8
dx = 0.125
dy = 0.03
do for [i=0:1] {
set arrow 1+i from graph 0,graph i to first split-dx,graph i lt -1 nohead
set arrow 3+i from first split+dx,graph i to graph 1,graph i lt -1 nohead
set arrow 5+i from first split-2*dx,graph i-dy to first split,graph i+dy lt -1 nohead
set arrow 7+i from first split,graph i-dy to split+2*dx,graph i+dy lt -1 nohead
}
plot 'test-bar.csv' using 2:xtic(1) every ::0::(split-1) lt 1,\
newhistogram at split+1,\
'' using 2:xtic(1) every ::split lt 1
或者,如果您不添加或堆叠更多列,您可以使用 boxes
绘图样式,它允许您使用正常的数值轴。