应 OP 要求更新 2

应 OP 要求更新 2

我想要绘制一个图形(在下页),如下所示:一个数轴,其中有一些用圆圈数字表示的间隔: 在此处输入图片描述

答案1

应 OP 要求更新 2

我创建了一个新的样式,称为 ,from infty以表示从 开始的间隔-infinity。为了将文本放置在图形下方,我将边界框命名为 axe 并在其下方放置了一个节点。

from infty/.style args={#1of#2}{%<-- new style "from infty"
            to path={($(\tikztostart)!#1!90:(\tikztotarget)$).. controls ($(\tikztostart)!1-#2!(\tikztotarget)!#1!90:(\tikztotarget)$) 
                .. (\tikztotarget) \tikztonodes}}

截屏

\documentclass[tikz,border=5mm]{standalone}
%\usepackage{tikz}
\usetikzlibrary{arrows.meta,calc,quotes}
\begin{document}

\tikzset{my curve/.style args={#1of#2}{
        to path={.. controls ($(\tikztostart)!#2!(\tikztotarget)!#1!90:(\tikztotarget)$) 
            and ($(\tikztostart)!1-#2!(\tikztotarget)!#1!90:(\tikztotarget)$) 
            .. (\tikztotarget)\tikztonodes}},
             my curve/.default={7mm of 0.25},
             to infty/.style args={#1of#2}{%<-- new style "to infty"
        to path={.. controls ($(\tikztostart)!#2!(\tikztotarget)!#1!90:(\tikztotarget)$) 
            .. ($(\tikztotarget)!#1!90:(\tikztotarget)$) \tikztonodes}},
            from infty/.style args={#1of#2}{%<-- new style "from infty"
        to path={($(\tikztostart)!#1!90:(\tikztotarget)$).. controls ($(\tikztostart)!1-#2!(\tikztotarget)!#1!90:(\tikztotarget)$) 
            .. (\tikztotarget) \tikztonodes}},
             to infty/.default={7mm of 0.4},
             from infty/.default={7mm of 0.4}}  

\begin{tikzpicture} [pics/tick/.style={code={\draw ++(0,-.2)node[below]{#1}--++(0,.4);}}]
\begin{scope}[local bounding box=axe]%<-- bounding box "axe"
\coordinate (z') at (-2,0);
\coordinate (c) at (1,0);
\coordinate (b) at (4,0);
\coordinate (a) at (6,0);
\coordinate (z) at (9,0);
\draw[-{Stealth[]}] (-2,0)--(10,0);
\pic at (c){tick=c};
\pic at (b){tick=b};
\pic at (a) {tick=a};
%\pic at (z) {tick};
\draw (z')to["4"{draw,circle},from infty](c) to["2"{draw,circle},my curve] (b) to ["3"{draw,circle},my curve] (a) to ["1"{draw,circle},to infty](z);
\end{scope}
\node[below] at (axe.south){My axis};%<-- node to add caption
\end{tikzpicture}

\end{document}

根据 OP 的要求进行更新

我创建了一个新的样式,称为to infty来表示无穷大的间隔。为了将文本放置在图形下方,我命名了边界框axe并在其下方放置了一个节点。

该代码已用 注释掉%<--

截屏

\documentclass[tikz,border=5mm]{standalone}
%\usepackage{tikz}
\usetikzlibrary{arrows.meta,calc,quotes}
\begin{document}

\tikzset{my curve/.style args={#1of#2}{
        to path={.. controls ($(\tikztostart)!#2!(\tikztotarget)!#1!90:(\tikztotarget)$) 
            and ($(\tikztostart)!1-#2!(\tikztotarget)!#1!90:(\tikztotarget)$) 
            .. (\tikztotarget)\tikztonodes}},
             my curve/.default={7mm of 0.25},
             to infty/.style args={#1of#2}{%<-- new style "to infty"
        to path={.. controls ($(\tikztostart)!#2!(\tikztotarget)!#1!90:(\tikztotarget)$) 
            .. ($(\tikztotarget)!#1!90:(\tikztotarget)$) \tikztonodes}},
             to infty/.default={7mm of 0.4}}  

\begin{tikzpicture} [pics/tick/.style={code={\draw ++(0,-.2)node[below]{#1}--++(0,.4);}}]
\begin{scope}[local bounding box=axe]%<-- bounding box "axe"
\coordinate (c) at (1,0);
\coordinate (b) at (4,0);
\coordinate (a) at (6,0);
\coordinate (z) at (9,0);
\draw[-{Stealth[]}] (0,0)--(10,0);
\pic at (c){tick=c};
\pic at (b){tick=b};
\pic at (a) {tick=a};
%\pic at (z) {tick};
\draw (c) to["2"{draw,circle},my curve] (b) to ["3"{draw,circle},my curve] (a) to ["1"{draw,circle},to infty](z);
\end{scope}
\node[below] at (axe.south){My axis};%<-- node to add caption
\end{tikzpicture}

\end{document}

曲线参数

这两种样式都设置好了,默认是上图的样子。可以修改高度曲线及其曲率具有以下参数。例如,my curve=12mm of .4意味着曲线具有高度并且12 mm控制点贝塞尔曲线位于路径的0.4和处。1-0.4=0.6

截屏

\draw (c) to["2"{draw,circle},my curve=12mm of .4] (b) to ["3"{draw,circle},my curve=8mm of .2] (a) to ["1"{draw,circle},to infty=15mm of .6](z);

第一个答案

我重复使用了我的曲线 7我在这里写的代码。我将其重命名为my curve

\tikzset{my curve/.style args={#1of#2}{
        to path={.. controls ($(\tikztostart)!#2!(\tikztotarget)!#1!90:(\tikztotarget)$) 
            and ($(\tikztostart)!1-#2!(\tikztotarget)!#1!90:(\tikztotarget)$) 
            .. (\tikztotarget)\tikztonodes}},
             my curve/.default={7mm of 0.25}} 

我定义了一个pic,可以让你画一个勾并在下面写文字。

pics/tick/.style={code={\draw ++(0,-.2)node[below]{#1}--++(0,.4);}}

结果:

截屏

代码:

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{arrows.meta,calc,quotes}
\begin{document}

\tikzset{my curve/.style args={#1of#2}{
        to path={.. controls ($(\tikztostart)!#2!(\tikztotarget)!#1!90:(\tikztotarget)$) 
            and ($(\tikztostart)!1-#2!(\tikztotarget)!#1!90:(\tikztotarget)$) 
            .. (\tikztotarget)\tikztonodes}},
             my curve/.default={7mm of 0.25}}  

\begin{tikzpicture} [pics/tick/.style={code={\draw ++(0,-.2)node[below]{#1}--++(0,.4);}}]

\coordinate (c) at (1,0);
\coordinate (b) at (4,0);
\coordinate (a) at (6,0);
\coordinate (z) at (9,0);
\draw[-{Stealth[]}] (0,0)--(10,0);
\pic at (c){tick=c};
\pic at (b){tick=b};
\pic at (a) {tick=a};
\pic at (z) {tick};
\draw (c) to["2"{draw,circle},my curve] (b) to ["3"{draw,circle},my curve] (a) to ["1"{draw,circle},my curve](z);
\end{tikzpicture}

\end{document}

相关内容