Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I would like to plot the shaded region between $y=\sin(x)$ and $y=0$ over $x \in [0, \pi]$ using TikZ and/or possible other packages which I don't know yet. Can you give some examples?

Specifically:

how to do the computation of the special function $\sin$?

how to specify the region in TikZ?

how to shade the region?

Thanks and regards!

share|improve this question
    
Have a look at texample.net for inspirations. –  Hendrik Vogt Dec 6 '10 at 18:13

1 Answer 1

up vote 24 down vote accepted

This is explained in the sections “15.4 Filling a Path” and “19 Plots of Functions” in the TikZ manual (numbers refer to the 2.10 version).

A simple example (note that \x r interprets \x as radians; the TikZ's sin function takes degrees as input):

\documentclass{article}
\usepackage{tikz}

\begin{document}
\begin{tikzpicture}
    \fill[fill=red] (pi/4,0) -- plot [domain=pi/4:3*pi/4] (\x,{sin(\x r)}) -- (3*pi/4,0) -- cycle;
    \draw plot[domain=0:pi] (\x,{sin(\x r)});

    \draw[gray,->] (-0.3,0) -- (pi+0.3,0);
\end{tikzpicture}
\end{document}

example

share|improve this answer
    
+1.5 for not using the built-in sin curve. –  Loop Space Dec 6 '10 at 19:31

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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