6

I'm new to tikz and can't find a way to fill the area under this curve. Could someone help me? Here's what I wrote:

\documentclass[tikz]{standalone}

\begin{document}

\begin{tikzpicture}
\draw[-latex, thick] (-.5,0) -- (4,0) node[below] {$x$};
\draw[-latex, thick] (0,-.5) -- (0,4.5) node[left] {$t$};

\draw [cyan!40] plot [smooth] coordinates {(0,3.95) (0.5,3.90) (1,4) (1.5,3.90) (2,4) (2.5,3.90) (3,3.95)};
\draw [cyan!40, ultra thick](0,4) -- (0,0) -- (3,0) -- (3,4);
\end{tikzpicture}  

\end{document}  

enter image description here

10

You can "close" your curve by continuing it through the corners in x-axis, and use "fill" in that path.

\documentclass[tikz]{standalone}

\begin{document}

\begin{tikzpicture}
\draw[-latex, thick] (-.5,0) -- (4,0) node[below] {$x$};
\draw[-latex, thick] (0,-.5) -- (0,4.5) node[left] {$t$};

\draw [cyan!40, fill=cyan!20] plot [smooth] 
    coordinates {(0,3.95) (0.5,3.90) (1,4) (1.5,3.90) (2,4) (2.5,3.90) (3,3.95)}
     -- (3,0) -- (0,0) -- cycle;
\draw [cyan!40, ultra thick](0,4) -- (0,0) -- (3,0) -- (3,4);
\end{tikzpicture}  

\end{document}

Result

  • Is it possible, not to repeat oneself, and to have the ultra thick border included in the first \draw command by using a local scope : {[ultra thick] <remainder of the path>} ? – marsupilam Jun 24 '17 at 20:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.