3

I would like to plot two separate data files in two separate axis environments so that they are placed right next to each other. They will be part of the same subfigure, so I think I need to shift the content of \begin{axis}...\end{axis} sufficiently to the right.

In materials science, the band structure and density of states are often plotted next to each other, like the one attached. I would like to do this with PGFPlots, but how can I shift the entire axis environment to the right? Do I have to individually move every fragment of the coordinate system, or can I just move everything at once?

enter image description here

  • 1
    Look at the groupplots library, or set at={<coordinate>} for the second axis. – Torbjørn T. May 24 '16 at 9:03
6

One option is a groupplot, another is a combination of the name and at keys to position the first axis relative to the second.

\documentclass{article}
\usepackage{pgfplots}
\usepgfplotslibrary{groupplots}
\begin{document}
An example with the \texttt{groupplots} library:

\begin{tikzpicture}
\begin{groupplot}[
  group style={
    group size=2 by 1,
    y descriptions at=edge left,
    horizontal sep=2mm
},
  scale only axis,
  height=6cm,
  ymin=0,ymax=7,
]
\nextgroupplot[width=2cm,xlabel=Something]
\addplot{5*rnd};

\nextgroupplot[width=6cm,xlabel=Else]
\addplot{4*rnd};
\end{groupplot}
\end{tikzpicture}

\bigskip

And by positioning one \texttt{axis} relative to the other.


\begin{tikzpicture}
\pgfplotsset{width=6cm}
\begin{axis}[name=Ax1,ymax=0.99] %ymax just for example
\addplot{rnd};
\end{axis}

\begin{axis}[name=Ax2,at={($(Ax1.north east)+(1cm,0)$)},anchor=north west]
\addplot{rnd};
\end{axis}
\end{tikzpicture}
\end{document}

enter image description here

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.