plot_y = [val * 100 for val in pca.explained_variance_ratio_] plot_x = range(1, len(plot_y) + 1) bars = plt.bar(plot_x, plot_y, align="center", color="#1C3041", edgecolor="#000000", linewidth=1.2) for bar in bars: yval = bar.get_height() plt.text(bar.get_x() + bar.get_width() / 2, yval + 0.001, f"{yval:.1f}%", ha="center", va="bottom") plt.xlabel("Principal Component") plt.ylabel("Percentage of Explained Variance") plt.title("Variance Explained per Principal Component", loc="left", fontdict={"weight": "bold"}, y=1.06) plt.grid(axis="y") plt.xticks(plot_x) plt.show()