使用不同的标签进行Foreach

使用不同的标签进行Foreach

有没有简单的方法来显示我的坐标系?

    \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。

在此处输入图片描述

相关内容