x 轴的第二个标签未出现在 3D pgfplot 中

x 轴的第二个标签未出现在 3D pgfplot 中

对于下图,我需要显示两个 x 轴标签,如图所示。问题是我需要较低的温度标签出现在图中“HERE”的位置。我可以使用 将above文本放置在节点位置上方,但当我使用 时轴标签不会出现below。如果我从节点位置省略abovebelow,则文本的上半部分将显示在轴线的顶部。

我跟着答案与这篇文章类似,但有一个重要的区别(据我所知)。我已将默认轴标签设置为位于图表上方,次要标签位于图表下方。

这是一系列图表中的一张。我正在逐项“构建”图表,以便让学生了解情况。我想暂时添加额外的 x 轴标签以方便定位。下一张图表将对第二个变量(种子大小)执行相同的操作。其余图表的标签仅在图表上方。

\documentclass[border=10pt]{article}
\usepackage{pgfplots}
    \usepgfplotslibrary{colorbrewer}
    \usepgfplotslibrary{fillbetween}
    \pgfplotsset{
        % Set `compat level to 1.11 or higher so you don't need to
        % prefix every tikz coordinate with `axis cs:'
        compat=1.14,
        3dbaseplot/.style={
                width           = 10cm,
            view            = {45}{65},
            axis on top,
            enlargelimits = false,
            domain          = 1:4,
            y domain       = 1:4,
            no markers,
            samples        = 30,
            xlabel          = {Temperature},
            ylabel          = {Seed Size},
            zlabel          = {Relative\\Abundance},
            xlabel style    = {sloped, at={(rel axis cs:0.5,1,1)}, above, sloped like x axis},
            ylabel style    = {sloped, at={(rel axis cs:0,0.5,1)}, above, sloped like y axis},
            zlabel style    = {rotate=-90, align=right},
            ticks               = none,
            smooth,
    },
    /pgf/declare function = {
        normal(\m,\s)=1/(2*\s*sqrt(pi))*exp(-(x-\m)^2/(2*\s^2));
    },
    /pgf/declare function = {
        bivar(\ma,\sa,\mb,\sb)=
            1/(2*pi*\sa*\sb) * exp(-((x-\ma)^2/\sa^2 + (y-\mb)^2/\sb^2))/2;
    }
}

\pgfmathsetmacro{\factor}{3}

\newcommand*\myaddplotX[4]{
    \addplot3+ [name path=#1,domain=#2-\factor*#3:#2+\factor*#3, color=#4] (x,4,{normal(#2,#3)});
}
\newcommand*\myaddplotY[4]{
    \addplot3+ [name path=#1,domain=#2-\factor*#3:#2+\factor*#3, color=#4] (1,x,{normal(#2,#3)});
}

\begin{document}

\begin{tikzpicture}[
    declare function = {orMuX=2.0;},
    declare function = {orMuY=3.2;},
    declare function = {blMuX=2.5;},
    declare function = {blMuY=2.7;},
    declare function = {sX=0.25;},
    declare function = {sY=0.15;},
    ]
        \begin{axis}[
            3dbaseplot,
            colormap/OrRd,
            set layers,
            ylabel={},
            samples=30,
        ]

            \myaddplotX{B}{blMuX}{sX}{white}
            \myaddplotY{C}{blMuY}{sY}{white}
            \myaddplotY{D}{orMuY}{sY}{white}
            \myaddplotX{A}{orMuX}{sX}{orange}

        \draw [dashed] (2.0-\factor*sX, 1) -- (2.0-\factor*sX, 4);
        \draw [dashed] (2.0+\factor*sX, 1) -- (2.0+\factor*sX, 4);

%% This places the text above the axis. I don't want this one.
        \node at (xticklabel cs:0.5) [above, sloped like x axis] {Temperature};

%% THIS DOES NOT APPEAR.This is the one I want.
        \node at (xticklabel cs:0.5) [below, sloped like x axis] {Temperature};

  \end{axis}
\end{tikzpicture}

\end{document}

在此处输入图片描述

答案1

我只是为了好玩才这么做的xslant

\documentclass[border=10pt]{article}
\usepackage{pgfplots}
    \usepgfplotslibrary{colorbrewer}
    \usepgfplotslibrary{fillbetween}
    \pgfplotsset{
        % Set `compat level to 1.11 or higher so you don't need to
        % prefix every tikz coordinate with `axis cs:'
        compat=1.14,
        3dbaseplot/.style={
                width           = 10cm,
            view            = {45}{65},
            axis on top,
            enlargelimits = false,
            domain          = 1:4,
            y domain       = 1:4,
            no markers,
            samples        = 30,
            xlabel          = {Temperature},
            ylabel          = {Seed Size},
            zlabel          = {Relative\\Abundance},
            xlabel style    = {sloped, at={(rel axis cs:0.5,1,1)}, above, sloped like x axis},
            ylabel style    = {sloped, at={(rel axis cs:0,0.5,1)}, above, sloped like y axis},
            zlabel style    = {rotate=-90, align=right},
            ticks               = none,
            smooth,
    },
    /pgf/declare function = {
        normal(\m,\s)=1/(2*\s*sqrt(pi))*exp(-(x-\m)^2/(2*\s^2));
    },
    /pgf/declare function = {
        bivar(\ma,\sa,\mb,\sb)=
            1/(2*pi*\sa*\sb) * exp(-((x-\ma)^2/\sa^2 + (y-\mb)^2/\sb^2))/2;
    }
}

\pgfmathsetmacro{\factor}{3}

\newcommand*\myaddplotX[4]{
    \addplot3+ [name path=#1,domain=#2-\factor*#3:#2+\factor*#3, color=#4] (x,4,{normal(#2,#3)});
}
\newcommand*\myaddplotY[4]{
    \addplot3+ [name path=#1,domain=#2-\factor*#3:#2+\factor*#3, color=#4] (1,x,{normal(#2,#3)});
}

\begin{document}

\begin{tikzpicture}[
    declare function = {orMuX=2.0;},
    declare function = {orMuY=3.2;},
    declare function = {blMuX=2.5;},
    declare function = {blMuY=2.7;},
    declare function = {sX=0.25;},
    declare function = {sY=0.15;},
    ]
        \begin{axis}[
            3dbaseplot,
            colormap/OrRd,
            set layers,
            ylabel={},
            samples=30,
        ]

            \myaddplotX{B}{blMuX}{sX}{white}
            \myaddplotY{C}{blMuY}{sY}{white}
            \myaddplotY{D}{orMuY}{sY}{white}
            \myaddplotX{A}{orMuX}{sX}{orange}

        \draw [dashed] (2.0-\factor*sX, 1) -- (2.0-\factor*sX, 4);
        \draw [dashed] (2.0+\factor*sX, 1) -- (2.0+\factor*sX, 4);

        \coordinate (A1) at (rel axis cs: 0,0,0);
        \coordinate (A2) at (rel axis cs: 1,0,0);

  \end{axis}
  \path  (A1) -- (A2) node[midway, above, sloped, xslant=.5]  {Temperature};
  \path  (A1) -- (A2) node[midway, below, sloped, xslant=.5]  {Temperature};
\end{tikzpicture}

\end{document}

演示

相关内容