2

I try to plot some 3D stuff. I use enlargelimits=false key in the pgfplotsset definition and restrict the domain to -1:1.

When plotting the first function, everything works fine. The axis reaches exactly from -1 to 1:

enter image description here

However, when I use the same style for another picture, it seems like the enlargelimits=false has no effect:

enter image description here

Can someone explain why this is and what I can do to prevent this behavior?


MWE

\documentclass{standalone}

\usepackage{pgfplots}

\pgfplotsset{%
  shapefunctionaxis/.style={%
    domain=-1.0:1.0,
    domain y=-1.0:1.0,
    enlargelimits=false,
    axis equal,
    xlabel=$\xi$,
    ylabel=$\eta$,
    zlabel=$N_{\i}$,
    zlabel style={rotate=-90},
    xtick distance={1.0},
    ytick distance={1.0},
    ztick distance={1.0},
    view={25}{30},% default is {25}{30}, pgfplots manual section 4.11.1
  }%
}

\begin{document}

% This works as expected:
\def\i{5}
\def\xii{0}
\def\etai{1.0}
% This does not work as expected:
%\def\i{4}
%\def\xii{-1.0}
%\def\etai{1.0}
\begin{tikzpicture}
  \begin{axis}[
    width=10cm,
    shapefunctionaxis,
  ]
    % Corner nodes
    \ifnum\ifnum\i=1 1\else\ifnum\i=2 1\else\ifnum\i=3 1\else\ifnum\i=4 1\else0\fi\fi\fi\fi%
      =1 %
      \addplot3[surf]{0.25*(1.0+\xii*x)*(1.0+\etai*y)*(\xii*x+\etai*y-1)};
    \else\fi
    % xi-edge middle nodes
    \ifnum\ifnum\i=5 1\else\ifnum\i=7 1\else0\fi\fi%
      =1 %
      \addplot3[surf]{0.5*(1.0-x*x)*(1.0+\etai*y)};
    \else\fi
    % eta-edge middle nodes
    \ifnum\ifnum\i=6 1\else\ifnum\i=8 1\else0\fi\fi%
      =1 %
      \addplot3[surf]{0.5*(1.0+\xii*x)*(1.0-y*y)};
    \else\fi
  \end{axis}
\end{tikzpicture}

\end{document}
1

According to the manual

/pgfplots/axis equal={⟨true,false⟩} (initially false)
Each unit vector is set to the same length while the axis dimensions stay constant. Afterwards, the size ratios for each unit in x and y will be the same.
Axis limits will be enlarged to compensate for the scaling effect.


Edit by krtek

The option unit rescale keep size=true was exactly the right hint. Thanks.

\documentclass{standalone}

\usepackage{pgfplots}

\pgfplotsset{%
  shapefunctionaxis/.style={%
    domain=-1.0:1.0,
    domain y=-1.0:1.0,
    enlargelimits=false,
    %axis equal,
    unit rescale keep size=true,
    xlabel=$\xi$,
    ylabel=$\eta$,
    zlabel=$N_{\i}$,
    zlabel style={rotate=-90},
    xtick distance={1.0},
    ytick distance={1.0},
    ztick distance={1.0},
    view={25}{30},% default is {25}{30}, pgfplots manual section 4.11.1
  }%
}

\begin{document}

% This works as expected:
%\def\i{5}
%\def\xii{0}
%\def\etai{1.0}
% These does not work as expected:
\def\i{4}
\def\xii{-1.0}
\def\etai{1.0}
\begin{tikzpicture}
  \begin{axis}[
    width=10cm,
    shapefunctionaxis,
  ]
    % Corner nodes
    \ifnum\ifnum\i=1 1\else\ifnum\i=2 1\else\ifnum\i=3 1\else\ifnum\i=4 1\else0\fi\fi\fi\fi%
      =1 %
      \addplot3[surf]{0.25*(1.0+\xii*x)*(1.0+\etai*y)*(\xii*x+\etai*y-1)};
    \else\fi
    % xi-edge middle nodes
    \ifnum\ifnum\i=5 1\else\ifnum\i=7 1\else0\fi\fi%
      =1 %
      \addplot3[surf]{0.5*(1.0-x*x)*(1.0+\etai*y)};
    \else\fi
    % eta-edge middle nodes
    \ifnum\ifnum\i=6 1\else\ifnum\i=8 1\else0\fi\fi%
      =1 %
      \addplot3[surf]{0.5*(1.0+\xii*x)*(1.0-y*y)};
    \else\fi
  \end{axis}
\end{tikzpicture}

\end{document}

enter image description here

  • Alright, so the problem is that the z-range is larger than 1?! Is there a possibility to only have equal x- and y-axis? – raedma Apr 13 '17 at 20:28
  • 1
    @krtek Perhaps unit rescale keep size is what you need. See the manual page 295-297. – Symbol 1 Apr 13 '17 at 20:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.