如何使用「僅標記」屬性來標記繪圖函數的點?

如何使用「僅標記」屬性來標記繪圖函數的點?

我試圖在 tikzpicture 中繪製一個函數,該函數僅顯示特定點並標記這些點。

我的程式碼如下所示:

\documentclass[12pt,a4paper]{article}

\usepackage{tikz}
\usetikzlibrary{fit}
\usetikzlibrary{calc}
\usetikzlibrary{arrows.meta}
\usetikzlibrary{patterns, patterns.meta}

\usepackage{pgfplots}
\pgfplotsset{compat=1.16}
\usepgfplotslibrary{fillbetween}
\usetikzlibrary{backgrounds, intersections}

\begin{document}

\begin{tikzpicture}[scale=1]
    \begin{axis}[
        width=0.6\linewidth,
        xmin=-72,
        xmax= 24,
        ymin=-16,
        ymax= 40,
        x=0.1cm,
        y=0.1cm,
        xtick distance=8,
        ytick distance=8,
        axis lines=middle,
        xlabel=$\Re z_n$,
        ylabel=$\Im z_n$,
        grid={both}]        
            
        \addplot[blue, only marks, domain=1:12, samples=12] ({sqrt(2)^(\x)*cos(deg(\x*pi/4))},{sqrt(2)^(\x)*sin(deg(\x*pi/4))});
\end{tikzpicture}

\end{document}

這段程式碼得出了要點。現在我想給這些點貼上標籤。我已經嘗試過以下程式碼,但它不起作用。我希望你可以幫助我。

\foreach \x in {1,...,12} 
    \draw[blue] ({sqrt(2)^(\x)*cos(deg(\x*pi/4))},{sqrt(2)^(\x)*sin(deg(\x*pi/4))}) node[above]  {$z_\x$};

我的問題是,我可以直接將標籤新增到 addplot 函數中,還是需要編寫一個新增標籤的循環?正確的程式碼是什麼樣的。

我希望你可以幫助我。

答案1

像這樣?和nodes near coords*={$z_{\coordindex}$},

程式碼

\documentclass[boreder=5mm]{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=1.18}
\begin{document}
\begin{tikzpicture}[scale=1]
    \begin{axis}[
        width=0.6\linewidth,
        xmin=-72,
        xmax= 24,
        ymin=-16,
        ymax= 40,
        x=0.1cm,
        y=0.1cm,
        xtick distance=8,
        ytick distance=8,
        axis lines=middle,
        xlabel=$\Re z_n$,
        ylabel=$\Im z_n$,
        grid={both},
        nodes near coords*={$z_{\coordindex}$},
        ]            
        \addplot+[blue, only marks,  domain=1:12, samples=12] ({sqrt(2)^(\x)*cos(deg(\x*pi/4))},{sqrt(2)^(\x)*sin(deg(\x*pi/4))});
    \end{axis}
\end{tikzpicture}
\end{document}

在此輸入影像描述

相關內容