我想要实现一个包含堆叠的二维层的三维图形,以下是示例: 我使用了以下代码和一个主文件:
\documentclass{article}
\usepackage{standalone}
\usepackage{tikz}
\usetikzlibrary{external}
\usepackage{pgfplotstable}
\usepackage{pgfplots}
\usepackage{tikzscale}
\pgfplotsset{compat=1.17}
\begin{filecontents*}{file1.dat}
x y
0 0
1 1
2 2
3 3
4 4
5 5
\end{filecontents*}
\begin{filecontents*}{file2.dat}
x y
0 0
1 4
2 6
3 8
4 10
5 12
\end{filecontents*}
\usepackage{subcaption}
\tikzexternalize[prefix=tikz-cache/]
\tikzset{external/force remake}
\usetikzlibrary{pgfplots.groupplots}
\pgfplotsset{every axis/.append style={
label style={font=\footnotesize\bfseries},
tick label style={font=\footnotesize},
legend style={font=\footnotesize}
},
area plot/.style={
fill opacity=1,
draw=black!50!black,
fill=white,
mark=none,
},
y axis/.append style={align=center}}
\tikzset{Line Label/.style={font=\footnotesize,scale=2}}
\newcommand{\figurefontsize}{\footnotesize}
\begin{document}
\begin{figure}[htpb]
\centering
\includegraphics[width=.5\linewidth]{sub.tikz}
\caption{Image I}
\end{figure}
\end{document}
和 tikz 文件sub.tikz
:
\pgfplotstableread{file1.dat}{\tablea}
\pgfplotstableread{file2.dat}{\tableb}
\tikzsetnextfilename{sub}
\begin{tikzpicture}
\begin{axis}[
ymin=0, ymax=30,
xmin=0, xmax=5,
xlabel={$x$},
ylabel={$y$},
grid=major,
legend entries={\(y_1\),\(y_2\),\(y_1+y_2\)},
legend pos = north west
]
% Select appropriate columns
\addplot3 [area plot, ultra thick, red] table [x=x, y expr=2, z=y] {\tableb}\closedcycle;
\addplot3 [area plot, ultra thick, blue] table [x=x, y expr=1, z=y] {\tablea} \closedcycle;
\end{axis}
\end{tikzpicture}
现在,在编译时,无论我是否使用,图形都不会改变大小
\includegraphics[width=5\linewidth]{sub.tikz}
或者
\includegraphics[width=.5\linewidth]{sub.tikz}
如果我有 2d 数据,同样的方法也有效。为什么当前方法会失败?