Coloring an area between two curves

I try to color the area like the picture

Coloring an area between two curves

    \documentclass[tikz,11pt]{standalone}     \usepackage[utf8]{inputenc}     \usepackage[T1]{fontenc}     \usepackage{pgfplots}     \usepgfplotslibrary{fillbetween}     \usetikzlibrary[arrows.meta,bending]     \usetikzlibrary{shapes.geometric,positioning,shapes}     \pgfplotsset{compat=newest}      \definecolor{mycolor}{RGB}{139,0,0}     \definecolor{water}{RGB}{123,158,200}      \begin{document}      \begin{tikzpicture}[/pgf/declare function={f=sin((x)r);}]      \begin{axis}     [restrict x to domain=-8:4, xmax=4, xmin=-8,      restrict y to domain=-1:5, ymax=5, ymin=-1,      x=1cm,      y=1cm,      hide y axis,      hide x axis,      samples=5000,      >=stealth,]      \addplot [name path=P,line width=1,smooth,domain=-5.3:3.2]  {0.25*x^2+0.5*x-0.25};      \draw[decorate,decoration=   {snake,amplitude=0.12mm},water,thick](axis cs:-4.4641,2.5)--(axis cs:2.4641,2.5);      \draw [thick,->](axis cs:-3,0)--(axis cs:3,0);      \draw [thick,->](axis cs:-2,-0.5)--(axis cs:-2,5);      \fill[mycolor](axis cs: -2,-0.25) rectangle (axis cs:-1.9,3.5);      \draw[thick,<->](axis cs:-3,0.5)--(axis cs:-2,0.5);      \draw[thick,<->](axis cs:-4,1.75)--(axis cs:-2,1.75);      \draw[thick,<->](axis cs:-5,3.5)--(axis cs:-2,3.5);      \node[above] at (axis cs:-3.5,3.5){3 m};      \node[above] at (axis cs:-3,1.75){2 m};      \node[above] at (axis cs:-2.5,0.5){1 m};      \node[right] at (axis cs:-2,0.2){\small O};      \node[left] at (axis cs:-3,0.5){A};      \node[left] at (axis cs:-4,1.75){N};      \node[left] at (axis cs:-5,3.5){M};       \node[right] at (axis cs:-1.9,0.5){0,5 m};      \node[right] at (axis cs:-1.9,1.75){1,75 m};      \node[right] at (axis cs:-1.9,3.5){3,5 m};      \node[right] at (axis cs:-1.9,2.8){Bâton};      \node[draw,anchor=west] at (axis cs:-7,0.5){Août};      \node[draw,anchor=west] at (axis cs:-7,1.75){Novembre};      \node[draw,anchor=west] at (axis cs:-7,3.5){Mars};      \node[anchor= east] at (axis cs:-3.1,0){Grande sécheresse};       \end{axis}       \end{tikzpicture}       \end{document} 

Coloring an area between two curves

Replay

You were very nearly there, just add name path=W to the line drawing the water surface, and something like

 \addplot [fill=blue!10] fill between[of=P and W];

right after it.

Coloring an area between two curves

\documentclass[tikz,11pt]{standalone}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{pgfplots}
\usepgfplotslibrary{fillbetween}
\usetikzlibrary[arrows.meta,bending]
\usetikzlibrary{shapes.geometric,positioning,shapes}
\pgfplotsset{compat=newest}

\definecolor{mycolor}{RGB}{139,0,0}
\definecolor{water}{RGB}{123,158,200}

\begin{document}

\begin{tikzpicture}[/pgf/declare function={f=sin((x)r);}]

\begin{axis}
[restrict x to domain=-8:4, xmax=4, xmin=-8,
 restrict y to domain=-1:5, ymax=5, ymin=-1,
 x=1cm,
 y=1cm,
 hide y axis,
 hide x axis,
 samples=5000,
 >=stealth,]
 \addplot [name path=P,line width=1,smooth,domain=-5.3:3.2]  {0.25*x^2+0.5*x-0.25};
 \draw[name path=W,decorate,decoration=   {snake,amplitude=0.12mm},water,thick](axis cs:-4.4641,2.5)--(axis cs:2.4641,2.5);
 \addplot [fill=blue!10] fill between[of=P and W];
 \draw [thick,->](axis cs:-3,0)--(axis cs:3,0);
 \draw [thick,->](axis cs:-2,-0.5)--(axis cs:-2,5);
 \fill[mycolor](axis cs: -2,-0.25) rectangle (axis cs:-1.9,3.5);
 \draw[thick,<->](axis cs:-3,0.5)--(axis cs:-2,0.5);
 \draw[thick,<->](axis cs:-4,1.75)--(axis cs:-2,1.75);
 \draw[thick,<->](axis cs:-5,3.5)--(axis cs:-2,3.5);
 \node[above] at (axis cs:-3.5,3.5){3 m};
 \node[above] at (axis cs:-3,1.75){2 m};
 \node[above] at (axis cs:-2.5,0.5){1 m};
 \node[right] at (axis cs:-2,0.2){\small O};
 \node[left] at (axis cs:-3,0.5){A};
 \node[left] at (axis cs:-4,1.75){N};
 \node[left] at (axis cs:-5,3.5){M};
 \node[right] at (axis cs:-1.9,0.5){0,5 m};
 \node[right] at (axis cs:-1.9,1.75){1,75 m};
 \node[right] at (axis cs:-1.9,3.5){3,5 m};
 \node[right] at (axis cs:-1.9,2.8){Bâton};
 \node[draw,anchor=west] at (axis cs:-7,0.5){Août};
 \node[draw,anchor=west] at (axis cs:-7,1.75){Novembre};
 \node[draw,anchor=west] at (axis cs:-7,3.5){Mars};
 \node[anchor= east] at (axis cs:-3.1,0){Grande sécheresse};

 \end{axis}

 \end{tikzpicture}

 \end{document}

Category: pgfplots Time: 2016-07-31 Views: 2
Tags: pgfplots

Related post

iOS development

Android development

Python development

JAVA development

Development language

PHP development

Ruby development

search

Front-end development

Database

development tools

Open Platform

Javascript development

.NET development

cloud computing

server

Copyright (C) avrocks.com, All Rights Reserved.

processed in 0.129 (s). 12 q(s)