【发布时间】:2012-11-09 22:25:24
【问题描述】:
我想在 gnuplot 的直方图中添加一条水平线,可以吗?
我的直方图在 x 轴上有: alea1 alea 2 alea3 nalea1 nalea 2 nalea 3 y 轴从 0 到 25。
在 22 处,我想添加一条水平线,从直方图的一端一直延伸到另一端。
【问题讨论】:
我想在 gnuplot 的直方图中添加一条水平线,可以吗?
我的直方图在 x 轴上有: alea1 alea 2 alea3 nalea1 nalea 2 nalea 3 y 轴从 0 到 25。
在 22 处,我想添加一条水平线,从直方图的一端一直延伸到另一端。
【问题讨论】:
尝试添加
, 22 title ""
在你的 plot 命令结束时。适用于我的测试数据(文件“histo”):
# Year Red Green Blue
1990 33 45 18
1991 35 42 19
1992 34 44 14
1993 37 43 25
1994 47 15 30
1995 41 14 32
1996 42 20 35
1997 39 21 31
plot "histo" u 2 t "Red" w histograms, "" u 3 t "Green" w histograms, "" u 4 t "Blue" w histograms, 22 title ""
(取自 Philip K. Janert,Gnuplot in Action)
【讨论】:
notitle 比 title "" 干净一些
添加水平线和/或垂直线的典型方法是使用arrow
set arrow from x1,y1 to x2,y2 nohead linestyle ...
对于水平线,y1 和 y2 将相同。根据您的问题,我有点不确定您所说的“22 岁”是什么意思,但我猜您的意思是您想在直方图顶部绘制线 y=22。如果是这种情况,请尝试此操作(在您的 plot 命令之前)。
set arrow from graph 0,first 22 to graph 1,first 22 nohead lc rgb "#000000" front
【讨论】:
set label "some text" at ...,...。但是,您也可以使用其他答案来做到这一点:plot <histogram_stuff>, 22 w lines title "some text" 将其实际放入情节键中。