# Area under curve in pgfplots

\begin{figure}[H]
\begin{center}
\begin{tikzpicture}
\begin{axis}[xticklabels={},yticklabels={},axis x line=center, axis y
line=center, xlabel={$x$}, ylabel={$y$}, xlabel style={right}, ylabel style=
{above},ticks=none]
\end{axis}
\node [] at (3.4,0.2) {$P$};
\end{tikzpicture}
\caption{Graph of $y = (2x-1)^4$ (brown) and the tangent function (black) at
the point $(1,1)$.}
\end{center}
\end{figure}


Hi there I'm not too sure how to shade the region between the tangent function and the curve. Some help would be awesome!!!

• Welcome to TeX.SE! Off-topic: don't use center environment within figure, use \centering, see here: tex.stackexchange.com/questions/23650/… – CarLaTeX Nov 28 '18 at 6:25
• Welcome to TeX.SX!! Rather than posting code fragments it is better to give a full minimal working example. Currently we have to guess what packages etc you are using and this makes it really hard to help you. A MWE should start with a \documentclass command, have a minimal preamble and then \begin{document}...\end{document}. The code should compile and be as small as possible to demonstrate your problem. – Andrew Nov 28 '18 at 6:26

Welcome to TeX.SE! One way is to use fillbetween.

\documentclass[tikz,border=3.14mm]{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=1.16}
\usepgfplotslibrary{fillbetween}
\usetikzlibrary{backgrounds}
\begin{document}
\begin{tikzpicture}
\begin{axis}[xticklabels={},yticklabels={},axis x line=center, axis y
line=center, xlabel={$x$}, ylabel={$y$}, xlabel style={right}, ylabel style=
{above},ticks=none]
\draw[name path=axis] (0,0) -- (7/8,0);
\node [anchor=south] at (0.5,0) {$P$};
\end{axis}
\path [name path=aux1,%draw=blue,%->,fill=orange,
intersection segments={of=curve and axis,
sequence={R3[reverse]--L3}}];
\begin{scope}[on background layer]
\path [fill=orange,
intersection segments={of=aux1 and tangent,
sequence={L1--R1}}];
\end{scope}
\end{tikzpicture}
\end{document}


But in this case you can certainly do the fills without fillbetween.

\documentclass[tikz,border=3.14mm]{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=1.16}
\usetikzlibrary{backgrounds}
\begin{document}
\begin{tikzpicture}
\begin{axis}[xticklabels={},yticklabels={},axis x line=center, axis y
line=center, xlabel={$x$}, ylabel={$y$}, xlabel style={right}, ylabel style=
{above},ticks=none]
\node [anchor=south] at (0.5,0) {$P$};