# Fill pattern for time series with bounds (tikz pgfplots)

I would like to plot three time series; two of them have bounds. In fact, it looks similar to the figure shown here: plotting two time series with bounds

In my case, the two areas of the two time series with bounds overlap quite a bit, so the resulting image is not that easy understand. Currently, I am using this code:

\pgfplotstableread{
temps   y_h y_h__inf    y_h__sup    y_f y_f__inf    y_f__sup    y_dd

100     0.0000      0.0000      0.0000      0.0001      0.0001      0.0001      0.0001
101     0.1713      0.0000      0.3445      0.3445      0.3445      0.3445      0.3445
102     0.5007      0.0000      0.5633      0.5633      0.5633      0.5633      0.5633
103     0.6984      0.5633      0.7615      0.7513      0.6691      0.7615      0.7615
104     0.7664      0.0000      0.8981      0.8544      0.5633      0.8981      0.8981
105     0.8766      0.7615      0.9388      0.9157      0.8395      0.9660      0.9660
106     0.9225      0.6691      0.9916      0.9317      0.7615      0.9916      0.9916
107     0.9334      0.8395      0.9916      0.9016      0.6691      0.9962      0.9986
108     0.8463      0.5633      0.9986      0.8914      0.6691      0.9916      0.9999
109     0.8725      0.4521      0.9999      0.9112      0.7615      0.9916      1.0000
110     0.8306      0.0000      1.0000      0.8820      0.6691      0.9962      1.0000

}{\table}

\begin{tikzpicture}

\begin{axis}
% y_h confidence interval
\addplot [stack plots=y, fill=none, draw=none, forget plot]   table [x=temps, y=y_h__inf]   {\table} \closedcycle;
\addplot [stack plots=y, fill=red!50, opacity=0.4, draw opacity=0, area legend]   table [x=temps, y expr=\thisrow{y_h__sup}-\thisrow{y_h__inf}]   {\table} \closedcycle;
% subtract the upper bound so our stack is back at zero
\addplot [stack plots=y, stack dir=minus, forget plot, draw=none] table [x=temps, y=y_h__sup] {\table};

% y_f confidence interval
\addplot [stack plots=y, fill=none, draw=none, forget plot]   table [x=temps, y=y_f__inf]   {\table} \closedcycle;
\addplot [stack plots=y, fill=blue!50, opacity=0.4, draw opacity=0, area legend]   table [x=temps, y expr=\thisrow{y_f__sup}-\thisrow{y_f__inf}]   {\table} \closedcycle;

% the line plots (y_h and y_f)
\addplot [stack plots=false, very thick,red]  table [x=temps, y=y_h]   {\table};
\addplot [stack plots=false, very thick,blue]  table [x=temps, y=y_f]   {\table};
\addplot [stack plots=false, very thick,green]  table [x=temps, y=y_dd]   {\table}; % smooth
\end{axis}

\end{tikzpicture}


And the corresponding chart looks like that:

To distinguish the two areas better, I would like to fill one with north west lines, and the other with south west lines. However, using the "pattern" command is not excepted for the command "stack". So, my first question is how I can fill these areas with patterns.

A solution has been shown by a user as a png file (the comment of Harish below), but the user did not post the code. Does anybody know how the latex code for that?

• Like this? → i.stack.imgur.com/exbEv.png and what do you mean by "each of the values on my X axis?"? – user11232 Oct 2 '15 at 13:05
• For your second question: tex.stackexchange.com/questions/47345/… You have to use the option xtick=data as parameter in your axis environment. – Nicolás Ozimica Oct 2 '15 at 13:06
• @ Harish Kumar: Yes, beautiful. Can you post the code for that? – San Oct 3 '15 at 4:33
• @ Nicolas: Yes, that's it for the x-axis. Many thanks! – San Oct 3 '15 at 4:37
• Harish, could you post the code for the image you proposed? Thanks in advance! – San Oct 7 '15 at 3:07

Here you go. The job is simple. Load the patterns tikz library and instead of fill use pattern:

\addplot [stack plots=y, pattern=north west lines,pattern color=red!50, opacity=0.4, draw opacity=0, area legend]   table [x=temps, y expr=\thisrow{y_h__sup}-\thisrow{y_h__inf}]   {\table} \closedcycle;


MWE:

\documentclass[border=2]{standalone}
\usepackage{pgfplotstable}
\pgfplotsset{compat=1.12}
\usetikzlibrary{patterns}

temps   y_h y_h__inf    y_h__sup    y_f y_f__inf    y_f__sup    y_dd

100     0.0000      0.0000      0.0000      0.0001      0.0001      0.0001      0.0001
101     0.1713      0.0000      0.3445      0.3445      0.3445      0.3445      0.3445
102     0.5007      0.0000      0.5633      0.5633      0.5633      0.5633      0.5633
103     0.6984      0.5633      0.7615      0.7513      0.6691      0.7615      0.7615
104     0.7664      0.0000      0.8981      0.8544      0.5633      0.8981      0.8981
105     0.8766      0.7615      0.9388      0.9157      0.8395      0.9660      0.9660
106     0.9225      0.6691      0.9916      0.9317      0.7615      0.9916      0.9916
107     0.9334      0.8395      0.9916      0.9016      0.6691      0.9962      0.9986
108     0.8463      0.5633      0.9986      0.8914      0.6691      0.9916      0.9999
109     0.8725      0.4521      0.9999      0.9112      0.7615      0.9916      1.0000
110     0.8306      0.0000      1.0000      0.8820      0.6691      0.9962      1.0000

}{\table}

\begin{document}
\begin{tikzpicture}

\begin{axis}
% y_h confidence interval
\addplot [stack plots=y, fill=none, draw=none, forget plot]   table [x=temps, y=y_h__inf]   {\table} \closedcycle;
\addplot [stack plots=y, pattern=north west lines,pattern color=red!50, opacity=0.4, draw opacity=0, area legend]   table [x=temps, y expr=\thisrow{y_h__sup}-\thisrow{y_h__inf}]   {\table} \closedcycle;
% subtract the upper bound so our stack is back at zero
\addplot [stack plots=y, stack dir=minus, forget plot, draw=none] table [x=temps, y=y_h__sup] {\table};

% y_f confidence interval
\addplot [stack plots=y, fill=none, draw=none, forget plot]   table [x=temps, y=y_f__inf]   {\table} \closedcycle;
\addplot [stack plots=y, , pattern=north east lines,pattern color=blue!50, opacity=0.4, draw opacity=0, area legend]   table [x=temps, y expr=\thisrow{y_f__sup}-\thisrow{y_f__inf}]   {\table} \closedcycle;

% the line plots (y_h and y_f)
\addplot [stack plots=false, very thick,red]  table [x=temps, y=y_h]   {\table};
\addplot [stack plots=false, very thick,blue]  table [x=temps, y=y_f]   {\table};
\addplot [stack plots=false, very thick,green]  table [x=temps, y=y_dd]   {\table}; % smooth
\end{axis}

\end{tikzpicture}
\end{document}


• Thanks for your answer. Actually, I had already tried what you just suggested. However, there is some weird "behavior": I use TexMaker to compile my tex files. When using the code you suggested and compiling in TexMaker, the application-build-in viewer shows nothing (only a blank space). Now, opening the created PDF with Adobe Viewer, the graph looks correct. Opening it with Nitro PDF gives very weird colors and fillings, that change all the time when zooming in or out. The code must somehow lead to a corrupted PDF file. Any ideas what may be the problem? Many thanks, Sanjay PS: The following – San Oct 24 '15 at 6:37