![如何创建带有注释的轴?](https://linux22.com/image/395273/%E5%A6%82%E4%BD%95%E5%88%9B%E5%BB%BA%E5%B8%A6%E6%9C%89%E6%B3%A8%E9%87%8A%E7%9A%84%E8%BD%B4%EF%BC%9F.png)
答案1
以下是包含简单\put
命令的启动器:
\documentclass{article}
\unitlength=1cm
\begin{document}
\begin{picture}(6,3)(-0.5,-1.5)
\put(0,0){\vector(1,0){5}}\put(5.1,-0.2){$x$}
\multiput(0,0)(1,0){5}{\line(0,1){0.3}}
\put(-0.2,-0.3){\tabular[t]{c}a\\b\\c\endtabular}
\put(0.75,-0.3){\tabular[t]{c}d\\e\\f\endtabular}
\put(1.8,-0.3){\tabular[t]{c}g\\h\\i\endtabular}
\put(2.8,-0.3){\tabular[t]{c}j\\k\\l\endtabular}
\put(3.7,-0.3){\tabular[t]{c}m\\n\\o\endtabular}
\end{picture}
\end{document}
答案2
使用 Ti钾Z 可能是最好的方法。这是针对您的请求的示例解决方案。我确实注释掉了代码以使其更容易理解。
\documentclass[tikz]{standalone}
\begin{document}
\begin{tikzpicture}
% Horizontal line
\draw[->] (0,0) -- (4.5,0)node[xshift = 0.25cm]{$x$};
\def\ourInfo{{
{"a", "d", "g", "j", "m"}, % Row 0
{"b", "e", "h", "k", "n"}, % Row 1
{"c", "f", "i", "l", "o"} % Row 2
}}
% getting information from the 2D array
\foreach \i in {0,...,2}{%rows
\foreach \j in {0, ..., 4}{%columns
% The \pgfmathparse gets what is inside the cell at (i,j).
% \pgfmathresult will output the result obtained previously.
\draw[] (\j,-0.5-\i/2)node[]{\pgfmathparse{\ourInfo[\i][\j]}\pgfmathresult};
}
}
% Taking care of the numbers above the horizontal line.
\foreach \i in {0, ..., 4}{
\draw(\i,0) -- (\i,0.25)node[yshift = 0.25cm]{\i};
}
% Define a 1D array and use a foreach loop to place what it has.
\def\innerData{{"", "abc", "xyz", "uvw"}}
\foreach \i in {0, ..., 3}{
\draw(\i+0.5,0) node[yshift = 0.5cm]{\pgfmathparse{\innerData[\i]}\small\pgfmathresult};
}
\end{tikzpicture}
\end{document}
答案3
我推荐 Ti钾Z 因为它可以改变外观的各个方面(箭头、线宽、线条样式、颜色、不透明度),并且具有\foreach
有助于避免重复的循环,并可与所有标准编译器一起使用。
\documentclass[tikz,border=3.14mm]{standalone}
\newcounter{pft}
\begin{document}
\begin{tikzpicture}
\draw[-stealth] (0,0) -- (5,0);
\draw foreach \X in {0,...,4} {(\X,0) -- ++ (0,0.2) node[above]{\X} };
\foreach \X in {0,...,14}
{\stepcounter{pft}
\node at ({int(\X/3)},{-0.45*(1+mod(\X,3))}) {\alph{pft}};}
\foreach \X [count=\Z] in {abc,xyz,uvw}
{\node[text depth=0.5ex] at (1.5+\Z,0.45){\X};}
\end{tikzpicture}
\end{document}