I'm trying to do a hysteresis loop style figure, and would like to skip some x-values where the figure doesn't really evolve. To that end, I try to splice together 3 axis, each containing a part of the overall data set.
MWE below:
\documentclass[]{standalone}
\usepackage{pgfplots}
\usepackage{tikz}
\usetikzlibrary{positioning}
\begin{document}
\newcommand\Xa{-7.5}
\newcommand\Xb{-6}
\newcommand\Xc{-1.5}
\newcommand\Xd{1.5}
\newcommand\Xe{6}
\newcommand\Xf{7.5}
\begin{tikzpicture}
\begin{axis}[%
name = mid,
unit vector ratio*=2 1 2,
xmin=\Xc,
xmax=\Xd,
xlabel={X label},
ymin=-4,
ymax=4,
axis background/.style={fill=white},
hide y axis
]
\addplot [color=red,solid,mark=asterisk,mark options={solid},forget plot, restrict x to domain=\Xc:\Xd]
table[]{-1.5 -4
1.5 4
};
\node [inner sep=0,outer sep=0](midleft) at (axis cs:\Xc, -4) {};
\node [inner sep=0,outer sep=0](midright) at (axis cs:\Xd, -4) {};
\end{axis}
\begin{axis}[%
at={(mid.outer west)},anchor=outer east,
unit vector ratio*=2 1 2,
xmin=\Xa,
xmax=\Xb,
xlabel={\vphantom{X label}},
xtick={-7, -6},
ymin=-4,
ymax=4,
ylabel={Y label},
axis background/.style={fill=white},
axis y line*=left
]
\addplot [color=red,solid,mark=asterisk,mark options={solid},forget plot, restrict x to domain=\Xa:\Xb]
table[]{-7 -4
-6 -4
};
\node [inner sep=0,outer sep=0](leftright) at (axis cs:\Xb, -4) {};
\end{axis}
\begin{axis}[%
at={(mid.outer east)},anchor=outer west,
unit vector ratio*=2 1 2,
xmin=\Xe,
xmax=\Xf,
xlabel={\vphantom{X label}},
xtick={6,7},
ymin=-4,
ymax=4,
axis background/.style={fill=white},
axis y line*=right
]
\addplot [color=red,solid,mark=asterisk,mark options={solid},forget plot, restrict x to domain=\Xe:\Xf]
table[]{6 4
7 4
};
\node [inner sep=0,outer sep=0](rightleft) at (axis cs:\Xe, -4) {};
\end{axis}
\draw [blue, thick] (leftright) -- (midleft);
\draw [blue, thick] (midright) -- (rightleft);
\end{tikzpicture}%
\end{document}
As you can see, there are some issues: first, the x-axis does not align between the three axis, the two outer seems to be aligned, but not with the center one. I have tried to correct this with a \vphanton x-label, that helped a little, but did not get it in line.
Second, the distance between the center and right, and center and left, axis is not equal.
Finally, the blue lines that should "continue" the x-axis (I plan to "decorate" these with wiggles such that it is clear that they are not continuous) does not reach the node position, there is a slight gap, visible in the PDF output. I tried to correct by setting inner and outer sep to 0, which also helped, but didn't fix it completely.
Can anyone help fix these issues?