3

I am trying to plot four 2d plots in a 3d box. I want these plots to be filled with respect to zero. That is, if the line is above zero, I want it to be filled from the line until zero. If the line dips below zero, I want it to be filled below zero, until the line. I cannot even manage to fill the plots correctly, there seems to be a bug, as discussed in a previous post here.

output1

This is the data and code:

\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}
Stefan Pinnow
  • 29,535
  • The fact that (a) \closedcycle is currently useless for 3d axes and (b) there is a unique meaning for it (at least for line plots in 3d), I decided to add support for such applications to pgfplots. As of pgfplots 1.13 (not released at the time of this writing), your example will work without any changes (as does the linked question). – Christian Feuersänger Dec 31 '15 at 17:10
  • Would you mind if I add your example to the pgfplots manual? – Christian Feuersänger Dec 31 '15 at 17:11
  • 1
    That would be great, happy to contribute one way or another. And very happy that this feature can be resolved. – Sophia-Goose Jan 02 '16 at 00:11
  • Please add your own answer here as this will help others as well. I will add another answer once pgfplots 1.13 is available in the TeX repositories. If you have difficulties with the color schemes, you can ask a follow-up question in order to address these issues as well. – Christian Feuersänger Jan 02 '16 at 10:58

2 Answers2

4

As Christian has mentioned in one of the comments above, the issue is solved in the now released v1.13 of PGFPlots. Your example now works without any changes.

Also a reduced variant of your example is added to the manual in section 4.6.3 on page 130.

Stefan Pinnow
  • 29,535
  • Welcome to TeX.SX! While this is true it's more like a comment than an answer –  Jan 09 '16 at 16:25
  • 1
    Well, the answer is "upgrade pgfplots to v 1.13 or newer and it works without modifications". If that is not a valid answer, the question is no longer a valid question (which is true since the issue is solved -- provided users have the correct version). I would vote to keep the answer as-is since it identifies the question as "this is a fixed bug" and provides the fixed version. – Christian Feuersänger Jan 09 '16 at 17:22
  • You are welcome. When you think, that "not modifying the code from your question" is better than your privided solution, please think of changing the accepted answer to the "better" solution (see here). – Stefan Pinnow Feb 06 '16 at 01:31
1

I have actually found a way to work around this. I am no expert on TikZ, but it seems to somewhat do the job. It would be great to do it with different colors.enter image description here

\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}