如何在特定的 x 轴值范围内绘制 yline?

How to draw yline within specific range of x-axis values?

你能帮我确定在 1991 到 1995 的范围内绘制 yline(对应于值 21)然后在 1996 到 2000 的范围内绘制值为 10 的 yline 的方法吗?下面附上我目前拥有的代码:

serrbar mean error year , scale(2) addplot(line mean year) xscale(r(1995 2000)) title("xxx")  yaxis(1 
2) xtitle("Year",height(6)) ytitle("xx") legend(order( 1 "xx" 2 "xx"))  xline(1995, lcol(red)) 
yline(21,  lpatter(dash)) yline(10,  lpatter(dash)) xlabel(1991(1)2000)

你不能那样做,但你可以得到同样的效果。

您没有提供可重现的示例,所以这里有一个。

webuse assembly, clear
serrbar mean std date
serrbar mean std date , addplot(function first=180, ra(108 110) || function second=200, ra(113 116)) legend(order(1 2))