具有分段常数色条的组图

具有分段常数色条的组图

我目前正在尝试将我的自定义颜色条与 2x1 组图结合起来,以便共享。在以下帮助下,我已经取得了很大进展话题,却陷入了僵局。

问题在于,出于某种原因(我将其归结为选项的引入colorbar sampled),第二个图引入了第二个颜色条,而我从未要求这样做。澄清一下,我试图实现的是跨越两个图的单个颜色条,即下图中显示的顶部颜色条。

我整理了一个最小的工作示例,它可以与自定义颜色条一起使用,确保颜色条高度正确并说明问题,并将其放在说明问题的输出图下方:

最小示例的结果

有人能指导我解决这个问题吗?虽然最小的例子可能没有表明这一点,但我确实需要piecewise constant颜色条。

\documentclass{standalone}

\usepackage{pgfplots}
\usepgfplotslibrary{groupplots}
\pgfplotsset{compat=newest}
\newlength\fheight
\newlength\fwidth

\begin{document}
\scriptsize
\centering
\setlength\fheight{4cm} 
\setlength\fwidth{5cm}
\begin{tikzpicture}

\begin{groupplot}[%
group style={group size=1 by 2,
xlabels at = edge bottom},
colormap={mymap}{[1pt]
rgb=(0.267004,0.00487433,0.329415);
rgb=(0.28315,0.113698,0.434361);
rgb=(0.271534,0.2104,0.505038);
rgb=(0.239637,0.300176,0.540669);
rgb=(0.202221,0.381534,0.554096);
rgb=(0.169529,0.456548,0.558034);
rgb=(0.140966,0.528998,0.555761);
rgb=(0.119984,0.601236,0.54219);
rgb=(0.146361,0.672773,0.509112);
rgb=(0.24974,0.740687,0.44999);
rgb=(0.405343,0.8007,0.361742);
rgb=(0.593466,0.848243,0.244848);
rgb=(0.797749,0.881204,0.118069);
rgb=(0.993248,0.906157,0.143936)},
colorbar sampled,
colormap access=piecewise constant,
colorbar style={
samples=14,
},
group/xlabels at = edge bottom,
xlabel={$x$},
ylabel={$y$},
]

\nextgroupplot[
width=0.838\fwidth,
height=\fheight,
scale only axis,
xmajorgrids,
ymajorgrids,
colorbar,
every colorbar/.append style={height=
    2*\pgfkeysvalueof{/pgfplots/parent axis height}+
    \pgfkeysvalueof{/pgfplots/group/vertical sep}}]
]

\addplot [draw=none] coordinates {(0,0)};

\nextgroupplot[
width=0.838\fwidth,
height=\fheight,
scale only axis,
xmajorgrids,
ymajorgrids,
]

\addplot [draw=none] coordinates {(0,0)};

\end{groupplot}
\end{tikzpicture}%

\end{document}

答案1

一时灵感迸发,我everyevery colorbar钥匙上取下它,它就起作用了(我猜)。这就是你想要的吗?

在此处输入图片描述

\documentclass{standalone}

\usepackage{pgfplots}
\usepgfplotslibrary{groupplots}
\pgfplotsset{compat=newest}
\newlength\fheight
\newlength\fwidth

\begin{document}
\scriptsize
\centering
\setlength\fheight{4cm} 
\setlength\fwidth{5cm}
\begin{tikzpicture}

\begin{groupplot}[%
group style={group size=1 by 2,
xlabels at = edge bottom},
colormap={mymap}{[1pt]
rgb=(0.267004,0.00487433,0.329415);
rgb=(0.28315,0.113698,0.434361);
rgb=(0.271534,0.2104,0.505038);
rgb=(0.239637,0.300176,0.540669);
rgb=(0.202221,0.381534,0.554096);
rgb=(0.169529,0.456548,0.558034);
rgb=(0.140966,0.528998,0.555761);
rgb=(0.119984,0.601236,0.54219);
rgb=(0.146361,0.672773,0.509112);
rgb=(0.24974,0.740687,0.44999);
rgb=(0.405343,0.8007,0.361742);
rgb=(0.593466,0.848243,0.244848);
rgb=(0.797749,0.881204,0.118069);
rgb=(0.993248,0.906157,0.143936)},
colorbar sampled,
colormap access=piecewise constant,
colorbar style={
samples=14,
},
group/xlabels at = edge bottom,
xlabel={$x$},
ylabel={$y$},
]

\nextgroupplot[
width=0.838\fwidth,
height=\fheight,
scale only axis,
xmajorgrids,
ymajorgrids,
colorbar,
% every colorbar/.append style={height=% <------ REMOVED every FROM HERE
colorbar/.append style={height=
    2*\pgfkeysvalueof{/pgfplots/parent axis height}+
    \pgfkeysvalueof{/pgfplots/group/vertical sep}}]
]

\addplot [draw=none] coordinates {(0,0)};

\nextgroupplot[
width=0.838\fwidth,
height=\fheight,
scale only axis,
xmajorgrids,
ymajorgrids,
]

\addplot [draw=none] coordinates {(0,0)};

\end{groupplot}
\end{tikzpicture}%

\end{document}

答案2

我不认为这能解决问题,但我确实找到了一种解决方法,方法是按照本文中的建议进行操作。话题;使用

轴外的彩条

选项来自pgf 手册。我发布这个是因为它确实提供了预期的结果,希望它对其他人有用。

在此处输入图片描述

\documentclass{standalone}

\usepackage{pgfplots}
\usepgfplotslibrary{groupplots}
\pgfplotsset{compat=newest}
\newlength\fheight
\newlength\fwidth

\begin{document}
\scriptsize
\centering
\setlength\fheight{4cm} 
\setlength\fwidth{5cm}
\begin{tikzpicture}

  \begin{groupplot}[%
    group style={group size=1 by 2,
    group name=scatter_combined,
    xlabels at = edge bottom},
    colormap={mymap}{[1pt]
    rgb=(0.267004,0.00487433,0.329415);
    rgb=(0.28315,0.113698,0.434361);
    rgb=(0.271534,0.2104,0.505038);
    rgb=(0.239637,0.300176,0.540669);
    rgb=(0.202221,0.381534,0.554096);
    rgb=(0.169529,0.456548,0.558034);
    rgb=(0.140966,0.528998,0.555761);
    rgb=(0.119984,0.601236,0.54219);
    rgb=(0.146361,0.672773,0.509112);
    rgb=(0.24974,0.740687,0.44999);
    rgb=(0.405343,0.8007,0.361742);
    rgb=(0.593466,0.848243,0.244848);
    rgb=(0.797749,0.881204,0.118069);
    rgb=(0.993248,0.906157,0.143936)},
    colorbar sampled,
    colormap access=piecewise constant,
    colorbar style={
    samples=14,
    },
    colorbar to name=sharedcolorbar,
    group/xlabels at = edge bottom,
    xlabel={$x$},
    ylabel={$y$},
    every colorbar/.append style={height=
        2*\pgfkeysvalueof{/pgfplots/parent axis height}+
        \pgfkeysvalueof{/pgfplots/group/vertical sep}},
    ]

    \nextgroupplot[
    width=0.838\fwidth,
    height=\fheight,
    scale only axis,
    xmajorgrids,
    ymajorgrids,
    ]

    \addplot [draw=none] coordinates {(0,0)};

    \nextgroupplot[
    width=0.838\fwidth,
    height=\fheight,
    scale only axis,
    xmajorgrids,
    ymajorgrids,
    ]

  \addplot [draw=none] coordinates {(0,0)};

  \end{groupplot}
  \node (fig6_Legend) at ($(scatter_combined c1r1.center)!0.5!(scatter_combined c1r2.center)+(0.6\fwidth,0)$){\ref{sharedcolorbar}};


\end{tikzpicture}%

\end{document}

相关内容