I'm creating a stacked line chart using the code below. Right now I'm plotting data from a pandas data frame. Using the code as below, I'm feeding in a list of 3 headers for variables in that df that interest me, and I'm happy with what I've got so far. However, I'd like to feed in more than 3 variables (about 80). So I'm looking for a reliable way to loop this to avoid typing in each of 80 lines, but I haven't figured it out yet.
Any simple ideas to accomplish this?
Thanks!
import matplotlib.pyplot as plt
df['Date'] = pd.to_datetime(df['Date'])
df.index = df['Date']
y1 = df[headers_list[0]].resample('m').sum()
y2 = df[headers_list[1]].resample('m').sum()
y3 = df[headers_list[2]].resample('m').sum()
x = list(range(len(y1)))
y = np.vstack([y1, y2, y3])
labels = [headers_list[0], headers_list[1], headers_list[2]]
fig, ax = plt.subplots(figsize=(20,6))
ax.stackplot(x, y1, y2, y3, labels=labels)
ax.legend(loc=2)
plt.show()