4

Below is an MWE

\documentclass{article}
\usepackage{pgfplots}
\usepgfplotslibrary{groupplots}
\usetikzlibrary{pgfplots.groupplots}

\pgfplotsset{compat = 1.12}

\begin{document}
    \centering

    \begin{figure}
    \centering
    \begin{tikzpicture}{fig6}
        \begin{groupplot}[
                height=6cm,
                width=6cm,
                group style={group size=2 by 2,
                             group name = fig6_plots,
                             xlabels at=edge bottom,
                             ylabels at=edge left
                                        },
                            xlabel = {\footnotesize $\rho$},
                            ylabel = {\footnotesize $\gamma$},
                                        colorbar horizontal,
                                        colorbar to name=Fig6Colorbar,
                                        colormap/blackwhite,
                                        y tick label style={
                                            /pgf/number format/.cd,
                                            fixed,
                                            fixed zerofill,
                                            precision=2,
                                            /tikz/.cd
                                        },
                                        x tick label style={
                                            /pgf/number format/.cd,
                                            fixed,
                                            fixed zerofill,
                                            precision=0,
                                            /tikz/.cd
                                        }]
                            \nextgroupplot[title={\scriptsize Increasing $\alpha$}, z buffer=sort]
                                            \addplot3[surf, shader=interp,colormap/blackwhite] file {PlusIncreasingSurface.txt};
                                        \nextgroupplot[title={\scriptsize Decreasing $\alpha$}, z buffer=sort]
                                            \addplot3[surf, shader=interp,colormap/blackwhite] file {PlusDecreasingSurface.txt};
                                        \nextgroupplot[title={\scriptsize Delta from Come and Go},view={0}{90}]
                                            \addplot3[surf, shader=interp,point meta min=-10,point meta max=0] file {PlusIncreasingDeltaSurface.txt};
                                        \nextgroupplot[title={\scriptsize Delta from Come and Go},view={0}{90}]
                                            \addplot3[surf, shader=interp,point meta min=-10,point meta max=0] file {PlusDecreasingDeltaSurface.txt};

        \end{groupplot}
        \node (fig6_Legend) at ($(fig6_plots c1r2.center)!0.5!(fig6_plots c2r2.center)-(0,4.5cm)$){\ref{Fig6Colorbar}};
    \end{tikzpicture}
    \caption{+Resources Reactive with $\alpha$ Starting at Upper Bound}
    \label{ReactiveDecreasing}
\end{figure}
\end{document}

That produces this output

enter image description here

When run with the data files linked here

PlusIncreasingSurface.txt

PlusIncreasingDeltaSurface.txt

PlusDecreasingSurface.txt

PlusDecreasingDeltaSurface.txt

So far so good...but given the big difference in scale, I decided to ditch the combined colorbar and let each of the bottom charts have its own scale. So I commented out the parts about the node and the meta points that produced the combined colorbar, leaving me with

\documentclass{article}
\usepackage{pgfplots}
\usepgfplotslibrary{groupplots}
\usetikzlibrary{pgfplots.groupplots}

\pgfplotsset{compat = 1.12}

\begin{document}
    \centering

    \begin{figure}
    \centering
    \begin{tikzpicture}{fig6}
        \begin{groupplot}[
                height=6cm,
                width=6cm,
                group style={group size=2 by 2,
                                         group name = fig6_plots,
                             xlabels at=edge bottom,
                             ylabels at=edge left
                                        },
                            xlabel = {\footnotesize $\rho$},
                            ylabel = {\footnotesize $\gamma$},
                                        colorbar horizontal,
                                        %colorbar to name=Fig6Colorbar,
                                        colormap/blackwhite,
                                        y tick label style={
                                            /pgf/number format/.cd,
                                            fixed,
                                            fixed zerofill,
                                            precision=2,
                                            /tikz/.cd
                                        },
                                        x tick label style={
                                            /pgf/number format/.cd,
                                            fixed,
                                            fixed zerofill,
                                            precision=0,
                                            /tikz/.cd
                                        }]
                            \nextgroupplot[title={\scriptsize Increasing $\alpha$}, z buffer=sort]
                                            \addplot3[surf, shader=interp,colormap/blackwhite] file {PlusIncreasingSurface.txt};
                                        \nextgroupplot[title={\scriptsize Decreasing $\alpha$}, z buffer=sort]
                                            \addplot3[surf, shader=interp,colormap/blackwhite] file {PlusDecreasingSurface.txt};
                                        \nextgroupplot[title={\scriptsize Delta from Come and Go},view={0}{90}]
                                            %\addplot3[surf, shader=interp,point meta min=-10,point meta max=0] file {PlusIncreasingDeltaSurface.txt};
                                            \addplot3[surf, shader=interp] file {PlusIncreasingDeltaSurface.txt};
                                        \nextgroupplot[title={\scriptsize Delta from Come and Go},view={0}{90}]
                                            %\addplot3[surf, shader=interp,point meta min=-10,point meta max=0] file {PlusDecreasingDeltaSurface.txt};
                                            \addplot3[surf, shader=interp] file {PlusDecreasingDeltaSurface.txt};
        \end{groupplot}
        %\node (fig6_Legend) at ($(fig6_plots c1r2.center)!0.5!(fig6_plots c2r2.center)-(0,4.5cm)$){\ref{Fig6Colorbar}};
    \end{tikzpicture}
    \caption{+Resources Reactive with $\alpha$ Starting at Upper Bound}
    \label{ReactiveDecreasing}
\end{figure}
\end{document}

When I run this on the same data, I now get this

enter image description here

What's with the "slice" at the top of the two contour plots? It looks like there is an unlabeled colorbar running across the top of each plot?

Bonus question -- how do I change the precision on the ticks in the colorbars?

3

The "slice" you see at the top of the two contour plots are actually colorbars for the two uppermost plots. These are included as you have added colorbar horizontal to the whole group. Each axis environment inherits these options, meaning every plot in this group will have its own colorbar. To see this clearly you can increase the vertical spacing between the plots.

To avoid this, you have to move the colorbar horizontal option to the axes where you indeed want them. If you want the colorbars of the two contour plots to have the same tick format, you can simply create a new style in pgfplots, and apply this to those axes. If you write

\pgfplotsset{%
  mycolorbar/.style={%
    colorbar horizontal,
    every colorbar/.append style={%
      x tick label style={%
        /pgf/number format/.cd,
        fixed,
        fixed zerofill,
        precision=2,
        /tikz/.cd}}}
}

before the tikzpicture environment, you can simply add the option mycolorbar to the axes where you want colorbars. If you want different format for the two colorbars, you have to define them in each of the \nextgroupplot[...] options.

Thus, the following code gives the output below

\documentclass{article}
\usepackage{pgfplots}
\usepgfplotslibrary{groupplots}
\usetikzlibrary{pgfplots.groupplots}

\pgfplotsset{compat = 1.12}

\begin{document}

\pgfplotsset{%
  mycolorbar/.style={%
    colorbar horizontal,
    every colorbar/.append style={%
      x tick label style={%
        /pgf/number format/.cd,
        fixed,
        fixed zerofill,
        precision=2,
        /tikz/.cd}}}
}

\begin{figure}
  \centering
  \begin{tikzpicture}{fig6}
    \begin{groupplot}[
      height=6cm,
      width=6cm,
      group style={%
        group size=2 by 2,
        group name=fig6_plots,
        xlabels at=edge bottom,
        ylabels at=edge left
      },
      xlabel = {\footnotesize $\rho$},
      ylabel = {\footnotesize $\gamma$},
      %colorbar to name=Fig6Colorbar,
      colormap/blackwhite,
      y tick label style={%
        /pgf/number format/.cd,
        fixed,
        fixed zerofill,
        precision=2,
        /tikz/.cd
      },
      x tick label style={
        /pgf/number format/.cd,
        fixed,
        fixed zerofill,
        precision=0,
        /tikz/.cd
      }
    ]
      \nextgroupplot[title={\scriptsize Increasing $\alpha$}, z buffer=sort]
        \addplot3[surf, shader=interp,colormap/blackwhite] file {PlusIncreasingSurface.txt};
      \nextgroupplot[title={\scriptsize Decreasing $\alpha$}, z buffer=sort]
        \addplot3[surf, shader=interp,colormap/blackwhite] file {PlusDecreasingSurface.txt};
      \nextgroupplot[mycolorbar, title={\scriptsize Delta from Come and Go},view={0}{90}]
        \addplot3[surf, shader=interp] file {PlusIncreasingDeltaSurface.txt};
      \nextgroupplot[mycolorbar, title={\scriptsize Delta from Come and Go},view={0}{90}]
        \addplot3[surf, shader=interp] file {PlusDecreasingDeltaSurface.txt};
    \end{groupplot}
  \end{tikzpicture}
  \caption{+Resources Reactive with $\alpha$ Starting at Upper Bound}
  \label{ReactiveDecreasing}
\end{figure}
\end{document}

Output

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.