3

For the figure below, I need show two labels for the x-axis, as shown. The problem is that I need the lower Temperature label to appear where "HERE" is in the figure. I can use above to place the text above the node position but the axis label does not appear when I use below. If I omit above or below from the node position, then the upper half of the text appears on top of the axis line.

I followed the answer from this post but there is one important difference (as far as I can tell). I have set my default axis labels to be above the graph, with the secondary labels below the graph.

This is one of a series of graphs. I am "building" the graph one item at a time to orient my students. I want to temporarily add the additional x-axis label for orientation purposes. The next graph will do the same thing for a second variable (seed size). The remaining figures would have the labels only above the graph.

\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}

enter image description here

3
  • 1
    Try adding clip mode=individual to the axis options, by default anything outside axis boundaries are clipped away. Nov 16, 2016 at 14:24
  • Another option is to create named coordinates inside the axis environment and to add labels etc. after \end{axis}. Nov 16, 2016 at 15:17
  • @TorbjørnT. This was the quickest solution for me and the one I used. It also introduced me to \pgfkeysgetvalue{/pgfplots/xmin}, et al. because clipping revealed to me that my dashed lines when outside the plot. So, I learned two things for the price of one! Thanks. Nov 17, 2016 at 9:09

1 Answer 1

2

I threw in the xslant just for fun.

\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}

demo

1
  • As noted above, I used the suggestion of @TorbjørnT. I learned from yours and will probably incorporate some ideas into future macros. +1 for xslant! Thanks. Nov 17, 2016 at 9:14

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .