def create_linegraph(uid,index_type,index_values, fieldid): import matplotlib.pyplot as plt fig = plt.gcf() fig.set_size_inches(7.6,6) plt.rcParams.update({'font.size':16}) title = 'Change in ' +index_type+' index with time' index_array = [] day_array = [] dates_array = [] xtick_dates = [] w = 1 key_num = 0 for (key,val) in index_values.items(): weather_date = key dates_array.append(weather_date) dates_array.sort() for key in dates_array: #wes1 = 1#print(index_array[key]) index_value = float(index_values[key])/100 d_date = str(key) y = d_date[0:4] m = d_date[4:6] d = d_date[6:] if int(m)==1: M = 'Jan' elif int(m)==2: M = 'Feb' elif int(m) ==3: M = 'Mar' elif int(m) == 4: M = 'Apr' elif int(m) ==5: M = 'May' elif int(m) == 6: M = 'Jun' elif int(m) ==7: M = 'Jul' elif int(m) ==8: M = 'Aug' elif int(m)==9: M = 'Sep' elif int(m) ==10: M = 'Oct' elif int(m) ==11: M ='Nov' else: M = 'Dec' n_date = d+'-'+M key_num = key_num + 1 if len(dates_array) - key_num < 7: xtick_dates.append(n_date) index_array.append(index_value) day_array.append(w) w=w+1 index_array = index_array[::-1] day_array = day_array[::-1] xtick_dates = xtick_dates[::-1] xlab = 'Days' ylab = 'Index Value' plt.plot(day_array,index_array) plt.xlabel(xlab) plt.ylabel(ylab) plt.title(title) plt.xticks(day_array,xtick_dates) plt.grid(b=True,which='major',color='#666666',linestyle='-') plt.show() file_name = uid+'/' + fieldid +'/'+index_type+'_linegraph.png' plt.savefig(file_name) plt.close()