2

This is just out of curiosity. If I use the command \pgfplotsset{set layers} in conjunction with a colorbar, the plot is shifted on my page and the colorbar does not appear where it is supposed to.

Here a MWE (where I of course don't need the set layers option):

\documentclass{article}

\usepackage{pgfplots}
\usepackage{pgfplotstable}

\begin{document}

\pgfplotstableread{
A B C
0 5 -1
0.5 2 0
1 7 1
1.5 11 1.5
}\mytable %


\begin{tikzpicture}
\pgfplotsset{set layers}

\pgfplotsset
{
colormap
={test}{color=(black); color=( green!75!black);color=(black)}
}

\begin{axis}[
colorbar horizontal,
colorbar style={
at={(0,1.4)},anchor=north west},
]
        \addplot[%
            scatter,%
            only marks,
            mark=*,
            scatter src=explicit,
            colormap name=test,
            ] table [x={A}, y ={B},meta ={C}] %
            {\mytable};
\end{axis}
\end{tikzpicture}

\end{document}
2
  • Which version of pgfplots do you have? A bug fix is included starting from 1.11 and on. See this answer. If you have a new version then include \pgfplotsset{compat=1.12} in your preamble
    – percusse
    Jun 29, 2015 at 16:10
  • I included it but nothing changed.
    – NOhs
    Jun 30, 2015 at 10:11

1 Answer 1

1

I am not 100% sure if this is a bug or a feature.

Nonetheless I provide a working solution here which only needs a minor change in your code.

For more details please have a look at the comments in the code.

% used PGFPlots v1.14
\documentclass{article}
\usepackage{pgfplots}
\usepackage{pgfplotstable}
    \pgfplotsset{
        compat=1.14,
        set layers,
        colormap={test}{
            color=(black)
            color=(green!75!black)
            color=(black)
        },
    }
    \pgfplotstableread{
    A B C
    0 5 -1
    0.5 2 0
    1 7 1
    1.5 11 1.5
    }\mytable
\begin{document}
a\\
\begin{tikzpicture}
    \begin{axis}[
        colorbar horizontal,
        colorbar style={
            % -----------------------------------------------------------------
%            % use this `at' position to show better what I mean
%            at={(0,1.25)},
%            % using the "regular" anchors cause the problem
%            % --> Is that a bug?
%            anchor=north west,
%            anchor=south west,
            % if you use the "outer" anchors, everything works fine
%            anchor=above north west,
            % -------------------------
            anchor=below south west,
            % use this `at' for a good result with the previous `anchor'
            at={(0,1.05)},
            % -----------------------------------------------------------------
%            % this should be another working solution,
%            % but this indeed seems to be a bug (too)
%            % (this is independend of `set layers')
%            at={(parent axis.above north west)},
%            anchor=below south west,
            name=bla,
%            % -----------------------------------------------------------------
        },
        name=blub,
    ]
        \addplot[
            scatter,
            only marks,
            mark=*,
            scatter src=explicit,
            colormap name=test,
        ] table [x={A}, y ={B},meta ={C}] {\mytable};
    \end{axis}
        \draw [red]   (bla.outer south west)  rectangle (bla.outer north east);
        \fill [red]   (bla.below south west)  circle (2pt);
        \fill [green] (blub.above north west) circle (2pt);
\end{tikzpicture}
\end{document}

image showing the result of above code

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .