Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

To show the properties of a function with two variables two-dimensionally I want to fix one variable but let it increase between plots that are placed horizontally next to each other, e.g. plot the functions where the fixed variable is set to 0.2, 0.4, 0.6 and 0.8 respectively. One way of doing this is to draw an x axis that is reset after its maximum is reached. Then the plots share y axis. How can one achieve this with pgfplots?

Below is a crude attempt of achieving this. One problem with it is that it is constructed as separate tikzpictures which may be broken over lines (which happens if the latter part of the example is uncommented). Another problem is that the x axis is broken after its reset.

A rough attempt of a plot with reset x axis

\documentclass{article}

\usepackage{pgfplots}

\pgfplotsset{
  foo/.style={
    domain=0:1,
    xmin=0, xmax=1,
    ymin=-1, ymax=1,
    axis x line=bottom,
    width=5cm,
  }
}

\begin{document}

\begin{figure}
  \begin{tikzpicture}
    \begin{axis}[foo,
      axis y line=left
      ]
      \addplot{0.2 - x};
    \end{axis}
  \end{tikzpicture}
  \begin{tikzpicture}
    \begin{axis}[foo,
      hide y axis
      ]
      \addplot{0.4 - x};
    \end{axis}
  \end{tikzpicture}
  % \begin{tikzpicture}
  %   \begin{axis}[foo,
  %     hide y axis
  %     ]
  %     \addplot{0.6 - x};
  %   \end{axis}
  % \end{tikzpicture}
  % \begin{tikzpicture}
  %   \begin{axis}[foo,
  %     hide y axis
  %     ]
  %     \addplot{0.8 - x};
  %   \end{axis}
  % \end{tikzpicture}
\end{figure}

\end{document}
share|improve this question
add comment

2 Answers

up vote 5 down vote accepted

You can have it all in one tikzpicture by using groupplots (or do it explicitly). The groupplots library also enables fine tuning on separation as well.

Simply add the following in your preamble:

\usepgfplotslibrary{groupplots}

and then do:

\begin{figure}
  \begin{tikzpicture}
    \begin{groupplot}[group style={group size=3 by 1,horizontal sep=.3cm}]
      \nextgroupplot[foo,axis y line=left]
      \addplot{0.2 - x};
      \nextgroupplot[foo,hide y axis]
      \addplot{0.4 - x};
      \nextgroupplot[foo, hide y axis]
      \addplot{0.6 - x};
   \end{groupplot}
 \end{tikzpicture} 
\end{figure}

The group size sets how many plots you need next to each other (here a 3x1 grid of plots).

Generally, you do not need a new tikzpicture for each axis environment. You can simply shift the axis placement in the picture.
This is what groupplots automatically does.

You can not end an axis prematurely. That is, you cannot acquire the end arrows and other styling specifics of the axis without ending it.

However, you can change the ticks and thus change the tick labels to restart after some x max. However, that might be more cumbersome than just using groupplots.

The end result of the above is:

enter image description here

share|improve this answer
add comment

If you went

\begin{figure}
  \mbox{\begin{tikzpicture}...
 \end{tikzpicture}}
\end{figure}

There would be no break points (just a single word space) between the plots.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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