4
\documentclass[10pt]{article}
\usepackage{pgf,tikz,pgfplots}
\pgfplotsset{compat=1.15}
\usepackage{mathrsfs}
\usetikzlibrary{arrows}
\pagestyle{empty}
\begin{document}
\begin{tikzpicture}[holdot/.style={circle,draw,fill=white,inner sep=1pt}]
 \draw[thick,-latex] (-2,0) -- (6,0);
 \draw[thick,-latex] (0,-1) -- (0,6);
 \draw[very thick,black!50!black] (-0.8,0.2) -- (3.5,4.5) to[out=45,in=135] 
 node[pos=0.5,above,font=\large]{$f(x)$} (5,4.5);
  \draw[] (1,0) node[below] (x0) {$a$};
  \draw[](4,0) node[below] (x0) {$b$};
  \draw[very thick,dashed,gray!20!gray]  (4,0) -- (4,4.8)  
  \draw[very thick,dashed,gray!20!gray]  (1,0) -- (1,2)  
  \filldraw[fill=gray!20,draw=black] (1,0) --(
\end{tikzpicture}
\end{document}

It produces the following

enter image description here

  • How I can fill the area between a and b with a color?
  • also to include the following text: $\int_a^b f(x)dx$ ?

Thanks in advance!

6

Here is my attempt:

\documentclass{article}
 
\usepackage{tikz}
\usepackage{amsmath}
    
\begin{document}
\begin{tikzpicture}

% Filled area
  \fill[yellow](1,0) -- (1,2) -- (3.5,4.5) to[out=45,in=35] (4,4.8) -- (4,0) -- cycle;
  
  \node at (2.5,1.25) {\large $\int\limits_{a}^{b} f(x)dx$};
  
 % Axes 
 \draw[thick,-latex] (-2,0) -- (6,0);
 \draw[thick,-latex] (0,-1) -- (0,6);
 
 \draw[very thick,black] (-0.8,0.2) -- (3.5,4.5) to[out=45,in=135] node[pos=0.5,above,font=\large]{$f(x)$} (5,4.5);
 
 \draw[very thick,dashed,gray]  
 (1,0) node[below,black] {$a$} -- (1,2)
 (4,0) node[below,black] {$b$} -- (4,4.8);
  
\end{tikzpicture}

\end{document}

which yields: enter image description here

1
  • 1
    Yes, I forgot it :D, Thanks! Jul 16 '20 at 15:29
4

With pgfplots and the pgfplots library fillbetween :

\documentclass[margin=3mm]{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=1.17}
\usepgfplotslibrary{fillbetween}

\begin{document}
    \begin{tikzpicture}
\begin{axis}[
    xmin=-0.8, xmax=5.6, 
    ymin=-0.8, ymax=5.6,
    axis lines=center,
    axis line style={-latex},
    axis on top,
    ticks=none
            ]
% function
\addplot[very thick, smooth, name path=A] coordinates 
{
    (-0.8,0.2)  (3.5,4.5) (5,4.5)
} node[pos=0.9, above=2mm, font=\large]{$f(x)$};
\addplot[draw=none, name path=B] coordinates {(1,0) (4,0)};
% fill
\addplot[yellow] fill between [of = A and B, soft clip={domain=1:4}];
\node[font=\large] at (2.5,1.25) {$\int\limits_{a}^{b} f(x)dx$};
%
\draw[thick, dashed, gray]  
    (1,2.0) -- (1,0) node[below] {$a$}
    (4,4.7) -- (4,0) node[below] {$b$};
\end{axis}
    \end{tikzpicture}
\end{document}

enter image description here

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.