如何重现具有不同间隔的片段

如何重现具有不同间隔的片段

我不知道如何重现下图中的图表

抱歉,我问了这么糟糕的问题。

在此处输入图片描述

答案1

以下是我的评论,我的版本如下:

条形图

\documentclass{article}
\usepackage{tikz}

\begin{document}
    \begin{center}
    
    \begin{tikzpicture}[scale=.5,arr/.style={line width=1pt,blue,Bar-Bar}]
    
        \foreach \i/\x in
            {
            1/1,
            2/3,
            3/4,
            4/7,
            5/9,
            6/11,
            7/13,
            8/15,
            9/20,
            10/21,
            11/23,
            12/27
            }
                {
                \coordinate (p_\i) at (\x,0);
                \filldraw (p_\i) circle (2pt) node[below=2pt] {$p_{\i}$};
                }           
            \draw (0,0) -- (28,0);
            \path (0,0) -- (0,10);  %just to avoid the `transform canvas` option to get your drawings out of the page
            
            \begin{scope}[arr,every path/.style={transform canvas={shift={(0,1)}}}]
                \draw   (p_1) -- (p_2);
                \draw   (p_3) -- (p_4);
                \draw   (p_11) -- (p_12);           
            \end{scope}
            
            \begin{scope}[arr,every path/.style={transform canvas={shift={(0,2)}}}]
                \draw   (p_2) -- (p_4);
                \draw   (p_5) -- (p_7);
                \draw   (p_10) -- (p_11);           
            \end{scope}     

            \begin{scope}[arr,every path/.style={transform canvas={shift={(0,4)}}}]
                \draw   (p_1) -- (p_3);
                \draw   (p_4) -- (p_5);
                \draw   (p_6) -- (p_7);
                \draw   (p_9) -- (p_11);            
            \end{scope} 
            
            
    \end{tikzpicture}

    \end{center}
\end{document}

您只需调整 p_1 到 p_12 的坐标,其余的就会随之调整。该transform canvas选项旨在允许您在 p_i 节点之间移动路径,并避免手动实现每个段的坐标。

答案2

从这里开始,剩下的就是输入数字:

\documentclass[tikz, border=3.5mm]{standalone} 

\usetikzlibrary{arrows.meta} 

\begin{document} 
    
    \begin{tikzpicture}[arr/.style={Bar-Bar}] 
        
       %baseline
        \draw[] (0,-0) -- (4,0);
        
        %nodes
        \draw[] (0,-0.1) -- (0,0.1);
        \node[scale=0.2] at (0,-0.2) {P1};
        
        \draw[] (1,-0.1) -- (1,0.1);
        \node[scale=0.2] at (1,-0.2) {P2};
        
        \draw[] (2,-0.1) -- (2,0.1);
        \node[scale=0.2] at (2,-0.2) {P3};
        
        %arrows
        \draw[arr] (0,0.5) -- (1,0.5);
        \draw[arr] (1,1) -- (2,1);
    
        %EDIT: red dashed line
        \draw[red,dashed] (0.5,0) -- (0.5,1);
        \draw[red,dashed] (1.5,0.5) -- (1.5,1.5);
        
\end{tikzpicture} 

\end{document}

答案3

\documentclass{article}
\usepackage{xpicture}

\newcommand{\Segment}[1]{\line(1,0){#1}\put(0,-.4){\line(0,1){.8}\put(#1,0){\line(0,1){.8}}}}


\begin{document}
\unitlength=2mm
\noindent{}

\begin{xpicture}(0,0)(50,40)
        \externalaxes{}
        \thicklines{}

        \put(4,24){\Segment{12}}

        \put(7.5,21){\Segment{11.5}}
        \put(36,21){\Segment{5}}

        \put(7.5,18){\Segment{16.5}}
        \put(27.5,18){\Segment{13.5}}

        \put(7.5,16){\Segment{5.5}}
        \put(14,16){\Segment{3.5}}
        \put(21,16){\Segment{0}}
        \put(24,16){\Segment{7}}
        \put(37.5,16){\Segment{10}}

        \put(4,13){\Segment{3.4}}
        \put(9,13){\Segment{5}}
        \put(41,13){\Segment{6.5}}

        \put(1,8){%
          \makenotics\makenolabels
          \cartesianaxes(0,0)(50,0)
          \makenolabels
          \printxticlabel{3}{\mathit{p}_1}
          \printxticlabel{6.5}{\mathit{p}_2\ }
          \printxticlabel{8}{\mathit{p}_3}
          \printxticlabel{13}{\mathit{p}_4}
          \printxticlabel{16.5}{\mathit{p}_5}
          \printxticlabel{20}{\mathit{p}_6}
          \printxticlabel{23}{\mathit{p}_7}
          \printxticlabel{26.5}{\mathit{p}_8}
          \printxticlabel{35}{\mathit{p}_9\ \ }
          \printxticlabel{36.5}{\mathit{p}_{10}}
          \printxticlabel{40}{\mathit{p}_{11}}
          \printxticlabel{46.5}{\mathit{p}_{12}}}
        

\end{xpicture}

\end{document}

xpicture 解决方案

相关内容