这只是出于好奇。如果我将命令\pgfplotsset{set layers}
与 结合使用colorbar
,则图表会在我的页面上移动,并且colorbar
不会出现在它应该出现的位置。
这里有一个 MWE(当然我不需要这个set layers
选项):
\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}
答案1
我不能 100% 确定这是一个错误还是一个功能。
尽管如此,我在这里提供了一个可行的解决方案,只需要对您的代码进行少量的更改。
有关更多详细信息,请查看代码中的注释。
% 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}