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.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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.

    integral segments/.code={\pgfmathsetmacro\integralsegments{#1}},
    integral segments=3,
    integral/.style args={#1:#2}{
        ybar interval,
        x filter/.code=\pgfmathparse{\pgfmathresult-((#2-#1)/\integralsegments)/2}
\begin{tikzpicture}[/pgf/declare function={f=sin(x);}]
    axis lines=middle
\addplot [
    integral segments=20,
] {f};
\addplot [thick] {f};
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
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
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

Your Answer


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.