![使用不同的标签进行Foreach](https://linux22.com/image/459403/%E4%BD%BF%E7%94%A8%E4%B8%8D%E5%90%8C%E7%9A%84%E6%A0%87%E7%AD%BE%E8%BF%9B%E8%A1%8CForeach.png)
有没有简单的方法来显示我的坐标系?
\begin{tikzpicture}
\draw [-latex,thick] (0,0)--(12.5,0);
\draw [-latex,thick] (0,0)--(0,10.5);
\foreach \y in{2,4,...,10}
\draw (0,\y) node [left] {\y};
\draw (1,0) node [below] {5};
\draw (2,0) node [below] {10};
\draw (3,0) node [below] {15};
\draw (4,0) node [below] {20};
\draw (5,0) node [below] {25};
\draw (6,0) node [below] {30};
\draw (7,0) node [below] {35};
\draw (8,0) node [below] {40};
\draw (9,0) node [below] {45};
\draw (10,0) node [below] {50};
\draw (11,0) node [below] {55};
\draw (12,0) node [below] {60};
\draw (0,0) node [below left] {0};
\draw [help lines] (0,0) grid (12,10);
\end{tikzpicture}
答案1
下面是使用的解决方案\foreach
。
此外,我发现您的图表中有两个不同的比例。在这种情况下,使用xscale
(或yscale
如果需要)很有用,这样您就可以使用所需的实际 x 值而不是绝对几何 x 值。xscale
设置为最大绝对几何 x 坐标(12)与最大实际 x 坐标(60)之间的比率,以便xscale = 12/60 = 0.2
。
\documentclass[border=5pt]{standalone}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}[
xscale=0.2,>=latex,
help lines/.style={black!50,ystep=1,xstep=5}]
\draw[help lines] (0,0) grid (60,10);
\draw[<->] (0,10.5) |- (62.5,0);
\foreach \x in {5,10,...,60} \node [below] at (\x,0) {\x};
\foreach \y in {2,4,...,10} \node [left] at (0,\y) {\y};
\node [below left] at (0,0) {0};
\end{tikzpicture}
\end{document}
如果您想在此图中进行大量绘图,请考虑使用该pgfplots
包而不是纯 TikZ。