在Gnuplot中添加水平线条柱状图

13

我想在gnuplot的直方图中添加一条水平线,这是否可行?

我的直方图在x轴上有:alea1 alea2 alea3 nalea1 nalea2 nalea3,y轴从0到25。

在22处,我想添加一条水平线,从直方图的一端横跨到另一端。

2个回答

16

尝试添加

, 22 title ""

在您的绘图命令结尾处添加“Works for my test data (file "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》)

我花了一点时间才明白你在这里说什么。你可能想演示一个完整的绘图命令,以清楚地展示你的意思。 - mgilson
完成, @mgilson。我总觉得没有原始问题中的数据有点具有挑战性。 - vaettchen
2
notitle is somewhat cleaner than title "" - hertzsprung
好的,“22”可以工作。但是是否可能让这行从某个点“x”开始? - Philipp Ludwig
@Philipp Ludwig - 如果您需要更多选项,使用箭头可能是正确的方法。 - vaettchen

13

典型的添加水平和/或垂直线的方式是使用箭头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

1
谢谢你们两个。我已经用箭头完成了。是否可以为我添加一行文字,解释我的直方图中y=22的那条线的含义,就像一个图例一样? - Audrey Lee-Gosselin
2
@AudreyLee-Gosselin -- 当然可以。只需执行 set label "some text" at ...,... 即可。但是,您也可以使用其他答案执行以下操作:plot <histogram_stuff>, 22 w lines title "some text",以将其实际放置在绘图键中。 - mgilson

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接