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.

I created a 2x2 array where each box contains a subfigure. For three subplots I use \addplot3 from PGFplots with colorbar and in the other, a \addplot. Due to the use of colorbar, the symmetry of the four subfigures is broken. I would like to know if there is a way to rescale the unique plot such that it will align to the other 3 subfigures with colorbar.

Here is an example of my code:

\documentclass[a4paper,12pt]{article}

\usepackage{pgfplots}
\usepgfplotslibrary{patchplots,colormaps}

\usepackage{subfigure}
\usepackage[a4paper]{geometry}
\usepackage{array}
\newcolumntype{C}[1]{>{\centering\arraybackslash}p{#1}}

\begin{document}
\subsection{First subsection}
\begin{figure}[htbp]
\hspace{-0.5cm}
\begin{tabular}{C{.48\textwidth}C{.48\textwidth}}
 %%%%%%%%%%%%%%%%%%%%%% 1 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 \subfigure [Subfigure 1] {
 \resizebox{0.5\textwidth}{!}{%
  \begin{tikzpicture} %
  \begin{axis}[view={0}{90}, %
               xlabel={$p$}, %
           ylabel={Mean}, %
               title={Mean vs $p$}, %
               y filter/.code=\pgfmathparse{\pgfmathresult/400}, %
               colormap/autumn, %
               colorbar, %
               xmin=0, %
               xmax=0.1, %
       ymin=0, %
       ymax=1, %
              xticklabel style={/pgf/number format/.cd,fixed,precision=2}, %
              ] %
  \end{axis} %
 \end{tikzpicture}
}} & 
%%%%%%%%%%%%%%%%%%%%%% 2 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\subfigure [Subfigure 2] {
 \resizebox{0.5\textwidth}{!}{%
 \begin{tikzpicture} %
  \begin{axis}[view={0}{90}, %
               xlabel={$p$}, %
           ylabel={Mean}, %
               title={Mean vs $p$}, %
               colormap/cool,
       colorbar,
               xmin=0,%
               xmax=0.1, %
       ymin=0, %
       ymax=1, %
               xticklabel style={/pgf/number format/.cd,fixed,precision=2}, %
              ] %
  \end{axis} %
 \end{tikzpicture}
}} \\
%%%%%%%%%%%%%%%%%%%%%% 3 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 \subfigure [Subfigure 3] {
 \resizebox{0.5\textwidth}{!}{%
\begin{tikzpicture} %
  \begin{axis}[tiny,
       xlabel={$p$}, %
           ylabel={Mean}, %
               title={Mean vs $p$}, %
       height=5.2cm, width=6cm,% improve scaling manually
               xmin=0,%
               xmax=0.1, %
       ymin=0, %
       ymax=1, %
       only marks, %
       mark size=0.1pt, %
               xticklabel style={/pgf/number format/.cd,fixed,precision=2}, 
      ]
   \end{axis}
  \end{tikzpicture}
 }} & 
%%%%%%%%%%%%%%%%%%%%%% 4 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\subfigure [Subfigure 4] {
 \resizebox{0.5\textwidth}{!}{%
 \begin{tikzpicture} %
  \begin{axis}[view={0}{90}, %
               xlabel={$p$}, %
           ylabel={Mean}, %
               title={Mean vs $p$}, %
               colormap/cool, %
       colorbar, %                   
       xmin=0, %
               xmax=0.1, %
       ymin=0, %
              ] %
  \end{axis} %
 \end{tikzpicture}
}} \\
\end{tabular}
\caption{Several options}
\end{figure}
\end{document}

Here is the result:

Maybe it would be simpler to place the 3rd pgfplot a bit higher:

share|improve this question

1 Answer 1

up vote 6 down vote accepted

I would not recommend using \resizebox to get the desired plot size, as this will scale the text as well: Arbitrarily different font sizes on the same page look really unprofessional.

One way to get more precise control over the size of the plots is to use the key scale only axis, which specifies that width and height commands only apply to the axis area without the tick labels, color bars, and titles. Then you can set the width to some appropriate value: If you want each plot to fill half the page width, you'll have to use some value smaller than 0.5\textwidth, as the color bars and labels still need to be accommodated. To get the plots to align nicely, you can pass the options trim axis left, trim axis right to the tikzpicture environment. This specifies that only the actual plot area will be used for positioning the plots.


If you want to use horizontal color bars below the plots, you can add the option baseline to the tikzpicture environments. This will align the lower edge of the plots with the text baseline.


Code for alignment with vertical color bars:

\documentclass[a4paper,12pt]{article}

\usepackage{pgfplots}
\usepgfplotslibrary{patchplots,colormaps}

\usepackage{subfigure}
\usepackage[a4paper]{geometry}
\usepackage{array}
\newcolumntype{C}[1]{>{\centering\arraybackslash}p{#1}}
\pgfplotsset{
    every axis/.append style={
        scale only axis,
        width=0.25\textwidth,
        xtick={0,0.05,0.1},
    },
    /tikz/every picture/.append style={
        trim axis left,
        trim axis right,
    }
}
\begin{document}
\subsection{First subsection}
\begin{figure}[htbp]
\hspace{-0.5cm}
\begin{tabular}{C{.48\textwidth}C{.48\textwidth}}
 %%%%%%%%%%%%%%%%%%%%%% 1 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 \subfigure [Subfigure 1] {
  \begin{tikzpicture} %
  \begin{axis}[
    view={0}{90}, %
    xlabel={$p$}, %
    ylabel={Mean}, %
    title={Mean vs $p$}, %
    y filter/.code=\pgfmathparse{\pgfmathresult/400}, %
    colormap/autumn, %
    colorbar, %
    xmin=0, %
    xmax=0.1, %
    ymin=0, %
    ymax=1, %
    xticklabel style={/pgf/number format/.cd,fixed,precision=2},
] %
  \end{axis} %
 \end{tikzpicture}
} & 
%%%%%%%%%%%%%%%%%%%%%% 2 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\subfigure [Subfigure 2] {
 \begin{tikzpicture} %
  \begin{axis}[view={0}{90}, %
               xlabel={$p$}, %
           ylabel={Mean}, %
               title={Mean vs $p$}, %
               colormap/cool,
       colorbar, 
               xmin=0,%
               xmax=0.1, %
       ymin=0, %
       ymax=1, %
               xticklabel style={/pgf/number format/.cd,fixed,precision=2}, %
              ] %
  \end{axis} %
 \end{tikzpicture}
} \\
%%%%%%%%%%%%%%%%%%%%%% 3 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 \subfigure [Subfigure 3] {

\begin{tikzpicture} %
  \begin{axis}[
       xlabel={$p$}, %
           ylabel={Mean}, %
               title={Mean vs $p$}, %
               xmin=0,%
               xmax=0.1, %
       ymin=0, %
       ymax=1, %
       only marks, %
       mark size=0.1pt, %
               xticklabel style={/pgf/number format/.cd,fixed,precision=2},
      ]
   \end{axis}
  \end{tikzpicture}
 } & 
%%%%%%%%%%%%%%%%%%%%%% 4 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\subfigure [Subfigure 4] {
 \begin{tikzpicture} %
  \begin{axis}[view={0}{90}, %
               xlabel={$p$}, %
           ylabel={Mean}, %
               title={Mean vs $p$}, %
               colormap/cool, %
       colorbar, %                   
       xmin=0, %
               xmax=0.1, %
       ymin=0,ymax=1, %
       xticklabel style={/pgf/number format/.cd,fixed,precision=2},
              ] %
  \end{axis} %
 \end{tikzpicture}
} \\
\end{tabular}
\caption{Several options}
\end{figure}
\end{document}

Code for alignment with horizontal color bars:

\documentclass[a4paper,12pt]{article}

\usepackage{pgfplots}
\usepgfplotslibrary{patchplots,colormaps}

\usepackage{subfigure}
\usepackage[a4paper]{geometry}
\usepackage{array}
\newcolumntype{C}[1]{>{\centering\arraybackslash}p{#1}}
\pgfplotsset{
    every axis/.append style={
        scale only axis,
        width=0.3\textwidth,height=0.23\textwidth,
        xtick={0,0.05,0.1},
    },
    /tikz/every picture/.append style={
        trim axis left,
        trim axis right,
        baseline
    }
}
\begin{document}
\subsection{First subsection}
\begin{figure}[htbp]
\hspace{-0.5cm}
\begin{tabular}{C{.48\textwidth}C{.48\textwidth}}
 %%%%%%%%%%%%%%%%%%%%%% 1 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 \subfigure [Subfigure 1] {
  \begin{tikzpicture} %
  \begin{axis}[
    view={0}{90}, %
    xlabel={$p$}, %
    ylabel={Mean}, %
    title={Mean vs $p$}, %
    y filter/.code=\pgfmathparse{\pgfmathresult/400}, %
    colormap/autumn, %
    colorbar horizontal, %
    xmin=0, %
    xmax=0.1, %
    ymin=0, %
    ymax=1, %
    xticklabel style={/pgf/number format/.cd,fixed,precision=2},
] %
  \end{axis} %
 \end{tikzpicture}
} & 
%%%%%%%%%%%%%%%%%%%%%% 2 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\subfigure [Subfigure 2] {
 \begin{tikzpicture} %
  \begin{axis}[view={0}{90}, %
               xlabel={$p$}, %
           ylabel={Mean}, %
               title={Mean vs $p$}, %
               colormap/cool,
       colorbar horizontal, 
               xmin=0,%
               xmax=0.1, %
       ymin=0, %
       ymax=1, %
               xticklabel style={/pgf/number format/.cd,fixed,precision=2}, %
              ] %
  \end{axis} %
 \end{tikzpicture}
} \\
%%%%%%%%%%%%%%%%%%%%%% 3 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 \subfigure [Subfigure 3] {

\begin{tikzpicture} %
  \begin{axis}[
       xlabel={$p$}, %
           ylabel={Mean}, %
               title={Mean vs $p$}, %
               xmin=0,%
               xmax=0.1, %
       ymin=0, %
       ymax=1, %
       only marks, %
       mark size=0.1pt, %
               xticklabel style={/pgf/number format/.cd,fixed,precision=2},
      ]
   \end{axis}
  \end{tikzpicture}
 } & 
%%%%%%%%%%%%%%%%%%%%%% 4 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\subfigure [Subfigure 4] {
 \begin{tikzpicture} %
  \begin{axis}[view={0}{90}, %
               xlabel={$p$}, %
           ylabel={Mean}, %
               title={Mean vs $p$}, %
               colormap/cool, %
       colorbar horizontal, %                   
       xmin=0, %
               xmax=0.1, %
       ymin=0,ymax=1, %
       xticklabel style={/pgf/number format/.cd,fixed,precision=2},
              ] %
  \end{axis} %
 \end{tikzpicture}
} \\
\end{tabular}
\caption{Several options}
\end{figure}
\end{document}
share|improve this answer
    
I added something to my LaTeX document and the line /tikz/every picture/.append style generate a problem. Is it possible to define a style and call it each time it is needed instead of global? –  Eagle May 4 '12 at 9:31
    
You'll need to provide more information about this. What problem does it generate (what's the error message)? What code did you use exactly? Most importantly, what are you trying to achieve? –  Jake May 4 '12 at 23:39

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.