Cumulative sum `cumsum`

import matplotlib.pyplot as plt
import numpy as np
v = sorted(np.arange(0,10), reverse=True)
tot = sum(v)
plt.bar(range(0, 10), v/tot, alpha=0.5, align='center')
plt.step(range(0, 10), np.cumsum(v)/tot, where='mid')
plt.ylabel('Explained variance ratio')
plt.xlabel('Principal components')

plt.show()

png