def correlate(chan_id, weather_variable, subplot_index, annotate_y): # 25 = lighting circuit # (R^2 = 0.443) # 8 = kitchen lights (R^2 = 0.194) # 2 = boiler (versus radiation R^2 = 0.052, # versus mean_temp R^2 = 0.298, # versus max_temp R^2 = 0.432, # versus min_temp R^2 = 0.212) # 3 = solar (R^2 = 0.798) # 12 = fridge vs min_temp R^2 = 0.255 (with on_power_threshold = 20) print("Opening channel data...") channel = Channel(DATA_DIR, chan_id) print("Calculating...") channel.on_power_threshold = 20 hours_on = channel.usage_per_period('D', tz_convert='UTC').hours_on hours_on = hours_on[hours_on > ON_DURATION_THRESHOLD] hours_on.description = 'hours on' print("Got {} days of data from usage_per_period.".format(hours_on.size)) print("Plotting...") x_aligned, y_aligned = pda.stats.align(weather_variable, hours_on) print(x_aligned.description) slope, intercept, r_value, p_value, std_err = linregress(x_aligned.values, y_aligned.values) ax = fig.add_subplot(2,2,subplot_index) ax = spfl.format_axes(ax) ax = pda.stats.plot_regression_line(ax, x_aligned, y_aligned, slope, intercept, r_value, annotate_y=annotate_y) print("R^2={:.3f}".format(r_value**2)) ax.set_title('Correlation between ' + channel.get_long_name() + ' and ' + metoffice.get_long_name(weather_variable.name))
ax.set_ylim([0, np.max(n)*1.65]) title_x = 0.5 elif c.name == 'lcd_office': ax.set_ylim([0, np.max(n)*1.5]) title_x = 0.5 elif c.name == 'htpc': ax.set_ylim([0, np.max(n)*1.2]) title_x = 0.4 elif c.name == 'breadmaker': ax.set_ylim([0, np.max(n)*0.5]) title_x = 0.5 elif c.name == 'laptop': ax.set_ylim([0, np.max(n)*0.9]) title_x = 0.5 elif c.name == 'toaster': ax.set_ylim([0, np.max(n)*1.1]) title_x = 0.4 elif c.name == 'hoover': ax.set_ylim([0, np.max(n)*1.0]) title_x = 0.5 else: ax.set_ylim([0, np.max(n)*1.2]) title_x = 0.5 xlim = ax.get_xlim() ax.xaxis.set_major_locator(MaxNLocator(5)) ax.set_title(c.get_long_name(), x=title_x, y=TITLE_Y, ha='center') plt.subplots_adjust(hspace=0.5, wspace=0.3) plt.savefig(LATEX_PDF_OUTPUT_FILENAME) plt.show()
ax.set_ylim([0, np.max(n) * 1.65]) title_x = 0.5 elif c.name == 'lcd_office': ax.set_ylim([0, np.max(n) * 1.5]) title_x = 0.5 elif c.name == 'htpc': ax.set_ylim([0, np.max(n) * 1.2]) title_x = 0.4 elif c.name == 'breadmaker': ax.set_ylim([0, np.max(n) * 0.5]) title_x = 0.5 elif c.name == 'laptop': ax.set_ylim([0, np.max(n) * 0.9]) title_x = 0.5 elif c.name == 'toaster': ax.set_ylim([0, np.max(n) * 1.1]) title_x = 0.4 elif c.name == 'hoover': ax.set_ylim([0, np.max(n) * 1.0]) title_x = 0.5 else: ax.set_ylim([0, np.max(n) * 1.2]) title_x = 0.5 xlim = ax.get_xlim() ax.xaxis.set_major_locator(MaxNLocator(5)) ax.set_title(c.get_long_name(), x=title_x, y=TITLE_Y, ha='center') plt.subplots_adjust(hspace=0.5, wspace=0.3) plt.savefig(LATEX_PDF_OUTPUT_FILENAME) plt.show()