我正在尝试使用表格数据构建面片图。为此,我使用pgf/tikz
、pgfplots
和pgfplotstable
命令\edef
。
我的代码:
\documentclass{standalone}
\usepackage{amsmath}
\usepackage{currfile}
\usepackage{filecontents}
\usepackage{pgfplots}
%\usepackage{showframe}
\begin{filecontents}{table.txt}
NLDefn1 NLDefn2 NLDefn3 NLDefn4 NLDefn5 NLDefn6 NLDefn7 NLDefn8 NLDefn9 NLDefn10
0.000000000000000e+00 0.000000000000000e+00 0.000000000000000e+00 0.000000000000000e+00 0.000000000000000e+00 0.000000000000000e+00 2.100000000000000e-02 4.300000000000000e-02 3.900000000000000e-02 2.000000000000000e-02
0.000000000000000e+00 0.000000000000000e+00 0.000000000000000e+00 1.000000000000000e-02 1.750000000000000e-02 1.000000000000000e-02 5.525000000000000e-02 6.700000000000000e-02 7.325000000000000e-02 5.500000000000000e-02
0.000000000000000e+00 0.000000000000000e+00 0.000000000000000e+00 1.333333333333333e-02 3.733333333333334e-02 1.333333333333333e-02 6.344444444444444e-02 6.811111111111111e-02 8.366666666666667e-02 6.333333333333334e-02
0.000000000000000e+00 0.000000000000000e+00 0.000000000000000e+00 2.487500000000000e-02 5.212500000000000e-02 2.750000000000000e-02 6.018750000000000e-02 7.137499999999999e-02 8.506250000000000e-02 5.756250000000000e-02
\end{filecontents}
\newcommand{\fillOpacity}{0.5}
\newcommand{\textOpacity}{1}
\pgfplotsset
{
patchOptsA/.style={patch,mesh,patch type=triangle,gray,ultra thin},
patchOptsB/.style={patch,patch type=triangle},
patchOptsC/.style={patch,patch type=triangle,mesh,black},
}
\tikzset
{
drawOpts/.style={gray,dashed,ultra thin},
nodeOptsA/.style={black,anchor=south,fill=white,fill opacity=0.25,text opacity=1}
}
\listfiles
\begin{document}
\noindent
\begin{tikzpicture}
\begin{axis}
[
width=0.5*210mm,
height=0.25*297mm,
%yscale=?,
axis lines=center,
xmin=-4/sqrt(3),
xmax=4/sqrt(3),
xtick=\empty,
hide x axis,
%xlabel=$x$,
ytick=\empty,
hide y axis,
%ylabel=$y$,
zmin=0,
zmax=0.1,
view={215}{10},
]
\addplot3[patchOptsA] coordinates {(0,0,0) (-1/sqrt(3),-1,0) (1/sqrt(3),-1,0)}; % Reference xy plane.
\pgfplotstablegetelem{3}{NLDefn1}\of{\currfiledir table.txt}
\edef\triangleCoordAz{\pgfplotsretval}
\pgfplotstablegetelem{3}{NLDefn2}\of{\currfiledir table.txt}
\edef\triangleCoordBz{\pgfplotsretval}
\pgfplotstablegetelem{3}{NLDefn3}\of{\currfiledir table.txt}
\edef\triangleCoordCz{\pgfplotsretval}
\addplot3[patchOptsB] coordinates {(0,0,\triangleCoordAz) ({-1/sqrt(3)},-1,\triangleCoordBz) ({1/sqrt(3)},-1,\triangleCoordCz)};
\addplot3[patchOptsC] coordinates {(0,0,\triangleCoordAz) ({-1/sqrt(3)},-1,\triangleCoordBz) ({1/sqrt(3)},-1,\triangleCoordCz)};
\addplot3[patchOptsA] coordinates {(-1/sqrt(3),-1,0) (-2/sqrt(3),-2,0) (0,-2,0)}; % Reference xy plane.
\pgfplotstablegetelem{3}{NLDefn2}\of{\currfiledir table.txt}
\edef\triangleCoordAz{\pgfplotsretval}
\pgfplotstablegetelem{3}{NLDefn4}\of{\currfiledir table.txt}
\edef\triangleCoordBz{\pgfplotsretval}
\pgfplotstablegetelem{3}{NLDefn5}\of{\currfiledir table.txt}
\edef\triangleCoordCz{\pgfplotsretval}
\addplot3[patchOptsB] coordinates {(-1/sqrt(3),-1,\triangleCoordAz) (-2/sqrt(3),-2,\triangleCoordBz) (0,-2,\triangleCoordCz)};
\addplot3[patchOptsC] coordinates {(-1/sqrt(3),-1,\triangleCoordAz) (-2/sqrt(3),-2,\triangleCoordBz) (0,-2,\triangleCoordCz)};
\addplot3[patchOptsA] coordinates {(-1/sqrt(3),-1,0) (0,-2,0) (1/sqrt(3),-1,0)}; % Reference xy plane.
\pgfplotstablegetelem{3}{NLDefn2}\of{\currfiledir table.txt}
\edef\triangleCoordAz{\pgfplotsretval}
\pgfplotstablegetelem{3}{NLDefn5}\of{\currfiledir table.txt}
\edef\triangleCoordBz{\pgfplotsretval}
\pgfplotstablegetelem{3}{NLDefn3}\of{\currfiledir table.txt}
\edef\triangleCoordCz{\pgfplotsretval}
\addplot3[patchOptsB] coordinates {(-1/sqrt(3),-1,\triangleCoordAz) (0,-2,\triangleCoordBz) (1/sqrt(3),-1,\triangleCoordCz)};
\addplot3[patchOptsC] coordinates {(-1/sqrt(3),-1,\triangleCoordAz) (0,-2,\triangleCoordBz) (1/sqrt(3),-1,\triangleCoordCz)};
\addplot3[patchOptsA] coordinates {(1/sqrt(3),-1,0) (0,-2,0) (2/sqrt(3),-2,0)}; % Reference xy plane.
\pgfplotstablegetelem{3}{NLDefn3}\of{\currfiledir table.txt}
\edef\triangleCoordAz{\pgfplotsretval}
\pgfplotstablegetelem{3}{NLDefn5}\of{\currfiledir table.txt}
\edef\triangleCoordBz{\pgfplotsretval}
\pgfplotstablegetelem{3}{NLDefn6}\of{\currfiledir table.txt}
\edef\triangleCoordCz{\pgfplotsretval}
\addplot3[patchOptsB] coordinates {(1/sqrt(3),-1,\triangleCoordAz) (0,-2,\triangleCoordBz) (2/sqrt(3),-2,\triangleCoordCz)};
\addplot3[patchOptsC] coordinates {(1/sqrt(3),-1,\triangleCoordAz) (0,-2,\triangleCoordBz) (2/sqrt(3),-2,\triangleCoordCz)};
% Dashed lines and nodes of triangle.
\pgfplotstablegetelem{3}{NLDefn1}\of{\currfiledir table.txt}
\edef\CoordZ{\pgfplotsretval}
\draw[drawOpts] (axis cs:0,0,0)--(axis cs:0,0,\CoordZ);
\fill[gray] (axis cs:0,0,\CoordZ) circle (1pt) node[nodeOptsA] {$1$};
\pgfplotstablegetelem{3}{NLDefn2}\of{\currfiledir table.txt}
\edef\CoordZ{\pgfplotsretval}
\draw[drawOpts] (axis cs:{-1/sqrt(3)},-1,0)--(axis cs:{-1/sqrt(3)},-1,\CoordZ);
\fill[gray] (axis cs:{-1/sqrt(3)},-1,\CoordZ) circle (1pt) node[nodeOptsA] {$x$};
\pgfplotstablegetelem{3}{NLDefn3}\of{\currfiledir table.txt}
\edef\CoordZ{\pgfplotsretval}
\draw[drawOpts] (axis cs:{1/sqrt(3)},-1,0)--(axis cs:{1/sqrt(3)},-1,\CoordZ);
\fill[gray] (axis cs:{1/sqrt(3)},-1,\CoordZ) circle (1pt) node[nodeOptsA] {$y$};
\pgfplotstablegetelem{3}{NLDefn4}\of{\currfiledir table.txt}
\edef\CoordZ{\pgfplotsretval}
\draw[drawOpts] (axis cs:{-2/sqrt(3)},-2,0)--(axis cs:{-2/sqrt(3)},-2,\CoordZ);
\fill[gray] (axis cs:{-2/sqrt(3)},-2,\CoordZ) circle (1pt) node[nodeOptsA] {$x^2$};
\pgfplotstablegetelem{3}{NLDefn5}\of{\currfiledir table.txt}
\edef\CoordZ{\pgfplotsretval}
\draw[drawOpts] (axis cs:0,-2,0)--(axis cs:0,-2,\CoordZ);
\fill[gray] (axis cs:0,-2,\CoordZ) circle (1pt) node[nodeOptsA] {$xy$};
\pgfplotstablegetelem{3}{NLDefn6}\of{\currfiledir table.txt}
\edef\CoordZ{\pgfplotsretval}
\draw[drawOpts] (axis cs:{2/sqrt(3)},-2,0)--(axis cs:{2/sqrt(3)},-2,\CoordZ);
\fill[gray] (axis cs:{2/sqrt(3)},-2,\CoordZ) circle (1pt) node[nodeOptsA] {$y^2$};
\end{axis}
\draw[dashed] (current bounding box.south west) rectangle (current bounding box.north east);
\end{tikzpicture}
\end{document}
结果如下:
生成的虚线没有像我希望的那样垂直于三角形的节点,而且这些node
实例的文本也不在三角形节点处。我想我可能\edef
以错误的方式使用了该命令。
我该如何解决?
答案1
错误描述似乎是由于在 pgfplots 环境中使用\draw
和造成的。替换\fill
axis
\draw[drawOptsA] (axis cs:0,0,0)--(axis cs:0,0,\coordZ);
\fill[gray] (axis cs:0,0,\coordZ) circle (1pt) node[nodeOptsA] {$1$};
命令
\addplot3[drawOpts] coordinates{(0,0,0) (0,0,\CoordZ)} node[nodeOptsA] {$1$};
并将更改drawOptsA
为
drawOptsA/.style={gray,dashed,ultra thin,mark=*,mark size=1pt}
我们得到了想要的结果:
为了清楚起见,以下是更正后的代码:
\documentclass{standalone}
\usepackage{amsmath}
\usepackage{currfile}
\usepackage{filecontents}
\usepackage{pgfplots}
\begin{filecontents}{table.txt}
NLDefn1 NLDefn2 NLDefn3 NLDefn4 NLDefn5 NLDefn6 NLDefn7 NLDefn8 NLDefn9 NLDefn10
0.000000000000000e+00 0.000000000000000e+00 0.000000000000000e+00 0.000000000000000e+00 0.000000000000000e+00 0.000000000000000e+00 2.100000000000000e-02 4.300000000000000e-02 3.900000000000000e-02 2.000000000000000e-02
0.000000000000000e+00 0.000000000000000e+00 0.000000000000000e+00 1.000000000000000e-02 1.750000000000000e-02 1.000000000000000e-02 5.525000000000000e-02 6.700000000000000e-02 7.325000000000000e-02 5.500000000000000e-02
0.000000000000000e+00 0.000000000000000e+00 0.000000000000000e+00 1.333333333333333e-02 3.733333333333334e-02 1.333333333333333e-02 6.344444444444444e-02 6.811111111111111e-02 8.366666666666667e-02 6.333333333333334e-02
0.000000000000000e+00 0.000000000000000e+00 0.000000000000000e+00 2.487500000000000e-02 5.212500000000000e-02 2.750000000000000e-02 6.018750000000000e-02 7.137499999999999e-02 8.506250000000000e-02 5.756250000000000e-02
\end{filecontents}
\newcommand{\fillOpacity}{0.5}
\newcommand{\textOpacity}{1}
\pgfplotsset
{
patchOptsA/.style={patch,mesh,patch type=triangle,gray,ultra thin},
patchOptsB/.style={patch,patch type=triangle},
patchOptsC/.style={patch,patch type=triangle,mesh,black},
}
\tikzset
{
drawOptsA/.style={gray,dashed,ultra thin,mark=*,mark size=1pt},
nodeOptsA/.style={black,anchor=south,fill=white,fill opacity=0.25,text opacity=1}
}
\listfiles
\begin{document}
\noindent
\begin{tikzpicture}
\begin{axis}
[
width=0.5*210mm,
height=0.25*297mm,
%yscale=?,
axis lines=center,
xmin=-4/sqrt(3),
xmax=4/sqrt(3),
xtick=\empty,
hide x axis,
%xlabel=$x$,
ytick=\empty,
hide y axis,
%ylabel=$y$,
zmin=0,
zmax=0.1,
view={215}{10},
]
\addplot3[patchOptsA] coordinates {(0,0,0) (-1/sqrt(3),-1,0) (1/sqrt(3),-1,0)}; % Reference xy plane.
\pgfplotstablegetelem{3}{NLDefn1}\of{\currfiledir batch_output_tol=1e-6_ef=poly0-3.txt}
\edef\triangleCoordAz{\pgfplotsretval}
\pgfplotstablegetelem{3}{NLDefn2}\of{\currfiledir table.txt}
\edef\triangleCoordBz{\pgfplotsretval}
\pgfplotstablegetelem{3}{NLDefn3}\of{\currfiledir table.txt}
\edef\triangleCoordCz{\pgfplotsretval}
\addplot3[patchOptsB] coordinates {(0,0,\triangleCoordAz) ({-1/sqrt(3)},-1,\triangleCoordBz) ({1/sqrt(3)},-1,\triangleCoordCz)};
\addplot3[patchOptsC] coordinates {(0,0,\triangleCoordAz) ({-1/sqrt(3)},-1,\triangleCoordBz) ({1/sqrt(3)},-1,\triangleCoordCz)};
\addplot3[patchOptsA] coordinates {(-1/sqrt(3),-1,0) (-2/sqrt(3),-2,0) (0,-2,0)}; % Reference xy plane.
\pgfplotstablegetelem{3}{NLDefn2}\of{\currfiledir table.txt}
\edef\triangleCoordAz{\pgfplotsretval}
\pgfplotstablegetelem{3}{NLDefn4}\of{\currfiledir table.txt}
\edef\triangleCoordBz{\pgfplotsretval}
\pgfplotstablegetelem{3}{NLDefn5}\of{\currfiledir table.txt}
\edef\triangleCoordCz{\pgfplotsretval}
\addplot3[patchOptsB] coordinates {(-1/sqrt(3),-1,\triangleCoordAz) (-2/sqrt(3),-2,\triangleCoordBz) (0,-2,\triangleCoordCz)};
\addplot3[patchOptsC] coordinates {(-1/sqrt(3),-1,\triangleCoordAz) (-2/sqrt(3),-2,\triangleCoordBz) (0,-2,\triangleCoordCz)};
\addplot3[patchOptsA] coordinates {(-1/sqrt(3),-1,0) (0,-2,0) (1/sqrt(3),-1,0)}; % Reference xy plane.
\pgfplotstablegetelem{3}{NLDefn2}\of{\currfiledir table.txt}
\edef\triangleCoordAz{\pgfplotsretval}
\pgfplotstablegetelem{3}{NLDefn5}\of{\currfiledir table.txt}
\edef\triangleCoordBz{\pgfplotsretval}
\pgfplotstablegetelem{3}{NLDefn3}\of{\currfiledir table.txt}
\edef\triangleCoordCz{\pgfplotsretval}
\addplot3[patchOptsB] coordinates {(-1/sqrt(3),-1,\triangleCoordAz) (0,-2,\triangleCoordBz) (1/sqrt(3),-1,\triangleCoordCz)};
\addplot3[patchOptsC] coordinates {(-1/sqrt(3),-1,\triangleCoordAz) (0,-2,\triangleCoordBz) (1/sqrt(3),-1,\triangleCoordCz)};
\addplot3[patchOptsA] coordinates {(1/sqrt(3),-1,0) (0,-2,0) (2/sqrt(3),-2,0)}; % Reference xy plane.
\pgfplotstablegetelem{3}{NLDefn3}\of{\currfiledir table.txt}
\edef\triangleCoordAz{\pgfplotsretval}
\pgfplotstablegetelem{3}{NLDefn5}\of{\currfiledir table.txt}
\edef\triangleCoordBz{\pgfplotsretval}
\pgfplotstablegetelem{3}{NLDefn6}\of{\currfiledir table.txt}
\edef\triangleCoordCz{\pgfplotsretval}
\addplot3[patchOptsB] coordinates {(1/sqrt(3),-1,\triangleCoordAz) (0,-2,\triangleCoordBz) (2/sqrt(3),-2,\triangleCoordCz)};
\addplot3[patchOptsC] coordinates {(1/sqrt(3),-1,\triangleCoordAz) (0,-2,\triangleCoordBz) (2/sqrt(3),-2,\triangleCoordCz)};
% Dashed lines and nodes of triangle.
\pgfplotstablegetelem{3}{NLDefn1}\of{\currfiledir batch_output_tol=1e-4_ef=poly0-3.txt}
\edef\coordZ{\pgfplotsretval}
\addplot3[drawOptsA] coordinates{(0,0,0) (0,0,\coordZ)} node[nodeOptsA]{$1$};
\pgfplotstablegetelem{3}{NLDefn2}\of{\currfiledir batch_output_tol=1e-4_ef=poly0-3.txt}
\edef\coordZ{\pgfplotsretval}
\addplot3[drawOptsA] coordinates{({-1/sqrt(3)},-1,0) ({-1/sqrt(3)},-1,\coordZ)} node[nodeOptsA] {$x$};
\pgfplotstablegetelem{3}{NLDefn3}\of{\currfiledir batch_output_tol=1e-4_ef=poly0-3.txt}
\edef\coordZ{\pgfplotsretval}
\addplot3[drawOptsA] coordinates{({1/sqrt(3)},-1,0) ({1/sqrt(3)},-1,\coordZ)} node[nodeOptsA] {$y$};
\pgfplotstablegetelem{3}{NLDefn4}\of{\currfiledir batch_output_tol=1e-4_ef=poly0-3.txt}
\edef\coordZ{\pgfplotsretval}
\addplot3[drawOptsA] coordinates{({-2/sqrt(3)},-2,0) ({-2/sqrt(3)},-2,\coordZ)} node[nodeOptsA] {$x^2$};
\pgfplotstablegetelem{3}{NLDefn5}\of{\currfiledir batch_output_tol=1e-4_ef=poly0-3.txt}
\edef\coordZ{\pgfplotsretval}
\addplot3[drawOptsA] coordinates{(0,-2,0) (0,-2,\coordZ)} node[nodeOptsA] {$xy$};
\pgfplotstablegetelem{3}{NLDefn6}\of{\currfiledir batch_output_tol=1e-4_ef=poly0-3.txt}
\edef\coordZ{\pgfplotsretval}
\addplot3[drawOptsA] coordinates{({2/sqrt(3)},-2,0) ({2/sqrt(3)},-2,\coordZ)} node[nodeOptsA] {$y^2$};
\end{axis}
\draw[dashed] (current bounding box.south west) rectangle (current bounding box.north east);
\end{tikzpicture}
\end{document}