我正在尝试对上面的图片进行编码。
这是我当前的代码,但它看起来不像预期的图形:
\begin{tikzpicture}
\draw[thick,->] (0,0) -- (8.5,0);
\draw[thick,->] (0,0) -- (0,4.5);
\draw[thick,-] (1,0) -- (1,1);
\draw[thick,-] (2,0) -- (2,1);
\draw[thick,-] (3,0) -- (3,1);
\draw[thick,-] (4,0) -- (4,1);
\draw[thick,-] (5,0) -- (5,1);
\draw[thick,-] (6,0) -- (6,1);
\draw[thick,-] (7,0) -- (7,1);
%\draw[thick,-] (4,0) -- (4,1);
\foreach \x in {0,1,2,3,4,5,6,7,8}
\draw (\x cm,1pt) -- (\x cm,-1pt) node[anchor=north] {$\x$};
\foreach \y in {0,1,2,3,4}
\draw (1pt,\y cm) -- (-1pt,\y cm) node[anchor=east] {$\y$};
\end{tikzpicture}
我怎样才能更改代码以获得所需的输出?
答案1
使用操作开始解决方案pic
:
\documentclass[tikz,border=10pt]{standalone}
\tikzset{sequence label/.store in=\seqlab,
sequence label={},
sequence/.pic={
\fill (0,0) circle[radius=2pt] node[below]{\seqlab};
\draw (-1,0)--++(0,1);
\draw (-0.6,0)--++(0,1);
\draw (1,0)--++(0,1);
\draw (0.6,0)--++(0,1);
\begin{scope}[font=\tiny,blue!50!cyan!80!black]
\node at (-0.8,0.8){BC};
\node at (0.8,0.8){BC};
\node at (0,0.8){Patch};
\end{scope}
\draw[stealth-stealth](-0.6,0.6)--(0.6,0.6)
node[below,midway,font=\tiny]{$\Delta X$};
\coordinate(-West) at (-1,0.6);
\coordinate(-East) at (1,0.6);
}
}
\begin{document}
\begin{tikzpicture}
\draw (0,-0.5)--++(0,3) (-0.5,0)--++(13,0);
\draw[sequence label=$X_i$] pic (A) at (1.5,0) {sequence};
\draw[sequence label=$X_{i+1}$] pic (B) at (6,0) {sequence};
\draw[sequence label=$X_{i+2}$] pic (C) at (10.5,0) {sequence};
% ARROWS in BETWEEN
\draw[stealth-stealth,blue!50!cyan!80!black](A-East)--(B-West)
node[above,midway,font=\tiny] {Gap}
node[below,midway,font=\tiny,text=black]{$\Delta X$};
\draw[stealth-stealth,blue!50!cyan!80!black](B-East)--(C-West)
node[above,midway,font=\tiny] {Gap}
node[below,midway,font=\tiny,text=black]{$\Delta X$};
\end{tikzpicture}
\end{document}
结果: