def create_temperature_bargraph(uid,min_temp_array,max_temp_array,date_array): import matplotlib.pyplot as plt; plt.rcdefaults() import numpy as np import matplotlib.pyplot as plt n_groups = len(min_temp_array) new_date_array = [] array_len = len(min_temp_array) key_count = 0; new_min_temp_array = [] new_max_temp_array = [] for key in date_array: if array_len<7: date = key year = date[0:4] month = date[4:6] day = date[6:] date = year+'-'+month+'-'+day new_date_array.append(date) new_min_temp_array.append(min_temp_array[key_count]) new_max_temp_array.append(max_temp_array[key_count]) if array_len >6: if (array_len-key_count)<7: date = key year = date[0:4] month = date[4:6] day = date[6:] date = year+'-'+month+'-'+day new_date_array.append(date) new_min_temp_array.append(min_temp_array[key_count]) new_max_temp_array.append(max_temp_array[key_count]) key_count = key_count+1 fig,ax = plt.subplots() n_groups = len(new_min_temp_array) index = np.arange(n_groups) bar_width = 0.35 opacity = 0.8 rects1 = ax.bar(index-bar_width/2,new_min_temp_array,bar_width,alpha=opacity,color='b',label='Min. Temperature (°C)') rects2 = ax.bar(index+bar_width/2,new_max_temp_array,bar_width,alpha=opacity,color='g',label='Max. Temperature (°C)') ax.set_xlabel('Days') ax.set_ylabel('Temperature (°C)') ax.set_title('Minimum and Maximum Temperature vs Date') ax.set_xticks(index) ax.set_xticklabels(new_date_array) ax.legend() fig.tight_layout() plt.show() file_name = uid+'_temp_bargraph.png' plt.savefig(file_name) plt.close()