有人知道为什么在这幅图中刻度没有出现在轴下吗?
\newcommand{\myaxis}[1]{
\draw[->] (0,#1) -- (25,#1);
\foreach \x in {0,...,24} {
\draw (\x,#1)++(0,3pt) -- (\x,#1)++(0,-3pt) node[anchor=north] {$\x$};
}
}
\begin{tikzpicture}[x=5mm]
% By default, tikz uses centimeters (cm) as unit
\myaxis{1}
\foreach \x in {2,4,6,8,10,12,14,16,18,20,22,24} {
\draw[red,fill=red] (\x,1) circle (5pt);
}
\myaxis{0}
\foreach \x in {3,6,9,12,15,18,21,24} {
\draw[red,fill=red] (\x,0) circle (5pt);
}
\end{tikzpicture}
多谢。
答案1
你的意思是像下面图片那样:
或者
在这种情况下你应该更换
\newcommand{\myaxis}[1]{
\draw[->] (0,#1) -- (25,#1);
\foreach \x in {0,...,24} {
\draw (\x,#1)++(0,3pt) -- (\x,#1)++(0,-3pt) node[anchor=north] {$\x$};
}
}
和
\newcommand{\myaxis}[1]{
\draw[->] (0,#1) -- ++(25,0);
\foreach \x in {0,...,24} {
\draw (\x,#1) -- ++(0,-4pt) node[below] {$\x$};
}
}
或者
\newcommand{\myaxis}[1]{
\draw[->] (0,#1) -- ++(25,0);
\foreach \x in {0,...,24} {
\draw (\x,#1) ++(0,3pt) -- ++(0,-6pt) node[below] {$\x$};
}
}
Comand 的意思是,在和\draw (\x,#1)++(0,3pt) -- (\x,#1)++(0,-3pt) node[anchor=north] {$\x$};
之间绘制一条线。节点从 的轴进一步移动。完成第二种情况的 MWE:(\x,#1)++(0,3pt)
(\x,#1)
(0,-3pt)
\documentclass[tikz, border=3mm]{standalone}
\begin{document}
\newcommand{\myaxis}[1]{
\newcommand{\myaxis}[1]{
\draw[->] (0,#1) -- ++(25,0);
\foreach \x in {0,...,24} {
\draw (\x,#1) ++(0,3pt) -- ++(0,-6pt) node[below] {$\x$};}
}
\begin{tikzpicture}[x=5mm]
% By default, tikz uses centimeters (cm) as unit
\myaxis{1}
\foreach \x in {2,4,...,24} {
\draw[red,fill=red] (\x,1) circle (5pt);
}
\myaxis{0}
\foreach \x in {3,6,...,24} {
\draw[red,fill=red] (\x,0) circle (5pt);
}
\end{tikzpicture}
\end{document}