将两个图表分组,一个在另一个之上,pgfplot

将两个图表分组,一个在另一个之上,pgfplot

我想组织两个图,其中一个图应位于另一个图上方。我当前的代码可以做到这一点,但是图之间的距离非常长。我想大幅缩短这个距离。

我当前的代码是:

\begin{tikzpicture}
    \begin{groupplot}[group style={group size=1 by 2,
        horizontal sep=0pt,
        vertical sep=-4pt},   
        colormap = {whiteblack}{color(0cm) = (white);color(1cm) = (black)},
        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=2,
            /tikz/.cd
        }    
    ]

    \nextgroupplot[
        axis x line=none,
        axis y line=none,
        axis z line=none,
        zmin = 0, zmax =0.1,  
        height=10cm,width=10cm 
    ]

    \addplot3 [patch, shader=faceted interp, z filter/.code=\def\pgfmathresult{0}, patch table={triangles.txt}
    ] shell {echo "data=dlmread('data.txt');
        tri=delaunay(data(:,1), data(:,2));
        dlmwrite('triangles.txt',tri-1,' ');
        disp(data)" | octave --silent};

    \nextgroupplot[
    axis x line=bottom,
    axis y line=left,
    xlabel = $x$,
    ylabel = $y$,
    zmin = 0, zmax =1,       
    colorbar,    
    height=10cm,width=10cm
    ]

    \addplot3 [patch, shader=faceted interp, patch table={triangles.txt}
    ] shell {echo "data=dlmread('data.txt');
        tri=delaunay(data(:,1), data(:,2));
        dlmwrite('triangles.txt',tri-1,' ');
        disp(data)" | octave --silent};

    \addplot3 [only marks] file {data.txt}; 

    \end{groupplot}   
 \end{tikzpicture}

我目前的结果是: enter image description here

另外,我怎样才能使颜色条变大,以致于它占据整个图形的高度?

编辑1:

现在的问题是如何仅显示与上图不重叠的轴的线?

我当前的图形和代码是:

\begin{tikzpicture}
    \begin{groupplot}[group style={group size=1 by 2,
        horizontal sep=0pt,
        vertical sep=-40pt},   
        colormap = {whiteblack}{color(0cm)  = (white);color(1cm) = (black)},
        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=2,
            /tikz/.cd
        }    
    ]

    \nextgroupplot[
        axis x line=none,
        axis y line=none,
        axis z line=none,
        zmin = 0, zmax =0.1,  
        height=10cm,width=10cm, 
    ]

    \addplot3 [patch, shader=faceted interp, z filter/.code=\def\pgfmathresult{0}, patch table={triangles.txt}
    ] shell {echo "data=dlmread('data.txt');
        tri=delaunay(data(:,1), data(:,2));
        dlmwrite('triangles.txt',tri-1,' ');
        disp(data)" | octave --silent};   

    \nextgroupplot[
    xlabel = $x$,
    ylabel = $y$,
    zmin = 0, zmax =1,  
    height=10cm,width=10cm,
    colorbar,
    every colorbar/.append style={height=10.5cm}, colorbar shift/.append style={yshift=1.8cm},
    axis lines*=box
    ]

    \addplot3 [patch, shader=faceted interp, patch table={triangles.txt}
    ] shell {echo "data=dlmread('data.txt');
        tri=delaunay(data(:,1), data(:,2));
        dlmwrite('triangles.txt',tri-1,' ');
        disp(data)" | octave --silent};

    \addplot3 [colormap = {bw}{color(0cm)  = (black);color(1cm) = (white)}, scatter, only marks, scatter src=z, scatter/use mapped color={
        draw=black,
        fill=mapped color,
    }] file {data.txt}; 

    \end{groupplot}   
    %\end{axis}
  \end{tikzpicture}

结果: enter image description here

答案1

最后一个问题是,平面图先绘制。因此 3d 图会过度绘制平面图。可以通过更改图的顺序并进行vertical sep相应调整来解决此问题。

\documentclass[border=1mm]{standalone}
\usepackage{filecontents}
\usepackage{pgfplots}
\usepgfplotslibrary{groupplots}
\pgfplotsset{compat=1.15}
\begin{filecontents*}{pgfplots-bw-data.txt}
2.17    0.001   0.82044815
2.17    0.002   0.82345825
2.17    0.004   0.82679255
2.17    0.008   0.83334715
2.17    0.016   0.84395915
2.17    0.032   0.8584953
2.21    0.001   0.77582165
2.21    0.003   0.78520505
2.21    0.009   0.80205985
2.21    0.027   0.83085105
2.24    0.001   0.7227885
2.24    0.002   0.73391615
2.24    0.005   0.7543979
2.24    0.015   0.78798745
2.24    0.003   0.74176635
2.24    0.009   0.77064805
2.24    0.027   0.81042375
2.26    0.001   0.66545585
2.26    0.003   0.7012046
2.26    0.005   0.721067
2.26    0.009   0.7447984
2.26    0.015   0.76715245
2.26    0.027   0.794177
2.27    0.001   0.62916195
2.27    0.003   0.6774642
2.27    0.009   0.72961785
2.27    0.027   0.7861086
2.28    0.001   0.5750828
2.28    0.003   0.65059675
2.28    0.005   0.6802631
2.28    0.009   0.7145367
2.28    0.015   0.74447695
2.28    0.027   0.7774403
2.29    0.001   0.51357255
2.29    0.002   0.581053
2.29    0.003   0.6173075
2.29    0.009   0.6972096
2.29    0.027   0.76793225
2.31    0.001   0.36997965
2.31    0.002   0.474415
2.31    0.003   0.53649295
2.31    0.009   0.6587164
2.31    0.016   0.70870255
2.31    0.027   0.7482423
2.31    0.05    0.7912395
2.34    0.001   0.2204104
2.34    0.002   0.316308
2.34    0.003   0.39256745
2.34    0.004   0.45240835
2.34    0.009   0.5883453
2.34    0.016   0.6590771
2.34    0.027   0.71444205
2.34    0.05    0.7690014
2.38    0.001   0.13286995
2.38    0.002   0.1828288
2.38    0.004   0.2980268
2.38    0.008   0.4507145
2.38    0.016   0.58417075
2.38    0.032   0.6833616
\end{filecontents*}
\begin{document}
\pgfdeclarelayer{top plot layer}
\pgfsetlayers{main,top plot layer}
\begin{tikzpicture}
    \begin{groupplot}[group style={group size=1 by 2,
        horizontal sep=0pt,
        vertical sep=-15.7cm},   
        colormap = {whiteblack}{color(0cm)  = (white);color(1cm) = (black)},
        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=2,
            /tikz/.cd
        }    
    ]

    \nextgroupplot[
        xlabel = $x$,
        ylabel = $y$,
        zmin = 0, zmax =1,  
        height=10cm,width=10cm,
        colorbar,
        every colorbar/.append style={height=10.5cm}, colorbar shift/.append style={yshift=1.8cm},
        axis lines*=box
    ]

    \addplot3 [patch, shader=faceted interp, patch table={triangles.txt}
    ] shell {echo "data=dlmread('pgfplots-bw-data.txt');
        tri=delaunay(data(:,1), data(:,2));
        dlmwrite('triangles.txt',tri-1,' ');
        disp(data)" | octave --silent};

    \addplot3 [colormap = {bw}{color(0cm)  = (black);color(1cm) = (white)}, scatter, only marks, scatter src=z, scatter/use mapped color={
        draw=black,
        fill=mapped color,
    }] file {pgfplots-bw-data.txt}; 

    \nextgroupplot[
        axis x line=none,
        axis y line=none,
        axis z line=none,
        zmin = 0, zmax =0.1,  
        height=10cm,width=10cm, 
    ]

    \addplot3 [patch, shader=faceted interp, z filter/.code=\def\pgfmathresult{0}, patch table={triangles.txt}
    ] shell {echo "data=dlmread('pgfplots-bw-data.txt');
        tri=delaunay(data(:,1), data(:,2));
        dlmwrite('triangles.txt',tri-1,' ');
        disp(data)" | octave --silent};   

    \end{groupplot}   
\end{tikzpicture}
\end{document}

enter image description here

相关内容