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.

The groupplots environment allows global values of xmax to be set. Is there a way to automatically select a common value for all plots in a group? For example, with the code below, the 4th plot does not have the same x-scale as the other 3 plots. Is it possible to have all 4 plots use the same x-axis without manually defining a maximum x value (in this case, '2')?

\documentclass{article}
\usepackage{pgfplots}
\usepgfplotslibrary{groupplots}
\begin{document}
\begin{tikzpicture}
\begin{groupplot}[group style={group size=2 by 2}]
\nextgroupplot
\addplot coordinates{(0,0)(1,1)(2,2)};
\nextgroupplot
\addplot coordinates{(0,2)(1,1)(2,0)};
\nextgroupplot
\addplot coordinates{(0,2)(1,1)(2,1)};
\nextgroupplot
\addplot coordinates{(0,2)(1,1)(1,0)};
\end{groupplot}
\end{tikzpicture}
\end{document}
share|improve this question
    
You can achieve the same scale via axis equal=true, but that might not be exactly what you want as the last graph does not have the same xmin, xmax, but not sure if that is required. –  Peter Grill Nov 19 '12 at 11:05
    
That does provide the correct scale, but I was ultimately looking to use x descriptions at=edge bottom, which, with the example provided, provides the wrong axis labels for the second plot. –  mynoduesp Nov 19 '12 at 12:13

1 Answer 1

You can use the every plot/.style key to enter the common settings in that group

\documentclass{article}
\usepackage{pgfplots}
\usepgfplotslibrary{groupplots}
\begin{document}
\begin{tikzpicture}
\begin{groupplot}[group style={group size=2 by 2,
                               every plot/.style={
                                        xmin=-1,
                                        xmax=2,
                                        enlargelimits=true
                                 }
                             }]
\nextgroupplot
\addplot coordinates{(0,0)(1,1)(2,2)};
\nextgroupplot
\addplot coordinates{(0,2)(1,1)(2,0)};
\nextgroupplot
\addplot coordinates{(0,2)(1,1)(2,1)};
\nextgroupplot
\addplot coordinates{(0,2)(1,1)(1,0)};
\end{groupplot}
\end{tikzpicture}
\end{document}

enter image description here

share|improve this answer
    
This requires xmin and xmax to be specified. Is it possible to achieve the same result automatically? –  mynoduesp Nov 19 '12 at 12:19
    
@mynoduesp Then we need to harvest all the xmax values from each plot and choose the largest one. I'll try to see if I can find something but I don't have much hope. –  percusse Nov 19 '12 at 13:16

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.