From 1d2737ea2c11b4a7c533c2eedc6f198a3c4d6f7a Mon Sep 17 00:00:00 2001 From: nat-salt Date: Wed, 6 Apr 2022 18:02:49 +0100 Subject: [PATCH 1/2] updates example plot_pca_3d.py to notebook style --- examples/decomposition/plot_pca_3d.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/examples/decomposition/plot_pca_3d.py b/examples/decomposition/plot_pca_3d.py index c693cfcfa78f3..4516b27b5cb99 100644 --- a/examples/decomposition/plot_pca_3d.py +++ b/examples/decomposition/plot_pca_3d.py @@ -22,8 +22,9 @@ from scipy import stats -# ############################################################################# +# %% # Create the data +# ----------------------------------- e = np.exp(1) np.random.seed(4) @@ -51,8 +52,10 @@ def pdf(x): b /= norm -# ############################################################################# +# %% # Plot the figures +# ----------------------------------- + def plot_figs(fig_num, elev, azim): fig = plt.figure(fig_num, figsize=(4, 3)) plt.clf() From daffd42d96df5f25a735312ed03a1f91c37b1a18 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lo=C3=AFc=20Est=C3=A8ve?= Date: Fri, 8 Apr 2022 15:58:02 +0200 Subject: [PATCH 2/2] Tweaks --- examples/decomposition/plot_pca_3d.py | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/examples/decomposition/plot_pca_3d.py b/examples/decomposition/plot_pca_3d.py index 4516b27b5cb99..e539af6d66b7a 100644 --- a/examples/decomposition/plot_pca_3d.py +++ b/examples/decomposition/plot_pca_3d.py @@ -15,16 +15,13 @@ # Kevin Hughes # License: BSD 3 clause -from sklearn.decomposition import PCA +# %% +# Create the data +# --------------- import numpy as np -import matplotlib.pyplot as plt -from scipy import stats - -# %% -# Create the data -# ----------------------------------- +from scipy import stats e = np.exp(1) np.random.seed(4) @@ -54,7 +51,15 @@ def pdf(x): # %% # Plot the figures -# ----------------------------------- +# ---------------- + +from sklearn.decomposition import PCA + +import matplotlib.pyplot as plt + +# unused but required import for doing 3d projections with matplotlib < 3.2 +import mpl_toolkits.mplot3d # noqa: F401 + def plot_figs(fig_num, elev, azim): fig = plt.figure(fig_num, figsize=(4, 3))