Untitled

mail@pastecode.io avatar
unknown
plain_text
2 months ago
633 B
1
Indexable
Never
import matplotlib.pyplot as plt
import numpy as np

years = np.arange(2001, 2011)
production = [465, 515, 518, 467, 502, 540, 557, 571, 586, 612]

def moving_average(data, window_size):
    moving_avg = []
    for i in range(len(data) - window_size + 1):
        window = data[i:i+window_size]
        avg = sum(window) / window_size
        moving_avg.append(avg)
    return moving_avg

window_size = 4
moving_avg = moving_average(production, window_size)

plt.plot(years[window_size-1:], moving_avg)
plt.title('4-Year Moving Average of Production (2001-2010)')
plt.xlabel('Year')
plt.ylabel('Production')
plt.grid(True)
plt.show()
Leave a Comment