def getTimeWattFigure(readings,name='Time Series Plot Of Watts',zeroed=False): """ Returns straightforward time series of watt values """ if zeroed: readings = tu.zeroIndexTimesAxisMPL(readings) times = getTimes(readings) watts = getWatts(readings) fig = plt.figure() axs = fig.add_subplot(111) axs.plot_date(x=times,y=watts,fmt='b-') axs.set_xlabel('Time') axs.set_ylabel('Watts') axs.set_title(name) axs.grid(True) # rotates and right aligns the x labels, and movees bottom of axes up to make room fig.autofmt_xdate() # bottom=0.18) # adjust for date labels # fig.subplots_adjust(left=0.18) return fig
def getAnalysisTimeWattFigure(readings,name): pdng = 2 # padding value readings = tu.zeroIndexTimesAxisMPL(readings) fig = getTimeWattFigure(readings,name) # additions: axs = fig.get_axes()[0] appWatts = getWatts(readings) maxApp = max(appWatts[pdng:-pdng]) minApp = min(appWatts[pdng:-pdng]) axs.hlines(maxApp,readings[pdng][0],readings[-pdng][0],color='r') axs.hlines(minApp,readings[pdng][0],readings[-pdng][0],color='r') xs = getTimes(readings) axs.fill_between(xs,appWatts,facecolor='0.8') axs.set_ylim(0,2300) return fig
def getAppFig(): """ Returns figure showing all appliances cmds: f = getAppFig1() f.savefig('appliances.png') (I know there is a better way of doing this) """ # grill grRs = ap.grill grRs = tu.zeroIndexTimesAxisMPL(grRs) grTs = getTimes(grRs) grWs = getWatts(grRs) # oven ovRs = ap.oven ovRs = tu.zeroIndexTimesAxisMPL(ovRs) ovTs = getTimes(ovRs) ovWs = getWatts(ovRs) # microwave mwRs = ap.microwave mwRs = tu.zeroIndexTimesAxisMPL(mwRs) mwTs = getTimes(mwRs) mwWs = getWatts(mwRs) # tv tvRs = ap.tv tvRs = tu.zeroIndexTimesAxisMPL(tvRs) tvTs = getTimes(tvRs) tvWs = getWatts(tvRs) # toaster tsRs = ap.toaster tsRs = tu.zeroIndexTimesAxisMPL(tsRs) tsTs = getTimes(tsRs) tsWs = getWatts(tsRs) # washing machine wmRs = ap.washingMachine wmRs = tu.zeroIndexTimesAxisMPL(wmRs) wmTs = getTimes(wmRs) wmWs = getWatts(wmRs) # dish washer dwRs = ap.dishWasher dwRs = tu.zeroIndexTimesAxisMPL(dwRs) dwTs = getTimes(dwRs) dwWs = getWatts(dwRs) fig = plt.figure(figsize=None) ax1 = fig.add_subplot(211) ax1.set_title('Rectangular-like appliance signatures') ax1.set_xlabel('Time') ax1.set_ylabel('Watts') ax1.xaxis_date(tz=None) gr,ov,mw,tv = ax1.plot( grTs,grWs,'b-', # rtrns 2D line ovTs,ovWs,'g-', mwTs,mwWs,'r-', tvTs,tvWs,'c-') ax1.legend( (gr,ov,mw,tv), # 2Dline handles ('Grill','Oven','Microwave','Television'), loc=('upper right'), fancybox=True, shadow=True) hmfmt = mdates.DateFormatter('%H:%M') ax1.xaxis.set_major_locator(mdates.HourLocator()) ax1.xaxis.set_major_formatter(hmfmt) ax2 = fig.add_subplot(212) ax2.set_title('Periodic-like appliance signatures') ax2.set_xlabel('Time') ax2.set_ylabel('Watts') ax2.xaxis_date(tz=None) ts,wm,dw = ax2.plot( tsTs,tsWs,'m-', wmTs,wmWs,'g-', dwTs,dwWs,'r-') ax2.legend( (ts,wm,dw), # 2Dline handles ('Toaster','Washing Machine','Dishwasher'), loc=('upper right'), fancybox=True, shadow=True) ax2.xaxis.set_major_locator(mdates.HourLocator()) ax2.xaxis.set_major_formatter(hmfmt) fig.subplots_adjust(hspace=0.5) #fig.autofmt_xdate() # erases x-axis of second graph return fig