3

I'm trying to do Multiple axis discontinuities with pgfplots, and so based on Axis break in pgfplots, I produced this MWE:

\documentclass{article}
\usepackage{calc} %\widthof

\usepackage{pgfplots}
\usepackage{pgfplotstable}
\usetikzlibrary{pgfplots.groupplots}
\usepackage{adjustbox}

\usepackage{tikz}
\usetikzlibrary{shapes}
\usetikzlibrary{positioning}
\usetikzlibrary{decorations.pathreplacing}

\begin{document}
\begin{center}
\begin{tikzpicture}
\begin{groupplot}[
  group style={
    group name=my fancy plots,
    group size=2 by 1,
    yticklabels at=edge left,
    %xticklabels at=edge bottom,
    %vertical sep=0pt,
    horizontal sep=0pt,
  },
%   width=8.5cm,
  height=6cm,
  ymin=-6, ymax=6
]

\nextgroupplot[
  xmin=0,xmax=5,
  xtick={0,5,10},
  axis y line=left,
  %axis x discontinuity=parallel, % disc. is at start, so avoid for first
  axis x line=bottom,
  x axis line style=-, % switch off the axis arrow tips,
  %width=4.5cm, % don't set width,
  x=0.1cm,      % set x scale (for width)
]
\addplot {x*0};

\nextgroupplot[
  xmin=45,xmax=80,
  axis y line=none,
  xtick={60,80},
  axis x discontinuity=parallel,
  axis x line=bottom,
  %width=2.0cm, % don't set width,
  x=0.1cm,      % set x scale (for width)
]
\addplot {0*x};

\end{groupplot}

\end{tikzpicture}
\end{center}
\end{document}

Turns out, what I get is this:

test51.png

... that is, the function is plotted only in the first "sub"plot, but not in the second one?!

Where am I going wrong, and how can I get the function to plot in its entirety?

1
  • 2
    This happens because you're evaluating the function only over the standard range -5 to 5. You have to set domain=0:80.
    – Jake
    Jun 1, 2014 at 19:30

1 Answer 1

2

You have to add the domain key to your groupplots, to define within which range the function should be plotted. If this key is set in the \begin{groupplot} options, you don't have to play with the sample key, in order to get the same marker density in both parts of the plot. Of course you can also use the no markeskey.

Applied to your MWE this would give:

\documentclass{article}
\usepackage{calc} %\widthof

\usepackage{pgfplots}
\usepackage{pgfplotstable}
\usetikzlibrary{pgfplots.groupplots}
\usepackage{adjustbox}

\usepackage{tikz}
\usetikzlibrary{shapes}
\usetikzlibrary{positioning}
\usetikzlibrary{decorations.pathreplacing}

\begin{document}
\begin{center}
\begin{tikzpicture}
\begin{groupplot}[
  group style={
    group name=my fancy plots,
    group size=2 by 1,
    yticklabels at=edge left,
    %xticklabels at=edge bottom,
    %vertical sep=0pt,
    horizontal sep=0pt,
  },
%   width=8.5cm,
  height=6cm,
  ymin=-6, ymax=6,
  domain=0:80,
]

\nextgroupplot[
  xmin=0,xmax=5,
  xtick={0,5,10},
  axis y line=left,
  %axis x discontinuity=parallel, % disc. is at start, so avoid for first
  axis x line=bottom,
  x axis line style=-, % switch off the axis arrow tips,
  %width=4.5cm, % don't set width,
  x=0.1cm,      % set x scale (for width)
]
\addplot {0*x};

\nextgroupplot[
  xmin=45,xmax=80,
  axis y line=none,
  xtick={60,80},
  axis x discontinuity=parallel,
  axis x line=bottom,
  %width=2.0cm, % don't set width,
  x=0.1cm,      % set x scale (for width)
]
\addplot {0*x};

\end{groupplot}

\end{tikzpicture}
\end{center}
\end{document}
1
  • Many thanks for the answer, @ lcnittl (and @jake); I wouldn't have guessed that the domain setting could have been the problem. Cheers!
    – sdaau
    Jun 2, 2014 at 13:08

You must log in to answer this question.

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