绘制数值射线

绘制数值射线

在此处输入图片描述

也许我搜索错了,但我找不到用垂直线绘制这条射线的方法。怎么办?

答案1

绘制这个图形有很多种可能性,这里是其中一种。

\documentclass[tikz,border=3.14mm]{standalone}
\begin{document}
\begin{tikzpicture}
\draw (0,0) -- (14,0);
\foreach \X in {0,...,13}
{\draw (\X,0.1) -- (\X,-0.1);}
\foreach \X in {0,4,10,12}
{\node[anchor=north] at (\X,-0.1){\X};}
\end{tikzpicture}
\end{document}

在此处输入图片描述

可以让你添加以逗号作为小数分隔符的数字的是

\documentclass[tikz,border=3.14mm]{standalone}
\begin{document}
\begin{tikzpicture}
\draw (0,0) -- (14,0);
\foreach \X in {0,...,13}
{\draw (\X,0.1) -- (\X,-0.1);}
\foreach \X in {0,2.6,4,6.7,10,12}
{\draw (\X,0.1) -- (\X,-0.1)
node[below] {\pgfmathprintnumber[use comma]{\X}};}
\end{tikzpicture}
\end{document}

在此处输入图片描述

如果你想要更密集的滴答声,请尝试例如

\documentclass[tikz,border=3.14mm]{standalone}
\begin{document}
\begin{tikzpicture}
\draw (0,0) -- (14,0);
\foreach \X [evaluate=\X as \Y using {int(10*(\X-int(\X)))}] in {0,0.1,...,13}
{\ifnum\Y=0
\draw (\X,0.15) -- (\X,-0.15);
\else
\draw (\X,0.1) -- (\X,-0.1);
\fi}
\foreach[evaluate=\X as \Y using {int(10*(\X-int(\X)))}] \X in {0,2.6,4,6.7,10,12}
{\ifnum\Y=0
\node[anchor=north] at (\X,-0.15){\pgfmathprintnumber[use comma]{\X}};
\else
\node[anchor=north] at (\X,-0.1){\pgfmathprintnumber[use comma]{\X}};
\fi
}
\end{tikzpicture}
\end{document}

在此处输入图片描述

当然,也可以在射线上方添加非整数值的刻度。

\documentclass[tikz,border=3.14mm]{standalone}
\begin{document}
\begin{tikzpicture}
\draw (0,0) -- (14,0);
\foreach \X [evaluate=\X as \Y using {int(10*(\X-int(\X)))}] in {0,0.1,...,13}
{\ifnum\Y=0
\draw (\X,0.15) -- (\X,-0.15);
\else
\draw (\X,0.1) -- (\X,-0.1);
\fi}
\foreach[evaluate=\X as \Y using {int(10*(\X-int(\X)))}] \X in {0,2.6,4,6.7,10,12}
{\ifnum\Y=0
\node[anchor=north] at (\X,-0.15){\pgfmathprintnumber[use comma]{\X}};
\else
\node[anchor=south] at (\X,0.1){\pgfmathprintnumber[use comma]{\X}};
\fi
}
\end{tikzpicture}
\end{document}

在此处输入图片描述

答案2

\documentclass[pstricks,border=15pt,12pt]{standalone}
\usepackage{pst-plot}
\begin{document}
\begin{pspicture}(-1,-1)(15,1)
\psaxes[yAxis=false](0,0)(-1,-1)(15,1)
\end{pspicture}
\end{document}

在此处输入图片描述

为了简单起见,故意隐藏了零。

答案3

使用简单的 LaTeX 命令:

\documentclass{article}
\begin{document}

\unitlength=1cm
\begin{picture}(14,0.5)(0,-0.5)
\put(0,0){\vector(1,0){14}}\multiput(0,-0.1)(1,0){14}{\line(0,1){0.2}}
\put(0,-0.5){0}\put(4,-0.5){4}\put(10,-0.5){10}\put(12,-0.5){12}
\end{picture}

\end{document}

在此处输入图片描述

答案4

\documentclass[12pt,pstricks,border=5pt]{standalone}
\usepackage{pst-plot,amsmath}
\begin{document}
\begin{pspicture}(-0.25,-0.5)(14,0.25)
\psaxes[yAxis=false,labels=none,arrows=->](14,0)
\foreach \X in {0,4,10,12}{\uput{8pt}[-90](\X,0){$\X$}}
\end{pspicture}
\end{document}

在此处输入图片描述

相关内容