軸環境で座標を使用して行の途中までテキストを表示する

軸環境で座標を使用して行の途中までテキストを表示する

軸環境で、テキストを行の途中に表示したいです。最小限の動作例を以下に示します。

\documentclass{article}
\usepackage{currfile}
\usepackage{filecontents}
\usepackage{pgfplots}

\usetikzlibrary{calc}

\begin{filecontents*}{batch_output_5.txt}
    NDOF Nelx Nely hnx hny condKBC errabsu errreleu errrelau beta beta_h
    640     9     9 1.111111111111111e-01 1.111111111111111e-01 1.234567890000000e+00 3.360958503340160e-03 6.801367190507313e-04 6.801883693667268e-04 1.234567890000000e+00 1.234567890000000e+00
    2864    19    19 5.263157894736842e-02 5.263157894736842e-02 1.234567890000000e+00 3.290048281511312e-04 6.939215705384151e-05 6.939186823409962e-05 1.234567890000000e+00 1.234567890000000e+00
    6089    29    29 3.448275862068965e-02 3.448275862068965e-02 1.234567890000000e+00 1.950755726148022e-04 4.494377155875972e-05 4.494363189976460e-05 1.234567890000000e+00 1.234567890000000e+00
    10450    39    39 2.564102564102564e-02 2.564102564102564e-02 1.234567890000000e+00 1.818287989540975e-04 3.111970271342298e-05 3.111966516370642e-05 1.234567890000000e+00 1.234567890000000e+00
   \end{filecontents*}

\begin{document}
    \begin{tikzpicture}
        \begin{loglogaxis}
        [
            unit vector ratio=1 1 1,
            %unit vector ratio*=1 1 1,
            ymin=10^-5,
            ymax=10^-2,
        ]
            \addplot table[x index=3,y index=7] {\currfiledir batch_output_5.txt};

            % Triangle coordinates.         
            \pgfplotstablegetelem{0}{[index]3}\of{\currfiledir batch_output_5.txt}
            \edef\triangleAcoordAx{\pgfplotsretval}
            \pgfplotstablegetelem{0}{[index]7}\of{\currfiledir batch_output_5.txt}
            \edef\triangleAcoordAy{\pgfplotsretval}
            \pgfplotstablegetelem{1}{[index]3}\of{\currfiledir batch_output_5.txt}
            \edef\triangleAcoordBx{\pgfplotsretval}
            \pgfplotstablegetelem{1}{[index]7}\of{\currfiledir batch_output_5.txt}
            \edef\triangleAcoordBy{\pgfplotsretval}
            \pgfplotstablegetelem{0}{[index]3}\of{\currfiledir batch_output_5.txt}
            \edef\triangleAcoordCx{\pgfplotsretval}
            \pgfplotstablegetelem{1}{[index]7}\of{\currfiledir batch_output_5.txt}
            \edef\triangleAcoordCy{\pgfplotsretval} 

            \coordinate (offset) at (0.2,-0.2);
            \coordinate (triangleAcoordA) at (axis cs:\triangleAcoordAx,\triangleAcoordAy);
            \coordinate (triangleAcoordB) at (axis cs:\triangleAcoordBx,\triangleAcoordBy);
            \coordinate (triangleAcoordC) at (axis cs:\triangleAcoordCx,\triangleAcoordCy);

            \coordinate (shiftedTriangleAcoordA) at ($(triangleAcoordA)+(offset)$);
            \coordinate (shiftedTriangleAcoordB) at ($(triangleAcoordB)+(offset)$);
            \coordinate (shiftedTriangleAcoordC) at ($(triangleAcoordC)+(offset)$);

            % Draw triangle.            
            \draw[black]    (shiftedTriangleAcoordA)--
                            (shiftedTriangleAcoordB)--
                            (shiftedTriangleAcoordC)--
                            cycle;
            \draw ($(shiftedTriangleAcoordB)+(shiftedTriangleAcoordC)-(shiftedTriangleAcoordB)$) node[anchor=north]{1};
            \draw ($(shiftedTriangleAcoordC)+(shiftedTriangleAcoordA)-(shiftedTriangleAcoordC)$) node[anchor=west]{2};
        \end{loglogaxis}    
    \end{tikzpicture}
\end{document}

最後の2つの\drawコマンドは次のようになります

\draw ($(shiftedTriangleAcoordB)+((shiftedTriangleAcoordC)-(shiftedTriangleAcoordB))/2$) node[anchor=north]{1};

ですが、そのコマンドは受け入れられません。どうすれば解決できますか?

二次的な質問:

1) テーブルからのデータを LaTeX 変数に保存し、後で座標で使用するためのよりエレガントな方法はありますか? すべて非常に面倒に見えます。

2)0.2,-0.2座標で使用されている は、どこを指しているのでしょうか?グラフの幅と高さの または パーセンテージを指すoffsetのではないと思います。axis cs

答え1

進行中のソリューション

実際には、多くの方法があります。

\draw ($(shiftedTriangleAcoordC)!0.5!(shiftedTriangleAcoordA)$) node[anchor=west]{2};

shiftedTriangleAcoordC「からへのパスの途中shiftedTriangleAcoordA」を取得するには、次のようにパス描画で直接ノードを使用します (繰り返しが少なくなります)。

% Draw triangle.            
\draw[black] (shiftedTriangleAcoordA)-- node[left,pos=0.5] {halfway}
             (shiftedTriangleAcoordB)--
             (shiftedTriangleAcoordC)-- node[right,pos=0.5] {halfway also}
             cycle;

または、コメントの解決策を使用してください。

工事中区域に入る

しかし、そもそも座標を定義するより良い方法についても質問がありました。この構文はコマンドでもpos=<fraction>使用できます。\addplot

つづく...

答え2

テキストを行の半分まで取得するには、コマンドを使用します

\coordinate (midBC) at ($(shiftedTriangleAcoordB)+0.5*(shiftedTriangleAcoordC)-0.5*(shiftedTriangleAcoordB)$);
\coordinate (midAC) at ($(shiftedTriangleAcoordC)+0.5*(shiftedTriangleAcoordA)-0.5*(shiftedTriangleAcoordC)$);

\draw (midBC) node[anchor=north]{1};
\draw (midAC) node[anchor=west]{2};

MaartenDhondtに感謝します。

関連情報