There is a example in sklearn.metrics.average_precision_score documentation.

import numpy as np
from sklearn.metrics import average_precision_score
y_true = np.array([0, 0, 1, 1])
y_scores = np.array([0.1, 0.4, 0.35, 0.8])
average_precision_score(y_true, y_scores)
0.83


But when I plot precision_recall_curve

precision, recall, _ = precision_recall_curve(y_true, y_scores)
plt.plot( recall,precision)


I got the picture:

why the area under the precision_recall_curve is not 0.83?

According to the documentation, the value is not exactly the area under curve, it is $$\text{AP} = \sum_n(R_n - R_{n-1})P_n.$$ which is a rectangular approximation.

      R     P

it is calculated as \begin{align*} \text{AP} & = \overbrace{(0.5 - 0.0)\times1.0}^{(R_2 - R_1)P_2} + \overbrace{(0.5 - 0.5)\times 0.5}^{(R_3 - R_2)P_3} + \overbrace{(1.0 - 0.5) \times0.66}^{(R_4 - R_3)P_4} \\ &= 0.5 + 0.00+ 0.33 = 0.83 \end{align*} which is the area under the red curve as illustrated below:
compared to $$\text{AUPR}=0.5 + \overbrace{\frac{0.5 + 0.66}{2} \times 0.5}^{\text{trapezoid area}} = 0.79$$ which is the area under the blue curve.