将箭头和文本放置在 pgfplot 中的特定点

将箭头和文本放置在 pgfplot 中的特定点

此代码是根据发布的解决方案构建的这里。我该如何在第二个图中添加这样的箭头和文本:

在此处输入图片描述

以下是代码:

\documentclass{book}
\usepackage[top=3cm,bottom=3cm,left=3.2cm,right=3.2cm,headsep=10pt,a4paper]{geometry}
\usepackage{tikz}
\usepackage{pgfplots,pgfplotstable, booktabs}
\usetikzlibrary{pgfplots.groupplots, matrix,backgrounds}
\usepgfplotslibrary{fillbetween}
\usepackage{filecontents}
\usepackage{graphicx}
\usepackage{float}
\usepackage{subfig}

\begin{filecontents*}{data23.csv}
A   B   C   D
0   -14.9000001 100 -100
0.0000064   8.83999991  100 -100
0.0000128   -3.73000002 100 -100
0.0000192   -2.80000019 100 -100
0.0000256   8.83999991  100 -100
0.000032    15.82999992 100 -100
0.0000384   8.37999988  100 -100
0.0000448   -1.4000001  100 -100
0.0000512   -6.99000001 100 -100
0.0000576   -11.6400001 100 -100
0.000064    -2.33000016 100 -100
0.0000704   0.4599998   100 -100
0.0000768   -1.4000001  100 -100
0.0000832   -19.10000014    100 -100
0.0000896   0   100 -100
0.000096    -4.19000006 100 -100
0.0001024   -15.84000015    100 -100
0.0001088   -5.13000011 100 -100
0.0001152   17.23000002 100 -100
0.0001216   7.44999981  100 -100
0.000128    10.24000001 100 -100
0.0001344   -2.33000016 100 -100
0.0001408   8.37999988  100 -100
0.0001472   -63.80000019    100 -100
0.0001536   -1851.47    100 -100
0.00016 -959001.16  100 -100
0.0001664   -959001.16  100 -100
0.0001728   -959001.16  100 -100
0.0001792   -959001.16  100 -100
0.0001856   -919131.57  100 -100
0.000192    194777.73   100 -100
0.0001984   238253.27   100 -100
0.0002048   277420.5    100 -100
0.0002112   291163.1    100 -100
0.0002176   286195.89   100 -100
0.000224    255122.31   100 -100
0.0002304   182965.3    100 -100
0.0002368   74969.14    100 -100
0.0002432   1717.82 100 -100
0.0002496   -46980.57   100 -100
0.000256    -60135.04   100 -100
0.0002624   -87181.11   100 -100
0.0002688   -82944.99   100 -100
0.0002752   -64264.06   100 -100
0.0002816   -42486.94   100 -100
0.000288    -19782.69   100 -100
0.0002944   -1171.61    100 -100
0.0003008   13164.71    100 -100
0.0003072   21098.18    100 -100
0.0003136   23432.54    100 -100
0.00032 22276.77    100 -100
0.0003264   18429.47    100 -100
0.0003328   11196.82    100 -100
0.0003392   4662.66 100 -100
0.0003456   -366.48 100 -100
0.000352    -3680.12    100 -100
0.0003584   -6535.09    100 -100
0.0003648   -7723.93    100 -100
0.0003712   -7477.13    100 -100
0.0003776   -6128.57    100 -100
0.000384    -3032.39    100 -100
0.0003904   -317.5800002    100 -100
0.0003968   248.1899998 100 -100
0.0004032   1216.77 100 -100
0.0004096   2771.61 100 -100
0.000416    3422.14 100 -100
0.0004224   1918.52 100 -100
0.0004288   947.6199999 100 -100
0.0004352   -420.96 100 -100
0.0004416   -2162.53    100 -100
0.000448    -1460.78    100 -100
0.0004544   153.6599999 100 -100
0.0004608   302.6799998 100 -100
0.0004672   605.8199999 100 -100
0.0004736   -415.8400002    100 -100
0.00048 -997.9200001    100 -100
0.0004864   -1122.25    100 -100
0.0004928   -926.2000001    100 -100
0.0004992   -723.6400001    100 -100
0.0005056   284.98  100 -100
0.000512    81.01999998 100 -100
0.0005184   572.29  100 -100
0.0005248   385.0999999 100 -100
0.0005312   -301.75 100 -100
0.0005376   -298.96 100 -100
0.000544    418.1599999 100 -100
0.0005504   71.7099998  100 -100
0.0005568   839.1199999 100 -100
0.0005632   1733.19 100 -100
0.0005696   1055.65 100 -100
0.000576    -544.3600001    100 -100
0.0005824   -648.2000001    100 -100
0.0005888   -1442.62    100 -100
0.0005952   -778.5900002    100 -100
0.0006016   398.1399999 100 -100
0.000608    1222.36 100 -100
0.0006144   1837.5  100 -100
0.0006208   -152.74 100 -100
0.0006272   -1656.83    100 -100
0.0006336   -477.77 100 -100
\end{filecontents*}

\pgfplotsset{%
    compat=1.12,
    every tick label/.append style={font=\scriptsize},
    every axis plot/.append style={line width=0.8pt},
    minor grid style={dashed,red},
    major grid style={dotted,green!50!black},
}

\captionsetup[subfigure]{labelfont={color=blue,scriptsize,it,bf},textfont={color=blue,scriptsize,it,bf},labelformat=parens,labelsep=space}

\begin{document}

\begin{figure}[H]
\begin{center}
\begin{tikzpicture}
\setcaptionsubtype
\begin{groupplot}[%
            ,group style={%
                ,group name=my plots
                ,group size=1 by 2
                ,vertical sep=2cm,
                ,horizontal sep = 2cm,
                ,ylabels at=edge left
            }
            ,width=10cm
            ,height=6cm
            ,try min ticks=5
            ,xlabel={\bfseries{\emph{\footnotesize{Number of Recursions}}}}
            ,grid=both
            ,every major grid/.style={gray, opacity=0.5}
            ]
\nextgroupplot[xmin = 0, xmax = 0.7]%
\addplot [blue,mark options={scale=.65}]table[x index=0,y index=1, x expr=\thisrow{A}*1000, col sep=space] {data23.csv};\label{plots:ltone}

\nextgroupplot[ymax = 500, ymin = -500, xmin = 0, xmax = 0.7]%
\addplot [blue,mark options={scale=.65}]table[x index=0,y index=1, x expr=\thisrow{A}*1000, col sep=space,restrict y to domain=-10000:10000] {data23.csv};\label{plots:lttwo}

\addplot [smooth,red,thick,name path=A] table[x index=0,y index=2, x expr=\thisrow{A}*1000, col sep=space]{data23.csv};
\addplot [draw=none,name path=B, domain=0:.6336, mark=none] {500};
%\addplot [red, fill opacity=0.1] fill between[of=A and B,soft clip={domain=0:0.6336}];

\begin{scope}[on background layer]
\fill [red!20] (0,100) rectangle (0.7,500);
\fill [red!20] (0,-100) rectangle (0.7,-500);
\end{scope}

\addplot [smooth,red,thick,name path=C] table[x index=0,y index=3, x expr=\thisrow{A}*1000, col sep=space]{data23.csv};
\addplot [draw=none,name path=D, domain=0:.6336, mark=none] {-500};


\end{groupplot}

\node[text width=.5\linewidth,align=center,anchor=south] at (my plots c1r1.north) {\caption[]{Test 1\label{subplot:ltone}}};
\node[text width=.5\linewidth,align=center,anchor=south] at (my plots c1r2.north) {\caption[]{Test 2\label{subplot:lttwo}}};

\end{tikzpicture}
\caption[]{Plot showing position ${\mathbf{P_{T}}}$}\label{abserror}
\end{center}
\end{figure}

\end{document}

答案1

添加name path=plotA到蓝色图后,您可以使用

\draw [-latex, shorten >=3pt, name intersections={of=plotA and A,name=i}] (0.2,420) node[left]{Text here} to[out=350,in=160] (i-1);

请注意,编译需要一段时间,可能是因为有很多交点。该name intersections部分来自intersections库,我相信是由加载的fillbetween。另请注意,只需查看轴上的值即可找到坐标 (0.2,420)。

当然,你也可以直接读取轴上的交点坐标,这样编译起来会快得多,尽管坐标可能不太精确。例如

\draw [-latex] (0.2,420) node[left]{Text here} to[out=350,in=160] (0.34,110);

还不错。

在此处输入图片描述

\documentclass{book}
\usepackage[top=3cm,bottom=3cm,left=3.2cm,right=3.2cm,headsep=10pt,a4paper]{geometry}
\usepackage{tikz}
\usepackage{pgfplots,pgfplotstable, booktabs}
\usetikzlibrary{pgfplots.groupplots, matrix,backgrounds}
\usepgfplotslibrary{fillbetween}
\usepackage{filecontents}
\usepackage{graphicx}
\usepackage{float}
\usepackage{subfig}

\begin{filecontents*}{data23.csv}
A   B   C   D
0   -14.9000001 100 -100
0.0000064   8.83999991  100 -100
0.0000128   -3.73000002 100 -100
0.0000192   -2.80000019 100 -100
0.0000256   8.83999991  100 -100
0.000032    15.82999992 100 -100
0.0000384   8.37999988  100 -100
0.0000448   -1.4000001  100 -100
0.0000512   -6.99000001 100 -100
0.0000576   -11.6400001 100 -100
0.000064    -2.33000016 100 -100
0.0000704   0.4599998   100 -100
0.0000768   -1.4000001  100 -100
0.0000832   -19.10000014    100 -100
0.0000896   0   100 -100
0.000096    -4.19000006 100 -100
0.0001024   -15.84000015    100 -100
0.0001088   -5.13000011 100 -100
0.0001152   17.23000002 100 -100
0.0001216   7.44999981  100 -100
0.000128    10.24000001 100 -100
0.0001344   -2.33000016 100 -100
0.0001408   8.37999988  100 -100
0.0001472   -63.80000019    100 -100
0.0001536   -1851.47    100 -100
0.00016 -959001.16  100 -100
0.0001664   -959001.16  100 -100
0.0001728   -959001.16  100 -100
0.0001792   -959001.16  100 -100
0.0001856   -919131.57  100 -100
0.000192    194777.73   100 -100
0.0001984   238253.27   100 -100
0.0002048   277420.5    100 -100
0.0002112   291163.1    100 -100
0.0002176   286195.89   100 -100
0.000224    255122.31   100 -100
0.0002304   182965.3    100 -100
0.0002368   74969.14    100 -100
0.0002432   1717.82 100 -100
0.0002496   -46980.57   100 -100
0.000256    -60135.04   100 -100
0.0002624   -87181.11   100 -100
0.0002688   -82944.99   100 -100
0.0002752   -64264.06   100 -100
0.0002816   -42486.94   100 -100
0.000288    -19782.69   100 -100
0.0002944   -1171.61    100 -100
0.0003008   13164.71    100 -100
0.0003072   21098.18    100 -100
0.0003136   23432.54    100 -100
0.00032 22276.77    100 -100
0.0003264   18429.47    100 -100
0.0003328   11196.82    100 -100
0.0003392   4662.66 100 -100
0.0003456   -366.48 100 -100
0.000352    -3680.12    100 -100
0.0003584   -6535.09    100 -100
0.0003648   -7723.93    100 -100
0.0003712   -7477.13    100 -100
0.0003776   -6128.57    100 -100
0.000384    -3032.39    100 -100
0.0003904   -317.5800002    100 -100
0.0003968   248.1899998 100 -100
0.0004032   1216.77 100 -100
0.0004096   2771.61 100 -100
0.000416    3422.14 100 -100
0.0004224   1918.52 100 -100
0.0004288   947.6199999 100 -100
0.0004352   -420.96 100 -100
0.0004416   -2162.53    100 -100
0.000448    -1460.78    100 -100
0.0004544   153.6599999 100 -100
0.0004608   302.6799998 100 -100
0.0004672   605.8199999 100 -100
0.0004736   -415.8400002    100 -100
0.00048 -997.9200001    100 -100
0.0004864   -1122.25    100 -100
0.0004928   -926.2000001    100 -100
0.0004992   -723.6400001    100 -100
0.0005056   284.98  100 -100
0.000512    81.01999998 100 -100
0.0005184   572.29  100 -100
0.0005248   385.0999999 100 -100
0.0005312   -301.75 100 -100
0.0005376   -298.96 100 -100
0.000544    418.1599999 100 -100
0.0005504   71.7099998  100 -100
0.0005568   839.1199999 100 -100
0.0005632   1733.19 100 -100
0.0005696   1055.65 100 -100
0.000576    -544.3600001    100 -100
0.0005824   -648.2000001    100 -100
0.0005888   -1442.62    100 -100
0.0005952   -778.5900002    100 -100
0.0006016   398.1399999 100 -100
0.000608    1222.36 100 -100
0.0006144   1837.5  100 -100
0.0006208   -152.74 100 -100
0.0006272   -1656.83    100 -100
0.0006336   -477.77 100 -100
\end{filecontents*}

\pgfplotsset{%
    compat=1.12,
    every tick label/.append style={font=\scriptsize},
    every axis plot/.append style={line width=0.8pt},
    minor grid style={dashed,red},
    major grid style={dotted,green!50!black},
}

\captionsetup[subfigure]{labelfont={color=blue,scriptsize,it,bf},textfont={color=blue,scriptsize,it,bf},labelformat=parens,labelsep=space}

\begin{document}

\begin{figure}[H]
\begin{center}
\begin{tikzpicture}
\setcaptionsubtype
\begin{groupplot}[%
            ,group style={%
                ,group name=my plots
                ,group size=1 by 2
                ,vertical sep=2cm,
                ,horizontal sep = 2cm,
                ,ylabels at=edge left
            }
            ,width=10cm
            ,height=6cm
            ,try min ticks=5
            ,xlabel={\bfseries{\emph{\footnotesize{Number of Recursions}}}}
            ,grid=both
            ,every major grid/.style={gray, opacity=0.5}
            ]
\nextgroupplot[xmin = 0, xmax = 0.7]%
\addplot [blue,mark options={scale=.65}]table[x index=0,y index=1, x expr=\thisrow{A}*1000, col sep=space] {data23.csv};\label{plots:ltone}

\nextgroupplot[ymax = 500, ymin = -500, xmin = 0, xmax = 0.7]%
\addplot [name path=plotA,blue,mark options={scale=.65}]table[x index=0,y index=1, x expr=\thisrow{A}*1000, col sep=space,restrict y to domain=-10000:10000] {data23.csv};\label{plots:lttwo}

\addplot [smooth,red,thick,name path=A] table[x index=0,y index=2, x expr=\thisrow{A}*1000, col sep=space]{data23.csv};
\addplot [draw=none,name path=B, domain=0:.6336, mark=none] {500};

\begin{scope}[on background layer]
\fill [red!20] (0,100) rectangle (0.7,500);
\fill [red!20] (0,-100) rectangle (0.7,-500);
\end{scope}

\addplot [smooth,red,thick,name path=C] table[x index=0,y index=3, x expr=\thisrow{A}*1000, col sep=space]{data23.csv};
\addplot [draw=none,name path=D, domain=0:.6336, mark=none] {-500};


\draw [-latex] (0.2,420) node[left]{Text here} to[out=350,in=160] (0.34,110);

% the slow version
%\draw [-latex, shorten >=3pt, name intersections={of=plotA and A,name=i}] (0.2,420) node[left]{Text here} to[out=350,in=160] (i-1);
\end{groupplot}

\node[text width=.5\linewidth,align=center,anchor=south] at (my plots c1r1.north) {\caption[]{Test 1\label{subplot:ltone}}};
\node[text width=.5\linewidth,align=center,anchor=south] at (my plots c1r2.north) {\caption[]{Test 2\label{subplot:lttwo}}};

\end{tikzpicture}
\caption[]{Plot showing position ${\mathbf{P_{T}}}$}\label{abserror}
\end{center}
\end{figure}

\end{document}

相关内容