如何使用 TikZ 在 3D 中绘制多个 2D 填充图形?

如何使用 TikZ 在 3D 中绘制多个 2D 填充图形?

我正在尝试在 3d 框中绘制四个 2d 图。我希望​​这些图相对于零填充。也就是说,如果线高于零,我希望它从线填充到零。如果线低于零,我希望它从零填充到线以下。我甚至无法正确填充图,似乎有一个错误,如上一篇文章所述这里

输出1

这是数据和代码:

\begin{tikzpicture}

\pgfplotstableread{
plot1     plot2     plot3     plot4
0.0045    0.0029    0.0089    0.0001
0.0040    0.0028    0.0083    0.0009
0.0035    0.0027    0.0073    0.0014
0.0029    0.0025    0.0062    0.0016
0.0024    0.0023    0.0050    0.0016
0.0019    0.0020    0.0038    0.0013
0.0014    0.0017    0.0027    0.0010
0.0010    0.0015    0.0018    0.0006
0.0007    0.0012    0.0010    0.0001
0.0004    0.0009    0.0005   -0.0004
0.0002    0.0007    0.0001   -0.0008
0.0001    0.0005   -0.0000   -0.0012
0.0000    0.0004   -0.0000   -0.0015
0.0000    0.0003    0.0001   -0.0018
0.0000    0.0002    0.0002   -0.0019
0.0001    0.0001    0.0005   -0.0021
0.0001    0.0001    0.0007   -0.0021
0.0002    0.0001    0.0009   -0.0021
0.0002    0.0000    0.0012   -0.0021
0.0002    0.0000    0.0013   -0.0021
0.0003    0.0000    0.0015   -0.0020
0.0003    0.0001    0.0016   -0.0020
0.0003    0.0001    0.0017   -0.0019
0.0003    0.0001    0.0017   -0.0018
0.0003    0.0001    0.0017   -0.0018
0.0003    0.0001    0.0017   -0.0017
0.0003    0.0001    0.0017   -0.0016
0.0003    0.0001    0.0017   -0.0016
0.0003    0.0001    0.0016   -0.0015
0.0003    0.0001    0.0016   -0.0015
0.0003    0.0001    0.0016   -0.0014
0.0003    0.0001    0.0016   -0.0014
0.0003    0.0001    0.0016   -0.0013
0.0003    0.0002    0.0015   -0.0013
0.0003    0.0002    0.0015   -0.0013
0.0003    0.0002    0.0015   -0.0012
0.0003    0.0002    0.0015   -0.0012
0.0003    0.0002    0.0015   -0.0011
0.0003    0.0002    0.0015   -0.0011
0.0003    0.0002    0.0014   -0.0010
}\dummydata
\begin{axis}[
    ytick={1,2,3,4},
    yticklabels={$\tilde{\widehat{y_t}}$, $\tilde{\widehat{c_t}}$, $\tilde{\widehat{i_t}}$, $\tilde{\widehat{z_t}}$},
    xtick={5, 15, 25, 35},
    zmin=-0.002,
    area plot/.style={
        fill opacity=0.75,
        draw=orange!80!black,thick,
        fill=orange,
        mark=none,
    }
]
\pgfplotsinvokeforeach{4,3,...,1}{
    \addplot3 [area plot] table [x expr=\coordindex, y expr=#1, z=plot#1]
      {\dummydata} \closedcycle;
}
\end{axis}
\end{tikzpicture}

答案1

正如 Christian 在上面的评论中提到的,该问题已在现已发布的 PGFPlots v1.13 中得到解决。您的示例现在无需任何更改即可运行。

另外,您的示例的简化版本也已添加到手册第 130 页的第 4.6.3 节中。

答案2

我实际上已经找到了解决这个问题的方法。我不是 Ti 方面的专家Z,但它似乎能起到一定作用。如果能用不同的颜色来做就更好了。在此处输入图片描述

\begin{tikzpicture}

\pgfplotstableread{
    plot1     plot2     plot3     plot4
    0.0045    0.0029    0.0089    0.0001
    0.0040    0.0028    0.0083    0.0009
    0.0035    0.0027    0.0073    0.0014
    0.0029    0.0025    0.0062    0.0016
    0.0024    0.0023    0.0050    0.0016
    0.0019    0.0020    0.0038    0.0013
    0.0014    0.0017    0.0027    0.0010
    0.0010    0.0015    0.0018    0.0006
    0.0007    0.0012    0.0010    0.0001
    0.0004    0.0009    0.0005   -0.0004
    0.0002    0.0007    0.0001   -0.0008
    0.0001    0.0005   -0.0000   -0.0012
    0.0000    0.0004   -0.0000   -0.0015
    0.0000    0.0003    0.0001   -0.0018
    0.0000    0.0002    0.0002   -0.0019
    0.0001    0.0001    0.0005   -0.0021
    0.0001    0.0001    0.0007   -0.0021
    0.0002    0.0001    0.0009   -0.0021
    0.0002    0.0000    0.0012   -0.0021
    0.0002    0.0000    0.0013   -0.0021
    0.0003    0.0000    0.0015   -0.0020
    0.0003    0.0001    0.0016   -0.0020
    0.0003    0.0001    0.0017   -0.0019
    0.0003    0.0001    0.0017   -0.0018
    0.0003    0.0001    0.0017   -0.0018
    0.0003    0.0001    0.0017   -0.0017
    0.0003    0.0001    0.0017   -0.0016
    0.0003    0.0001    0.0017   -0.0016
    0.0003    0.0001    0.0016   -0.0015
    0.0003    0.0001    0.0016   -0.0015
    0.0003    0.0001    0.0016   -0.0014
    0.0003    0.0001    0.0016   -0.0014
    0.0003    0.0001    0.0016   -0.0013
    0.0003    0.0002    0.0015   -0.0013
    0.0003    0.0002    0.0015   -0.0013
    0.0003    0.0002    0.0015   -0.0012
    0.0003    0.0002    0.0015   -0.0012
    0.0003    0.0002    0.0015   -0.0011
    0.0003    0.0002    0.0015   -0.0011
    0.0003    0.0002    0.0014   -0.0010
}\dummydata
\begin{axis}[
view={35}{25},
z post scale=1.3,
x post scale=1.3,
%enlargelimits=false,
%zmin=-0.0025,
zcycle=0,
ytick={1,2,3,4},
yticklabels={$\tilde{\widehat{y_t}}$, $\tilde{\widehat{c_t}}$, $\tilde{\widehat{i_t}}$, $\tilde{\widehat{h_t}}$},
xtick={5, 15, 25, 35},
area plot/.style={
    fill opacity=0.5,
    draw=blue!40!black,thick,
    fill=red!100!,
    mark=none,
},
xlabel={Periods},
zlabel={Deviation from steady state}
]
\pgfplotsinvokeforeach{4,3,2,1}{
    \addplot3[area plot] table[x expr=\coordindex, y expr=#1, z=plot#1] {\dummydata}
-- (axis cs:\pgfkeysvalueof{/pgfplots/xmax},#1,\pgfkeysvalueof{/pgfplots/zcycle})
-- (axis cs:\pgfkeysvalueof{/pgfplots/xmin},#1,\pgfkeysvalueof{/pgfplots/zcycle})
-- cycle;
}
\end{axis}
\end{tikzpicture}

相关内容