4

I'm trying to use \tikzfillbetween to fill a pattern between two free handed curves, here is my code so far:

 \documentclass{article}
\usepackage{tikz}
\usepackage{pgfplots}
\usetikzlibrary{pgfplots.fillbetween}
\usetikzlibrary{patterns}
\pgfplotsset{compat=1.13}
\begin{document}

\begin{center}
\begin{tikzpicture}
\coordinate (y) at (0,4);
\coordinate (x) at (7,0);
\draw[->] (0,0)--(x) node[below]{$t$};
\draw[->] (0,0)--(y) node[left]{\scriptsize $Y,C,A$};
\draw[name path=Consume] (0,2) node[left]{\scriptsize $\overline{C}$}--(6,2);
\draw[dashed] (6,2)--(6,0) node[below]{\scriptsize $N$};
\draw[blue, name path=Income] (0,0) to [out=0,in=130] (4,3)--(4,0)--(6,0);
\draw (3.8,3.5) node[left]{\scriptsize $Y_t$};
\tikzfillbetween[of=Consume and Income]{pattern=dots};
\end{tikzpicture}
\end{center}

\end{document}

enter image description here

I need to change the color and the pattern for each diferent area and remove a warning I'm getting:

'fill between': Could not activate graphics layer 'pre main'. Filled path will be on top of the other ones. Please ensure that 'premain' is somewhere in the layer list (or set '/tikz/fill between/on layer=').

I tried to search it on the tikz manual, but I couldn't find the tikzfillbetween command. Can someone give me a hand with this or tell me where I can find the instructions for this command?

Thx!

EDIT: The warning is fixed by this:

On Preambler:

\pgfdeclarelayer{ft}
\pgfdeclarelayer{bg}
\pgfsetlayers{bg,main,ft}

On Tikz

\tikzfillbetween[of=Consume and Income, on layer=ft]

Thx again Paul and Ignasi

2
  • See p.439 of pgfplots manual: Note that this auto-activation of set layers and the installation of a clip path is done for \addplot fill between, not for the lower level drawing instructions like \tikzfillbetween or intersection segments. If you need them, you have to install a layer list manually using either set layers (if inside of an axis) or \pgfsetlayers. Jan 22, 2018 at 15:38
  • Ty Paul, I'm working on it
    – R. Nihil
    Jan 22, 2018 at 20:15

1 Answer 1

3

Like this?

enter image description here

\documentclass{article}
\usepackage{tikz}
\usepackage{pgfplots}
\usetikzlibrary{pgfplots.fillbetween}
\usetikzlibrary{patterns}
\pgfplotsset{compat=1.13}
\begin{document}

\begin{center}
\begin{tikzpicture}
\coordinate (y) at (0,4);
\coordinate (x) at (7,0);
\draw[->] (0,0)--(x) node[below]{$t$};
\draw[->] (0,0)--(y) node[left]{\scriptsize $Y,C,A$};
\draw[name path=Consume] (0,2) node[left]{\scriptsize $\overline{C}$}--(6,2);
\draw[dashed] (6,2)--(6,0) node[below]{\scriptsize $N$};
\draw[blue, name path=Income] (0,0) to [out=0,in=130] (4,3)--(4,0)--(6,0);
\draw (3.8,3.5) node[left]{\scriptsize $Y_t$};
\tikzfillbetween[of=Consume and Income,
    split,
    every even segment/.style={pattern color=orange}]{pattern=dots, pattern color=green};
\end{tikzpicture}
\end{center}

\end{document}

or this?

enter image description here

\documentclass{article}
\usepackage{tikz}
\usepackage{pgfplots}
\usetikzlibrary{pgfplots.fillbetween}
\usetikzlibrary{patterns}
\pgfplotsset{compat=1.13}
\begin{document}

\begin{center}
\begin{tikzpicture}
\coordinate (y) at (0,4);
\coordinate (x) at (7,0);
\draw[->] (0,0)--(x) node[below]{$t$};
\draw[->] (0,0)--(y) node[left]{\scriptsize $Y,C,A$};
\draw[name path=Consume] (0,2) node[left]{\scriptsize $\overline{C}$}--(6,2);
\draw[dashed] (6,2)--(6,0) node[below]{\scriptsize $N$};
\draw[blue, name path=Income] (0,0) to [out=0,in=130] (4,3)--(4,0)--(6,0);
\draw (3.8,3.5) node[left]{\scriptsize $Y_t$};
\tikzfillbetween[of=Consume and Income,
    split,
    every segment no 0/.style={pattern color=orange},
    every segment no 1/.style={pattern color=green},
    every segment no 2/.style={pattern color=blue},
    ]{pattern=dots};
\end{tikzpicture}
\end{center}

\end{document}
0

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .