如何使用python循环生成2004年至2015年每年的单独图?
目前,我每年都会重复编写代码,而且代码过于繁琐
plt.figure(figsize=(30,15), dpi= 80)
calmap.yearplot(df_raw1['2004']['TEU'], cmap='YlGn', fillcolor='grey',
linewidth=0) # Plot for year 2004
plt.figure(figsize=(30,15), dpi= 80)
calmap.yearplot(df_raw1['2005']['TEU'], cmap='YlGn', fillcolor='grey',
linewidth=0) # Plot for year 2005
plt.figure(figsize=(30,15), dpi= 80)
calmap.yearplot(df_raw1['2005']['TEU'], cmap='YlGn', fillcolor='grey',
linewidth=0) # Plot for year 2006
plt.figure(figsize=(30,15), dpi= 80)
calmap.yearplot(df_raw1['2007']['TEU'], cmap='YlGn', fillcolor='grey',
linewidth=0) # Plot for year 2007
plt.show()
答案 0 :(得分:0)
years = ['2004', '2005', '2006', '2007', '2008', '2009','2010', '2011', '2012', '2013', '2014', '2015']
for i in range(len(years)):
plt.figure(figsize=(30,15), dpi= 80)
calmap.yearplot(df_raw1[years[i]]['TEU'], cmap='YlGn', fillcolor='grey', linewidth=0)
plt.show()