pgfplots によって生成されたプロットでキャプション付きのノードの位置を指定するにはどうすればよいでしょうか?

pgfplots によって生成されたプロットでキャプション付きのノードの位置を指定するにはどうすればよいでしょうか?

私の質問は、プロット内のノードの位置をどのように指定するかということです。これが MWE です:

\begin{figure}
\begin{tikzpicture}
    \begin{axis}[
        xlabel=X (\%),
        ylabel=Y (\%),
            legend style={
                draw=none, fill=none, 
                font=\tiny,
                at={(0.5,0.17)},
                anchor=north,
                legend columns=4,
                legend cell align={right},
            },
            xmajorgrids,
        ]
            %CORING (2023)
        \addplot+ [red, mark=square*, nodes near coords,every node near coord/.append style=
                        {xshift=15pt,yshift=8pt,anchor=east,font=\footnotesize}, ultra thick]
                coordinates {
                    (88.25, 93.07)
                    (78.66, 93.83)
                    (66.60, 94.20)
                    (58.19, 94.42)
                    (40.00, 94.67)
                    (19.16, 94.75)
                    (00.00, 93.96)};
            \legend{
                    Method A
                    }
    \end{axis}
\end{tikzpicture}
\caption{My method. %in terms of accuracy versus FLOPs reduction. 
}
\end{figure}

ここに画像の説明を入力してください

この例では、テキストが線で重ねられています。すべてのノードの位置は次のように設定されます。

{xshift=15pt,yshift=8pt}

しかし、これはすべてのノードでうまく機能するわけではありません。そこで、各ノードの位置ChatGPT はこれを提案しますが、機能しません:

各座標に「node[pos]」オプションを追加することで、各ノードの位置を変更できます。「pos」は、座標とラベルを結ぶ線に沿ったノードの位置を指定する 0 から 1 までの値です。たとえば、最初の座標のノードを右に移動するには、「nodes near coords」の代わりに「node[pos=0.5]」を設定し、「xshift」と「yshift」の値をそれに応じて調整します。

前もって感謝します!

答え1

オプションを使用するとcoordinate style、特定の条件に応じて特定のラベルのスタイルを変更できます (もちろん、このメカニズムを使用して、特定の座標のラベルにxshiftまたは を設定することもできます)。yshift

\documentclass[border=10pt]{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=newest}

\begin{document}
\begin{tikzpicture}
    \begin{axis}[
        xlabel=X (\%),
        ylabel=Y (\%),
        legend style={
            draw=none, fill=none, 
            font=\tiny,
            at={(0.5,0.17)},
            anchor=north,
            legend columns=4,
            legend cell align={right},
        },
        xmajorgrids,
    ]
        %CORING (2023)
        \addplot+ [
            red, 
            mark=square*, 
            nodes near coords,
            every node near coord/.append style={
                font=\footnotesize
            }, 
            ultra thick, 
            coordinate style/.condition={x < 10 || x > 40}{
                anchor=west,
            },
            coordinate style/.condition={x > 60}{
                anchor=east,
            }
        ]
        coordinates {
            (88.25, 93.07)
            (78.66, 93.83)
            (66.60, 94.20)
            (58.19, 94.42)
            (40.00, 94.67)
            (19.16, 94.75)
            (00.00, 93.96)
        };
        \legend{
            Method A
        }
    \end{axis}
\end{tikzpicture}
\end{document}

ここに画像の説明を入力してください

関連情報