答案1
一个简单的foreach
就可以做到:
\documentclass[tikz,border=2mm]{standalone}
\begin{document}
\begin{tikzpicture}
\draw[->] (0,-1)--++(90:4);
\draw[->] (-1,0)--++(0:12);
\coordinate (aux) at (0,0);
\foreach \i in {1,-1,1,1,1,-1,1,-1,-1,1,-1}
\draw[->] (aux)--++(1,\i) coordinate (aux);
\end{tikzpicture}
\end{document}
答案2
差不多就可以了(虽然没有轴):
\documentclass[tikz,border=5]{standalone}
\usetikzlibrary{decorations.pathreplacing}
\tikzset{arrow path/.style={decoration={show path construction,
lineto code={
\path [->, every lineto/.try]
(\tikzinputsegmentfirst) -- (\tikzinputsegmentlast);
}}, decorate},
every lineto/.style={draw, thick, ->},
lineto/.style={every lineto/.append style={#1}},
ballot sequence/.style={arrow path, .. ballot sequence=#1@@;},
.. ballot sequence/.code args={#1#2#3;}{%
\if#1@\else
\if#1-
\tikzset{symbol #1#2/.try, .. ballot sequence=#3;}%
\else
\tikzset{symbol #1/.try, .. ballot sequence=#2#3;}%
\fi\fi%
},
symbol -1/.style={insert path={ -- ++(1,-1) }},
symbol 1/.style={insert path={ -- ++(1,1) }}
}
\begin{document}
\begin{tikzpicture}[>=stealth]
\path [lineto=red] (5,0) [ballot sequence={1-1}];
\path [lineto=green] (3,3) [ballot sequence={111-1-1-1}];
\path [lineto=blue] (0,6) [ballot sequence={1-1111-11-1-11-1-1}];
\end{tikzpicture}
\end{document}