Last active
December 28, 2018 03:50
-
-
Save RyotaBannai/0f490b7132bc14e901170afaaaf56300 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from matplotlib.patches import Ellipse | |
| import matplotlib as mpl | |
| ax = plt.gca(); ax.set_xlabel('X'); ax.set_ylabel('Y') | |
| plt.scatter(X_raw[:, 0], X_raw[:, 1], c='#B8860B', alpha=0.5) | |
| plt.scatter(X_mean[0], X_mean[1], c='red', s=50) | |
| U_, s_, _ = LA.svd(np.cov(X, rowvar=False), full_matrices=False) | |
| angle = np.degrees(np.arctan2(U_[1,0], U_[0,0])) | |
| width, height = 2 * np.sqrt(s_) | |
| for nsig in range(1, 4): | |
| args = [X_mean, nsig*width, nsig*height, angle] | |
| kwargs = dict(color='#008000', alpha=1./(nsig+.5), linewidth=2, fill=False) | |
| ell = mpl.patches.Ellipse(*args, **kwargs) | |
| ell.set_clip_box(ax.bbox) | |
| ax.add_artist(ell) | |
| # Or also below works as well | |
| # ax.add_patch(Ellipse(*args,**kwargs)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment