Gnuplot 断轴无复图
我想在Y轴上绘制一个轴断开的柱状图。已经解释了一个很好的教程,但是它们不适合我的需要。数据点是Gnuplot 断轴无复图,gnuplot,Gnuplot,我想在Y轴上绘制一个轴断开的柱状图。已经解释了一个很好的教程,但是它们不适合我的需要。数据点是 "Method" "Year1" "Year2" M1 12 -40 M2 5 40 set ylabel "The Profit (%)" set style data histogram set style histogram cluster gap 1 # Draw a horizontal line at Y=0
"Method" "Year1" "Year2"
M1 12 -40
M2 5 40
set ylabel "The Profit (%)"
set style data histogram
set style histogram cluster gap 1
# Draw a horizontal line at Y=0
set arrow 1 from -1,0 to 2,0 nohead
plot 'test_data.txt' using 2:xtic(1) ti col lc rgb "black", '' u 3 ti col lc rgb "grey"
此数据点的代码段如下
"Method" "Year1" "Year2"
M1 12 -40
M2 5 40
set ylabel "The Profit (%)"
set style data histogram
set style histogram cluster gap 1
# Draw a horizontal line at Y=0
set arrow 1 from -1,0 to 2,0 nohead
plot 'test_data.txt' using 2:xtic(1) ti col lc rgb "black", '' u 3 ti col lc rgb "grey"
输出结果如下所示
如您所见,灰色条位于极值上。我想要的是将Y范围从-20限制到+20,并在第二个条上放置一个~
符号(将其旋转90度),然后放置一个标签-40和+40。像这样的数字
这是怎么可能的?你可以做到,但它非常乏味:
中的y值
标签
打印样式打印标签set ylabel "The Profit (%)"
set style histogram cluster gap 1
set boxwidth 0.9 relative
# Draw a horizontal line at Y=0
set xzeroaxis lt -1
ulim = 15
llim = -15
set yrange[-20:20]
sc = 0.333
set style fill solid noborder
plot 'test_data.txt' using ($2 > ulim ? ulim : ($2 < llim ? llim : $2)):xtic(1) ti col lc rgb "black" with histogram, \
'' u ($3 > ulim ? ulim : ($3 < llim ? llim : $3)) ti col lc rgb "grey" with histogram,\
for [c=2:3] '' u ($0-1+(c-2.5)*sc):(column(c) > ulim ? ulim : 1/0):(sprintf('+%d', ulim)) with labels offset 0, char 1.5 notitle,\
for [c=2:3] '' u ($0-1+(c-2.5)*sc):(column(c) < llim ? llim : 1/0):(sprintf('%d', llim)) with labels offset 0, char -1.5 notitle,\
for [c=2:3] for [ofs=0:1] '' u ($0-1+(c-2.5)*sc - 0.03 + ofs*0.02):\
(column(c) > ulim ? ulim - 1 : (column(c) < llim ? llim - 1 : 1/0)):(0.04):(2) with vectors lc rgb 'black' nohead notitle
set ylabel“利润(%)”
设置样式直方图簇间距1
将boxwidth设置为0.9相对
#在Y=0处绘制一条水平线
设置X轴lt-1
ulim=15
llim=-15
设置Y范围[-20:20]
sc=0.333
设置样式填充顺序
使用($2>ulim?ulim:($2ulim?ulim:($3ulim?ulim:1/0):(sprintf('+%d',ulim)),标签偏移量为0,字符1.5 notitle\
对于[c=2:3]“u($0-1+(c-2.5)*sc:(第(c)列ulim?ulim-1:(第(c)列
并根据4.6.3给出以下结果:
涉及的内容太多,无法解释一切,因此这里有一些重要的评论:
- 直方图框从0开始放置,并提供自定义标签。这对于标签和向量的放置非常重要(
)using语句中的$0-1
- 系数
是由on xtick的三列(第1年、第2年和sc=0.333
)得出的gap 1
- 该方法适用于第2列和第3列
- 脚本给出了一些警告,因为某些绘图是空的(第2列的值没有超过限制,因此相应的标签和向量绘图不包含点)
- 我认为用曲线来表示破损的盒子是不可行的
- 若你们的盒子有边框,它们也会出现在破损盒子的顶部,这可能是违反直觉的
- 使用
在set xzeroaxis
处绘制一条线,或使用y=0
图形坐标绘制一个箭头(
)将箭头从图形0设置为第一个0到图形1,第一个0为nohead
for
语句的含义吗?[c=2:3]的c
中的是什么?对不起,您确定脚本可以工作吗?当我粘贴它并运行时,我得到了预期的错误“test_plot.txt”,第20行:“)”
,它指向plot命令。我检查了(
和)
,它们很好。但是不知道为什么会抱怨抱歉,我在添加sc
变量时输入了一个错误。[c=2:3]
的首先用c=2
执行绘图命令,然后用c=3
执行绘图命令。如有必要,我将使用此选项裁剪两个框(第二列和第三列)。