exp_var = [val * 100 for val in pca.explained_variance_ratio_] plot_y = [sum(exp_var[:i+1]) for i in range(len(exp_var))] plot_x = range(1, len(plot_y) + 1) plt.plot(plot_x, plot_y, marker="o", color="#9B1D20") for x, y in zip(plot_x, plot_y): plt.text(x, y + 1.5, f"{y:.1f}%", ha="center", va="bottom") plt.xlabel("Principal Component") plt.ylabel("Cumulative Percentage of Explained Variance") plt.title("Cumulative Variance Explained per Principal Component", loc="left", fontdict={"weight": "bold"}, y=1.06) plt.yticks(range(0, 101, 5)) plt.grid(axis="y") plt.xticks(plot_x) plt.show()