Skip to content

Instantly share code, notes, and snippets.

@RyotaBannai
Created December 19, 2018 16:47
Show Gist options
  • Save RyotaBannai/ec4e9d825d8f436f7f935bb916aa5e4f to your computer and use it in GitHub Desktop.
Save RyotaBannai/ec4e9d825d8f436f7f935bb916aa5e4f to your computer and use it in GitHub Desktop.
ax = plt.gca(); ax.set_xlabel('X'); ax.set_ylabel('Y')
plt.scatter(X[:, 0], X[:, 1], alpha=0.3, color="#191970")
plt.scatter(pca.mean_[0], pca.mean_[1], c='red', s=50)
plt.axis('equal')
for length, vector in zip(pca.explained_variance_, pca.components_):
dir_ = vector * 3 * np.sqrt(length)
start = pca.mean_; end = start + dir_
arrowprops = dict(arrowstyle='->',linewidth=2,
shrinkA=0, shrinkB=0, color='red', alpha=0.5)
ax.annotate('', xy=end, xytext=start, arrowprops=arrowprops)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment