Polynomial fit to z-scores

import numpy as np import matplotlib.pyplot as plt seq = np.array([13, 18, 22, 26, 17, 35, 27, 29, 21, 33, 38, 19, 26, 28, 22, 32, 28, 24, 17, 19, 20]) seq_mean, seq_std = np.mean(seq), np.std(seq) # Z-scores tell us how many standard deviations away from the mean a value is z_scores = [(s - seq_mean) / seq_std for s in seq] z_score_range = range(len(z_scores)) p_low_deg = np.poly1d(np.polyfit(z_score_range, z_scores, 3)) p_high_deg = np.poly1d(np.polyfit(z_score_range, z_scores, len(seq)-1)) plt.axhline(0, ls='--', lw=0.4, color='black', alpha=0.5) plt.title('Fitting a low- and high degree polynomial\nto the z-scores obtained from a sequence') plt.plot(z_score_range, z_scores, '.', markersize=6, markeredgecolor='black', markeredgewidth=0.4, color='#DDDDDD', ) plt.plot(z_score_range, p_low_deg(z_score_range), '-', color='#FFC933', lw=3, alpha=0.5, label='low degree') plt.plot(z_score_range, p_high_deg(z_score_range), '-', color='#0028B2', lw=3, alpha=0.3, label='high degree') plt.legend(loc='best', frameon=False) plt.tight_layout() plt.show() Polynomial fit to z-scores