有没有办法在 TiKz/pgfplot 中的子图之间绘制某种联系,就像这样例子? 我希望实现这样的目标:
但我需要在图表之间画一条“x 2000”的线。
编辑:所以现在我有这样的东西:
来自我的main.tex
:
\input{aipcheck}
\documentclass[final]{aipproc}
\layoutstyle{8x11single}
\usepackage[utf8]{inputenc}
\usepackage{algorithm2e}
\usepackage{color}
\usepackage[usenames,dvipsnames]{xcolor}
\usepackage{cleveref}
\usepackage{pgfplots}
\pgfplotsset{
tick label style={font=\tiny}, %axis numbers
label style={font=\small}, %axis labels
legend style={font=\tiny}
}
\begin{document}
(...)
\begin{figure}
\centering
\newlength\figureheight
\newlength\figurewidth
\setlength\figureheight{5cm}
\setlength\figurewidth{5cm}
\input{figs/_ddmp2d.tikz}
\label{fig2D}
\end{figure}
_ddmp2d.tikz
最初由matlab2tikz,但已被修改,包含:
% This file was created by matlab2tikz v0.3.3.
% Copyright (c) 2008--2013, Nico Schlömer <[email protected]>
% All rights reserved.
%
% The latest updates can be retrieved from
% http://www.mathworks.com/matlabcentral/fileexchange/22022-matlab2tikz
% where you can also make suggestions and rate matlab2tikz.
%
%
%
\begin{tikzpicture}
\begin{axis}[%
width=\figurewidth,
height=\figureheight,
scale only axis,
xmin=0,
xmax=15,
xlabel={Number of iterations},
ymin=0,
ymax=16000000000000,
name=plot1,
after end axis/.append code={\coordinate (a) at (axis description cs:1,0);}]
\addplot [
thick,
color=red,
dash pattern=on 1pt off 3pt on 3pt off 3pt,
forget plot
]
table[row sep=crcr]{
1 15841000000000\\
(...)
15 25160000000\\
};
\addplot [
thick,
color=black,
dashed,
forget plot
]
table[row sep=crcr]{
1 15841000000000\\
(...)
15 52501000000\\
};
\addplot [
thick,
color=blue,
dotted,
forget plot
]
table[row sep=crcr]{
1 15841000000000\\
(...)
15 5324200000\\
};
\addplot [
thick,
color=green,
solid,
forget plot
]
table[row sep=crcr]{
1 15841000000000\\
(...)
15 551920000\\
};
\addplot [
thick,
color=green,
solid,
forget plot
]
table[row sep=crcr]{
3 0\\
3 16000000000000\\
};
\addplot [
thick,
color=blue,
dotted,
forget plot
]
table[row sep=crcr]{
4 0\\
4 16000000000000\\
};
\addplot [
thick,
color=black,
dashed,
forget plot
]
table[row sep=crcr]{
5 0\\
5 16000000000000\\
};
\addplot [
thick,
color=red,
dash pattern=on 1pt off 3pt on 3pt off 3pt,
forget plot
]
table[row sep=crcr]{
8 0\\
8 16000000000000\\
};
\end{axis}
\begin{scope}[xshift=5cm]
\begin{axis}[%
width=0.35\figurewidth,
height=\figureheight,
scale only axis,
xmin=995,
xmax=1000,
xtick={997,998,999,1000},
xticklabels={$997$,$998$,$999$,$1000$},
ymin=0,
ymax=8000000000,
at=(plot1.right of south east),
anchor=left of south west,
yticklabel pos=right,
axis x discontinuity=crunch,
after end axis/.append code={\coordinate (b) at (axis description cs:0,1);}
]
\addplot [
thick,
color=red,
dash pattern=on 1pt off 3pt on 3pt off 3pt
]
table[row sep=crcr]{
995 6093100000\\
996 6093100000\\
997 6093100000\\
998 6093100000\\
999 6093100000\\
1000 6093100000\\
};
\addplot [
thick,
color=black,
dashed
]
table[row sep=crcr]{
995 1577100000\\
996 1598000000\\
997 1598500000\\
998 1628600000\\
999 1631000000\\
1000 1595900000\\
};
\addplot [
thick,
color=blue,
dotted
]
table[row sep=crcr]{
995 2592000000\\
996 2591900000\\
997 2591700000\\
998 2591600000\\
999 2591500000\\
1000 2591400000\\
};
\addplot [
thick,
color=green,
solid
]
table[row sep=crcr]{
995 391810000\\
996 391810000\\
997 391810000\\
998 391810000\\
999 391810000\\
1000 391810000\\
};
\end{axis}
\draw[gray] (a) -- (b) node[pos=0.5,sloped,fill=white] {$\times$2000};
\end{scope}
\end{tikzpicture}%
答案1
请考虑提供可编译的示例,正如您在下面看到的,它不超过 10 行,但使问题更容易回答。
您可以使用轴坐标保留坐标以供日后使用。
\documentclass{article}
\usepackage{pgfplots}
\pgfplotsset{compat=1.8}
\begin{document}
\begin{tikzpicture}
\begin{axis}[width=3cm,height=5cm,after end axis/.append code={\coordinate (a) at (axis description cs:1,0);}]
\end{axis}
\begin{scope}[xshift=4cm]
\begin{axis}[after end axis/.append code={\coordinate (b) at (axis description cs:0,1);}]
\end{axis}
\draw[gray] (a) -- (b) node[pos=0.5,sloped,fill=white] {$x=2000$};
\end{scope}
\end{tikzpicture}
\end{document}
答案2
我发现这比接受的答案稍微清楚一点:
\documentclass{article}
\usepackage{pgfplots}
\usetikzlibrary{calc}
\pgfplotsset{compat=1.8}
\begin{document}
\begin{tikzpicture}
\begin{axis}[width=3cm,height=5cm,name=a]
\end{axis}
\begin{axis}[width=10cm,height=10cm,name=b,at={($(a.south east)+(5cm,0)$)}]
\end{axis}
\draw[gray] (a.south east) -- (b.north west) node[pos=0.5,sloped,fill=white] {$x=2000$};
\end{tikzpicture}
\end{document}