带有点的简单线条,已知坐标

带有点的简单线条,已知坐标

有没有什么简单的方法可以在 tikz、asympote 或类似软件中制作出类似于此图像的东西?

我知道每个点的坐标 =)

简单数轴

实际数字

我当然知道如何解决这个问题,但在 tikz 或类似程序中解决这个问题对我来说还很新鲜。

答案1

在 TikZ 中有一个简单的方法可以做到这一点,使用语句\foreach。像这样:

\documentclass{article}
\usepackage{tikz}
\begin{document}
    \noindent
    \begin{tikzpicture}
        \path[draw, thick, ->] (-.3,0) -- (6.3,0);
        \foreach \x in {0,...,6}{
            \path[draw, thick] (\x,0) -- ++(0,-.15) node [below] {\x};
        }
        \foreach \x/\name in {0/A,.6/B,1/C,1.5/D,2/E,2.3/F,3/G,3.3/H,4/I,4.6/J,5/K,5.5/L}{
            \path[draw, fill=blue] (\x,0) circle[radius=2pt] node [above=2 mm, blue] {\name};
        }
    \end{tikzpicture}
\end{document}

您可以自动标记并根据您输入的坐标自动绘制线条。这是基本方法,结果如下所示:

在此处输入图片描述

答案2

pstricks下面是一个带有(需要xelatexdvips)的示例

\documentclass{article}
\usepackage{pst-plot}
\begin{document}
\begin{pspicture}(0,-1)(6,1)
\psline{->}(0,0)(6,0)
\def\dotatline#1#2{%
  \uput[-90](!#1 ){$#2$}
  \psdot(!#1)
}


\dotatline{8 1 3 div exp 0}{8^{\frac{1}{3}}}

\dotatline{5.5 0 exp 0}{5,5^{0}}

\dotatline{21 sqrt 0}{\sqrt{21}}

\dotatline{6 2 1 neg exp mul 0}{6\cdot 2^{-1}}

\end{pspicture}
\end{document}

在此处输入图片描述

答案3

您无需为位置提供十进制值,而是可以使用pgfmathsetmacro来计算要放置节点的位置。第一个参数是一般数学表达式,第二个参数是要放置的标签。

除了字母之外,您还可以提供数学表达式来标记点。此外,\PlaceNode下面的宏接受一个可选的第一个参数,该参数将应用于标签,以防您希望像我对标签所做的那样对其进行稍微调整tab(30)

在此处输入图片描述

\documentclass[border=5pt,tightpage]{standalone}
\usepackage{tikz}

\newcommand*{\PlaceNode}[3][]{%
    \pgfmathsetmacro{\result}{#2}%
    \node at (\result,0) [fill=red,circle, inner sep=1.5pt] {}; \node at (\result,0) [above, #1] {\scriptsize#3};%
}%
\newcommand*{\PlaceTick}[3][]{%
    \pgfmathsetmacro{\result}{#2}%
    \draw [blue,thick] (\result,0) -- (\result,-0.1) node [below,#1] {#3};
}%

\begin{document}
\begin{tikzpicture}
\draw [thick, blue] (0,0) -- (10,0);

\foreach \x in {0,...,10} {
    \PlaceTick[below]{\x}{$\x$}
}

\PlaceNode{8^(1/3)}{A}
\PlaceNode{5^0}{B}
\PlaceNode{sqrt(21)}{C}
\PlaceNode{tan(30)}{D}
\PlaceNode{15*(2^(-1))}{E}
\PlaceNode{(3/2)^3}{F}
\end{tikzpicture}

\bigskip
\begin{tikzpicture}
\draw [thick, blue] (0,0) -- (10,0);

\foreach \x in {0,...,10} {
    \PlaceTick[below]{\x}{$\x$}
}

\PlaceNode{8^(1/3)}{$8^{\frac{1}{3}}$}
\PlaceNode{5^0}{$5^0$}
\PlaceNode{sqrt(21)}{$\sqrt{21}$}
\PlaceNode[yshift=0.3cm]{tan(30)}{$\tan{30^\circ}$}
\PlaceNode{15*(2^(-1))}{$15 \cdot 2^{-1}$}
\PlaceNode{(3/2)^3}{$\left(\frac{3}{2}\right)^3$}
\end{tikzpicture}
\end{document}

答案4

这是另一个尝试,使用了许多pstricks捆绑包。因此,它需要 或xelatex- latex> dvips->ps2pdf编译序列:

在此处输入图片描述

\documentclass{article}
\usepackage{pst-node}% http://ctan.org/pkg/pst-node
\usepackage[nomessages]{fp}% http://ctan.org/pkg/fp
\usepackage{pstricks-add}% http://ctan.org/pkg/pstricks-add
\usepackage{xcolor}% http://ctan.org/pkg/xcolor
\begin{document}

\begin{pspicture}(7,3)
  \SpecialCoor
  \psset{xunit=2cm}% Default x-unit

  % ========== AXIS ==========
  \pcline{->}(-0.5,0)(6.5,0)% Horizontal line

  % ========== NODE DEFINITIONS ==========
  \pnode(0,0){A}% A
  \FPeval{\result}{tan(30*pi/180)}% tan 30 degrees ~ 0.57735026918962576450914878050196
  \pnode(\result,0){B}% B
  \pnode(1,0){C}% C 5.5^0 = 1
  \pnode(1.5,0){D}% D (dummy node)
  \pnode(2,0){E}% E 8^(1/3) = 2
  \pnode(2.3,0){F}% F (dummy node)
  \pnode(3,0){G}% G 6 x 2^{-1} = 3
  \FPeval{\result}{pow(3,3/2)}% (3/2)^3 = 3.375
  \pnode(\result,0){H}% H
  \pnode(4,0){I}% I
  \FPeval{\result}{root(2,21)}% sqrt(21) ~ 4.582575694955840006588047193728
  \pnode(\result,0){J}% J
  \pnode(5,0){K}% K
  \pnode(5.55,0){L}% L (dummy node)

  % ========== NODE PRESENTATION ==========
    \psset{linestyle=solid,linewidth=0.5pt,linecolor=black,fillcolor=blue!60,fillstyle=solid}
    \psforeach{\node}{A,C,E,G,I,K,{6,0}}{\uput{10pt}[d]{0}(\node){\the\psLoopIndex}}% Print index
    \psforeach{\nNode}{0,1,2,3,4,5,6}{\psline(\nNode,0)(\nNode,-5pt)}% Print index line
  \psforeach{\node}{A,B,C,D,E,F,G,H,I,J,K,L}{%
    \pscircle(\node){2.5pt}% Print nodes
    \uput{10pt}[u]{0}(\node){\color{blue!60}\node}% Print label
  }
\end{pspicture}

\end{document}

在上面的代码中,您可以将 修改xunit为任意值,这将水平拉伸图像。水平单位距离(从AC等)为2cm

相关内容