目标是让网格位于图表下方,但axis on top=false
为 有效addplot
但不为addplot3
,为了解决这个问题,我应用了提出的解决方案addplot3 上不尊重顶部的轴groupplots
,但由于我单独使用,set layers
严重影响了布局。我还应用了pgfplot 图例位于网格顶部,但在轴和 groupplot 中的图形下方(添加cell picture=true
)这有所改善,但我仍然得到了colorbar
放错位置且没有图例的信息。
第一张图片是想要的图形布局,但它需要有网格. (通过注释标有 %% 的代码获得:添加到“修复”...)
第二张图片是我目前设法得到的结果(使用这篇文章中的代码),网格现在位于图形后面,但布局搞砸了。
\documentclass{article}
\usepackage{pgfplots}
\pgfplotsset{compat=1.12}
\usetikzlibrary{pgfplots.colormaps}
\usetikzlibrary{pgfplots.groupplots}
\begin{document}
\begin{tikzpicture}
\begin{groupplot}[
set layers, cell picture=true, %% Added to "fix" axis on top=false
domain=-1:1,
xmin=-1.2, xmax=1.2,
colormap/copper,
group style={group size=1 by 2, horizontal sep=0pt,vertical sep=0pt},
grid=major,
ylabel absolute,
axis on top=false,
]
\nextgroupplot[
axis equal image=true,
ymin=0, ymax=0.8,
xticklabel=\empty,
ylabel={Probability},
]
\addplot[
mesh,
samples=25,
] gnuplot {
min(a,b) = (a < b) ? a : b
r2(x) = min(1,(x^2))
6*(1-r2(x))*(27-8*r2(x)) / (73 * pi)
};
\node[above right] at (0,0) { $ y = 0 $ };
\nextgroupplot[
ymin=-1.2, ymax=1.2, zmin=0,
view={0}{90},
colorbar horizontal,
colorbar style={point meta min=0,point meta max=0.7},
colorbar/width=2.5mm,
grid=major,
clip=false,
ylabel={$y$},
xlabel={$x$},
]
\addplot3[
on layer=axis foreground, %% Added to "fix" axis on top=false
samples=25,
contour gnuplot={
output point meta=rawz,
levels={0.2,0.4,0.6},
labels=true,
handler/.style=smooth,
},
z filter/.code=\def\pgfmathresult{0},
] gnuplot {
min(a,b) = (a < b) ? a : b
r2(x,y) = min(1,(x^2+y^2))
(x,y,6*(1-r2(x,y))*(27-8*r2(x,y)) / (73 * pi) )
};
\coordinate[label=below right:{\tiny P1}] (P1) at (-0.65, -0.3, 0);
\coordinate[label=below right:{\tiny P2}] (P2) at (axis cs: 0.3, 0.4, 0);
\coordinate[label=above right:{\tiny O} ] (O) at (axis cs: 0.0, 0.0, 0.0);
\fill[black] (O) circle (1pt);
\fill[black] (P1) circle (2pt);
\fill[black] (P2) circle (2pt);
\draw (0,0) circle(1);
\draw[<->,shorten >= 2pt, shorten <= 2pt] (0,0) -- (-55:1)
node[midway,above,sloped] { \tiny $ r = 1 $ };
\draw[->,shorten >= 4pt, shorten <= 4pt] (P1) -- (P2);
\end{groupplot}
\end{tikzpicture}
\end{document}