我尝试绘制一些 3D 内容。我enlargelimits=false
在定义中使用键pgfplotsset
并将其限制domain
为 -1:1。
绘制第一个函数时,一切正常。轴正好从 -1 到 1:
但是,当我对另一张图片使用相同的样式时,似乎enlargelimits=false
没有效果:
有人能解释一下为什么会这样以及我该怎么做才能防止这种行为吗?
平均能量损失
\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
根据手册
/pgfplots/axis equal={⟨true,false⟩}
(最初false
)
每个单位向量的长度都相同,而轴尺寸保持不变。之后,x 和 y 中每个单位的尺寸比率将相同。
轴限值将被扩大以补偿缩放效果。
由 krtek 编辑
这个选项unit rescale keep size=true
正是正确的提示。谢谢。
\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}