我已完成以下操作:
\documentclass{article}
\usepackage{pgfplots}
\begin{document}
\begin{tikzpicture}
\begin{axis}
\addplot[smooth, domain=0:3] {1+sin(x+rand*10)};
\addplot[smooth, domain=3:6] {5-0.5*x+sin(x+rand*10)};
\addplot[smooth, domain=6:9] {2+sin(x+rand*10)};
\addplot[smooth, domain=0:3, dashed] {1};
\addplot[smooth, domain=3:9, dashed] {2};
\end{axis}
\end{tikzpicture}
\end{document}
问题是线条在点 (6,2) 处跳跃。有人能帮忙吗?
答案1
感谢@Jake,这是答案:
\documentclass{article}
\usepackage{pgfplots}
\usetikzlibrary{decorations.pathreplacing}
\begin{document}
\begin{tikzpicture}
\begin{axis}[axis line style = very thick, smooth, no markers,
axis lines= middle,
ylabel=Price,
xlabel=Time,
xmax=10, xmin=-1,
ymax=5, ymin=-1,
ytickmax=0,
xtickmax=0,
]
\addplot[smooth, domain=0:3, samples=20] {1+rand*0.3};
\addplot[smooth, domain=3:9, samples=40] {rand*0.3 + (x<6 ? 5-0.5*x : 2)};
\addplot[smooth, domain=0:3, dashed] {1};
\addplot[smooth, domain=3:9, dashed] {2};
\end{axis}
\node[draw] at (5,5) {Price Adjustment};
\node[draw] at (2.5,0) {Good News};
\draw[thick,->] (2.5, 0.5) -- (2.5, 1.5);
\draw[thick,->] (4.5,4.5) -- (4, 4);
\draw [blue,decorate,decoration={brace,amplitude=5pt},xshift=-4pt,yshift=0pt]
(2.7,4.5) -- (4.4,3.1) node [black,midway] {};
\end{tikzpicture}
\end{document}