如何將平滑圖中的隨機點與軸連接起來?

如何將平滑圖中的隨機點與軸連接起來?

我有一個隨機的平滑繪圖(只是平滑地連接點)並且想要突出顯示點之間的點。應透過將圖表上的點與其在 x 軸上的座標連接來進行突出顯示。

這是我想要保留的 MWE

\documentclass{standalone}

\usepackage{tikz}
\usepackage{pgfplots}

\begin{document}
 \begin{tikzpicture}
      \begin{axis}[ytick=\empty,xtick=\empty, 
             axis on top=false,xmin=0, xmax=10, ymin=0, ymax=5, 
             axis x line=left, axis y line=left, clip=false]
      \node at (rel axis cs:1,0) [above, anchor=north west] {$x$};
      \node at (rel axis cs:0,1) [above, anchor=west] {$y$};
      \addplot[smooth] coordinates {
       (0,0)
       (2,3)
       (5,1.2)
       (5.8,4)
       (8,3.8)
       (10,3.5) 
       } coordinate [pos=.9] (prior) ;

       \end{axis}
  \end{tikzpicture}
\end{document}

我想prior使用平行於 y 軸的線將座標與 x 軸連接起來。我的看法是這樣的

\draw[dotted] (prior)-- (rel axis cs:0.9,0);

然而,由於某種我不清楚的原因,這不是正確的座標(有點偏右)。現在我想知道,如何評估正確的座標?該函數繪製了一個範圍,0:10因此我的數學技能將決定該.9範圍也應該是.9x 軸的長度。然而,這似乎是不正確的。有人知道正確的座標是什麼嗎?或者更簡單:如何以最短的方式將點(之前的)與 x 軸連接起來?

我嘗試使用此問題的答案中建議的解決方案:平滑 pgf 圖。問題是我不知道先前點的 y 座標。

為了完整起見,這裡是它產生的輸出(不用介意軸的不同標籤)

在此輸入影像描述

答案1

所以你正在尋找這個?

之所以pos=0.9不在 x=0.9 處,是因為座標確實放置在直線長度的 90% 處。並且由於在線的開頭(即在低 x 值時)有很多“上下”,因此該線的這部分比在線末尾的部分“更長”(即在高 x 值時) ),幾乎是一條水平直線。

(只是為了完整性:因此,如果您的意圖是在線路上放置一個位於 x=0.9 處的節點,那麼目前無法直接使用該pos功能,但在PGFP圖追蹤器。當然,這也可以間接完成,例如使用intersectionsTikZ 的函式庫。

% used PGFPlots v1.14
\documentclass[border=5pt]{standalone}
\usepackage{pgfplots}
    \pgfplotsset{
        % use this `compat' level or higher so there is no need any more to prefix
        % TikZ coordinates with `axis cs:'
        compat=1.11,
    }
\begin{document}
\begin{tikzpicture}
    \begin{axis}[
        xtick=\empty,
        ytick=\empty,
        xmin=0,
        xmax=10,
        ymin=0,
        ymax=5,
        axis lines=center,
        % (moved the axis labels here)
        xlabel={$x$},
        ylabel={$y$},
        xlabel style={anchor=north west},
        ylabel style={anchor=north east},
    ]

        \addplot [smooth] coordinates {
            (0,0)
            (2,3)
            (5,1.2)
            (5.8,4)
            (8,3.8)
            (10,3.5)
        }
            coordinate [pos=.9] (prior)
        ;

        % to draw a vertical line from `prior' down to the x axis use the `|-' operator and state an arbitrary x value, but 0 as y value
        \draw [dotted] (prior) -- (prior |- 0,0);
    \end{axis}
\end{tikzpicture}
\end{document}

顯示上述程式碼結果的圖像

相關內容