7

Is there a way to draw a sort of connection between subplots in TiKz/pgfplot, like in this example? I'm looking to achieve something like this:

enter image description here

But I would need to draw the "x 2000" line between the plots.

EDIT: So right now I have something like this:

enter image description here

Coming from my 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}

with _ddmp2d.tikz, originally created from matlab2tikz, but already modified, containing:

% This file was created by matlab2tikz v0.3.3.
% Copyright (c) 2008--2013, Nico Schlömer <nico.schloemer@gmail.com>
% 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}%
  • 3
    Could you please post some example code that shows how you generate the axes? Otherwise there's too much guesswork involved when trying to come up with a solution. – Jake Jul 17 '13 at 18:38
12

Please consider giving compilable examples, as you can see below it doesn't take more than 10 lines but makes the question much more simpler to answer.

You can leave coordinates using the axis coordinates for later use.

\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}

enter image description here

  • somehow I've read the label as x=2000 – percusse Jul 17 '13 at 18:52
  • I assume xshift=4cm is supposed to set the distance between the two plots, however it doesn't seem to be working here - somehow the x2000 label is eating into the ytick label. And compat=1.8 is throwing an error: Package pgfkeys Error: Choice '1.8' unknown in key '/pgfplots/compat/anchors'. I am going to ignore this key. [}] – joaocandre Jul 17 '13 at 23:54
  • 3
    If you have a look at the comments and the start of my answer. This is precisely what we are trying to avoid. – percusse Jul 18 '13 at 0:22
  • I've added the code. – joaocandre Jul 18 '13 at 11:44
0

I find this slightly clearer than the accepted answer:

\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}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.