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.

How to use sin function in pgfplots? In this post Timing and integration with TikZ PGFlots i need [/pgf/declare function={f=sin(x);}] but generate a line, and [/pgf/declare function={f=sin(x r);}] not work.

\documentclass{article}
\usepackage{pgfplots}
\begin{document}
\pgfplotsset{
    integral segments/.code={\pgfmathsetmacro\integralsegments{#1}},
    integral segments=3,
    integral/.style args={#1:#2}{
        ybar interval,
        domain=#1+((#2-#1)/\integralsegments)/2:#2+((#2-#1)/\integralsegments)/2,
        samples=\integralsegments+1,
        x filter/.code=\pgfmathparse{\pgfmathresult-((#2-#1)/\integralsegments)/2}
    }
}
\begin{tikzpicture}[/pgf/declare function={f=sin(x);}]
\begin{axis}[
    domain=0:10,
    samples=100,
    axis lines=middle
]
\addplot [
    fill=yellow,
    integral segments=20,
    integral=-6:6
] {f};
\addplot [thick] {f};
\end{axis}
\end{tikzpicture}
\end{document}
share|improve this question
    
Can you elaborate and let us know what you mean by "not work". Ideally you should compose a MWE that illustrates the problem including the \documentclass so that those trying to help don't have to recreate it. And details exactly what you have a problem with. –  Peter Grill Oct 8 '11 at 3:40
add comment

1 Answer

up vote 6 down vote accepted

If you replace /pgf/declare function={f=sin(x);} with /pgf/declare function={f=sin((x)r);}, the function plots as expected, with the x values behaving like radians. If you also change the integral domain to 0:2*pi, you get the following output:

share|improve this answer
2  
I use [/pgf/declare function={f=sin(deg(x));}]. Thanks. –  Regis da Silva Oct 8 '11 at 4:58
    
Jake: The MWE does not suggest this output you have. What else did you change around to restrict the filling to the first two regions? –  night owl Oct 8 '11 at 6:42
add comment

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.