//------------------------------------------------------------
// Plot the sequence of reconstructions
fig = plt.figure(figsize=(8, 8))
fig.subplots_adjust(hspace=0)
for i, n in enumerate([0, 4, 8, 20]):
ax = fig.add_subplot(411 + i)
ax.plot(wavelengths, spec, "-", c="gray")
After Change
// Adjust font sizes for text
import matplotlib
matplotlib.rc("font", size=8)
//------------------------------------------------------------
// Download data
data = sdss_corrected_spectra.fetch_sdss_corrected_spectra()
spectra = sdss_corrected_spectra.reconstruct_spectra(data)
wavelengths = sdss_corrected_spectra.compute_wavelengths(data)
//------------------------------------------------------------
// Compute PCA components
// Eigenvalues can be computed using PCA as in the commented code below:
//from sklearn.decomposition import PCA
//pca = PCA()
//pca.fit(spectra)
//evals = pca.explained_variance_ratio_
//evals_cs = evals.cumsum()
// because the spectra have been reconstructed from masked values, this
// is not exactly correct in this case: we"ll use the values computed
// in the file compute_sdss_pca.py
evals = data["evals"] ** 2
evals_cs = evals.cumsum()
evals_cs /= evals_cs[-1]
evecs = data["evecs"]
spec_mean = spectra.mean(0)
//------------------------------------------------------------
// Find the coefficients of a particular spectrum
spec = spectra[1]
coeff = np.dot(evecs, spec - spec_mean)
//------------------------------------------------------------
// Plot the sequence of reconstructions
fig = plt.figure(figsize=(5, 5))
fig.subplots_adjust(hspace=0, top=0.95, bottom=0.1, left=0.12, right=0.93)
for i, n in enumerate([0, 4, 8, 20]):
ax = fig.add_subplot(411 + i)
ax.plot(wavelengths, spec, "-", c="gray")