Today marked the first day of the Energize Andover Building Energy Boot Camp. We unfortunately began our day by fixing the problems half of us had with our internet, and learned that the problems were caused by policies on the network. Once everyone was connected, several informative presentations were given, covering everything from the pandas package to the infrastructure behind our BACnet data server. To end the day, we began experimenting with matplotlib to make a line graph with live power data. You can find my code and results at the end of this post.

## Images

The Building Energy Monitor

The Network Infrastructure

## Code and Output

The following is a screenshot of my completed live line graph:

The code used to achieve this output:

``````import os
import pandas as pd
import matplotlib.pyplot as plt
import matplotlib.animation as animation
import numbers
from building_data_requests_external import get_value

# Each row contains the following:
#   - Label
#   - Facility
#   - Instance ID of electric meter

# Choose row
main_row = df[df['Label'] == 'Main (kW)']

# Create figure for plotting
fig = plt.figure()
xs = []
ys = []

# How many times animate() has been called, starts

# This function is called periodically from FuncAnimation
def animate(i, xs, ys):

# Calculate minutes and seconds from updates
minutes = 0

while sec >= 60:
sec = sec - 60
minutes = minutes + 1

value, units = get_value(main_row['Facility'], main_row['Meter'], live=True)
value = int(value) if isinstance(value, numbers.Number) else ''
units = units if units else ''

# Add x and y to lists
xs.append('{:02d}:{:02d}'.format(minutes, sec))
ys.append(value)

# Limit x and y lists to 20 items
xs = xs[-20:]
ys = ys[-20:]

# Draw x and y lists
ax.clear()
ax.plot(xs, ys)

# Format plot
plt.xticks(rotation=45, ha='right')
plt.title('AHS Main Power Usage Over Time')
plt.ylabel('Power ({0})'.format(units))
plt.xlabel('Elapsed Time Since Run (Minutes:Seconds)')