不使用 groupplot 的情况下多图颜色条的位置

不使用 groupplot 的情况下多图颜色条的位置

我有 6 个图(2 行,3 列),其中colormap只有一个图colorbar位于图的顶部。使用anchorat没有给出预期的结果,我认为这是因为它们引用的是轴而不是颜色条(第一张图)。此外,如果我将anchorat规范放在里面,colorbar style它不起作用(第二张图)。的宽度也存在问题colorbar,我将其设置为轴宽度的 3 倍,但它比预期的要短一点。

\documentclass{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=newest}


\begin{document}
\pgfplotsset{every axis/.append style={font=\tiny}}
\pgfplotsset{mystyle/.style={
    scale only axis,
    height=.29\linewidth, width=.29\linewidth,
    colormap/cool,
    point meta min=-10,
    point meta max=10,
    view={0}{90}}}
\begin{tikzpicture}
\begin{axis}    [mystyle,
            name=frame66a,
            xticklabels={,,}]
    \addplot3[surf,shader=flat] {x+y};
\end{axis}
\begin{axis}    [mystyle,
            name=frame66b,
            at={(frame66a.south west)},
            anchor=north west]
    \addplot3[surf,shader=flat] {x+y};
\end{axis}
\begin{axis}    [mystyle,
            name=frame100a,
            at={(frame66a.south east)},
            anchor=south west,
            yticklabels={,,}, xticklabels={,,}]
    \addplot3[surf,shader=flat] {x+y};
\end{axis}
\begin{axis}    [mystyle,
            name=frame100b,
            at={(frame100a.south west)},
            anchor=north west,
            yticklabels={,,}]
    \addplot3[surf,shader=flat] {x+y};
\end{axis}
\begin{axis}    [mystyle,
            name=frame120a,
            at={(frame100a.south east)},
            anchor=south west,
            yticklabels={,,}, xticklabels={,,}]
    \addplot3[surf,shader=flat] {x+y};
\end{axis}
\begin{axis}    [mystyle,
            name=frame120b,
            at={(frame120a.south west)},
            anchor=north west,
            yticklabels={,,}]
    \addplot3[surf,shader=flat] {x+y};
\end{axis}
\begin{axis}    [hide axis,
                scale only axis,
            height=0pt, width=0pt,
            colormap/cool,
            colorbar horizontal,
            colorbar style={width=.87\linewidth},
            point meta min=0,
            point meta max=350,
            at={(frame120a.north east)},
            anchor=south east]
    \addplot [draw=none] coordinates {(0,0)};
\end{axis}
\end{tikzpicture}
\end{document} 

在此处输入图片描述

在此处输入图片描述

答案1

我找到了一个解决方案。我创建了一个axis3 轴大小、2 轴高度的环境,然后使用at和将其颜色条放在顶部anchor

\documentclass{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=newest}


\begin{document}
\pgfplotsset{every axis/.append style={font=\tiny}}
\pgfplotsset{mystyle/.style={
    scale only axis,
    height=.3\linewidth, width=.3\linewidth,
    colormap/cool,
    point meta min=-10,
    point meta max=10,
    view={0}{90}}}
\begin{tikzpicture}
\begin{axis}    [mystyle,
            name=frame66a,
            xticklabels={,,}]
    \addplot3[surf,shader=flat] {x+y};
\end{axis}
\begin{axis}    [mystyle,
            name=frame66b,
            at={(frame66a.south west)},
            anchor=north west]
    \addplot3[surf,shader=flat] {x+y};
\end{axis}
\begin{axis}    [mystyle,
            name=frame100a,
            at={(frame66a.south east)},
            anchor=south west,
            yticklabels={,,}, xticklabels={,,}]
    \addplot3[surf,shader=flat] {x+y};
\end{axis}
\begin{axis}    [mystyle,
            name=frame100b,
            at={(frame100a.south west)},
            anchor=north west,
            yticklabels={,,}]
    \addplot3[surf,shader=flat] {x+y};
\end{axis}
\begin{axis}    [mystyle,
            name=frame120a,
            at={(frame100a.south east)},
            anchor=south west,
            yticklabels={,,}, xticklabels={,,}]
    \addplot3[surf,shader=flat] {x+y};
\end{axis}
\begin{axis}    [mystyle,
            name=frame120b,
            at={(frame120a.south west)},
            anchor=north west,
            yticklabels={,,}]
    \addplot3[surf,shader=flat] {x+y};
\end{axis}
\begin{axis}    [hide axis,
                scale only axis,
            height=.6\linewidth, width=.9\linewidth,
      at={(frame66a.north west)}, anchor=north west,
            colormap/cool,
            colorbar horizontal,
       colorbar style={height=.03\linewidth, at={(0,1.05)},anchor=south west},
            point meta min=0,
            point meta max=350]
    \addplot [draw=none] coordinates {(0,0)};
\end{axis}
\end{tikzpicture}
\end{document}

在此处输入图片描述

相关内容