0

I have a set of coordinates, e.g.

    (-4, 1) (-3, 2) (-2, 3), (-1, 4)
    (500, 4) (501, 3) (502, 2) (501, 1)

Suppose I plot these points with an interpolation curve through them as follows.

\begin{tikzpicture}
  \begin{axis}
    \addplot[smooth, mark=*] coordinates {
      (-4, 1) (-3, 2) (-2, 3), (-1, 4)

      %a gap in the interpolation curve here

      (500, 4) (501, 3) (502, 2) (501, 1)
    };
  \end{axis}
\end{tikzpicture}

The problem with this is that the graph looks like 2 vertical lines because of the scaling/compressing of the x axis. The graph is meant to show a curve with positive slope on the left, one with negative slope on the right, and a gap in-between. So I want to shrink/disappear the gap, the interval [5, 499] in the x-axis, and still label things appropriately.

1 Answer 1

1
\documentclass[tikz, border=1cm]{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=1.18}
\begin{document}
\begin{tikzpicture}
\begin{axis}[name=axis1, axis y line*=left, xtick=data]
\addplot[smooth, mark=*] coordinates {(-4, 1) (-3, 2) (-2, 3) (-1, 4)};
\end{axis}
\begin{axis}[at={(axis1.south east)}, axis y line*=right, yticklabels=\empty, xtick=data]
\addplot[smooth, mark=*] coordinates {(500, 4) (501, 3) (502, 2) (501, 1)};
\end{axis}
\end{tikzpicture}
\end{document}

Graph wit split x axis

Edit: With correct interval removed and same x tick distance

\documentclass[tikz, border=1cm]{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=1.18}
\begin{document}
\begin{tikzpicture}
\newcommand{\xinterval}{10}
\begin{axis}[
name=axis1,
axis y line*=left,
xmax=5, xmin=\pgfkeysvalueof{/pgfplots/xmax}-\xinterval,
]
\addplot[smooth, mark=*] coordinates {(-4, 1) (-3, 2) (-2, 3) (-1, 4)};
\end{axis}
\begin{axis}[
at={(axis1.south east)},
axis y line*=right,
yticklabels=\empty,
xmin=499, xmax=\pgfkeysvalueof{/pgfplots/xmin}+\xinterval,
]
\addplot[smooth, mark=*] coordinates {(500, 4) (501, 3) (502, 2) (501, 1)};
\end{axis}
\end{tikzpicture}
\end{document}

Graph with discontinuity in x axis

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .