GnuPlot:在Boxes中间写一些文字

时间:2017-05-12 22:46:27

标签: plot gnuplot

我正试图在Boxes of the plot(绘制通过gnu情节)的中间写,但找不到一些优雅的方式。手动找到所有盒子的中间点是很繁琐的。请指导我搞清楚。 Here at the position of circles, I want to add some text, vertically

1 个答案:

答案 0 :(得分:1)

正如@Christoph在评论中提到的,plot ... w labels是其中一个选项。唯一的额外成分"包括计算标签的位置。例如,可以举例如下:

set terminal pngcairo
set output 'fig.png'

fName='test.dat'

bw = 0.9

yMin = 50
yMax = 130

xMin = 2
xMax = 15

set boxwidth bw

set xr [xMin - bw/2:xMax + bw/2]
set yr [yMin:yMax]

#scale 0 makes sure that the tic marks don't "show up"
set format x "1 %.0f"
set xtics 2,1,15 rotate by -15 scale 0

set ytics 50,10,130 scale 0

set ylabel "TODO"
set xlabel "TODO"

set key top right

#place the labels in the "middle" with respect to the
#minimum on the y-axis
p \
    100 t "Todo" lc rgb "black" dt 3, \
    fName u 1:2 w boxes t "TODO" lc rgb "black", \
    fName u 1:(($2-yMin)/2+yMin):(sprintf("%.0f", $2)) w labels t '' tc rgb 'dark-red'

这会产生: enter image description here

假设数据文件test.dat为:

2  100
3  75
4  74
5  76
6  74
7  78
8  92
9  98
10  75
11  105
12  118
13  120
14  122
15  122