from requests import get
import matplotlib.pyplot as plt
import matplotlib.animation as animation
import datetime as dt

from bme280 import BME280

try:
    from smbus2 import SMBus
except ImportError:
    from smbus import SMBus

fig = plt.figure()
ax = fig.add_subplot(1, 1, 1)
xs = []
ys =[]

bus = SMBus(1)
bme280 = BME280(i2c_dev=bus)

def animate(i, xs, ys):
    pressure = bme280.get_pressure()
    xs.append(dt.datetime.now().strftime('%H:%M:%S'))
    ys.append(pressure)
    xs = xs[-20:]
    ys = ys[-20:]
    ax.clear()
    ax.plot(xs, ys)
    plt.xticks(rotation=45, ha='right')
    plt.subplots_adjust(bottom=0.30)
    plt.title('Pressure over time')
    plt.ylabel("pressure")
    
ani = animation.FuncAnimation(fig, animate, fargs=(xs, ys), interval=60000)
plt.show()




[(13, 'matplotlib.pyplot.figure', 'plt.figure', True, 'import matplotlib.pyplot as plt\n'), (18, 'smbus.SMBus', 'SMBus', False, 'from smbus import SMBus\n'), (19, 'bme280.BME280', 'BME280', False, 'from bme280 import BME280\n'), (34, 'matplotlib.animation.FuncAnimation', 'animation.FuncAnimation', True, 'import matplotlib.animation as animation\n'), (35, 'matplotlib.pyplot.show', 'plt.show', True, 'import matplotlib.pyplot as plt\n'), (29, 'matplotlib.pyplot.xticks', 'plt.xticks', True, 'import matplotlib.pyplot as plt\n'), (30, 'matplotlib.pyplot.subplots_adjust', 'plt.subplots_adjust', True, 'import matplotlib.pyplot as plt\n'), (31, 'matplotlib.pyplot.title', 'plt.title', True, 'import matplotlib.pyplot as plt\n'), (32, 'matplotlib.pyplot.ylabel', 'plt.ylabel', True, 'import matplotlib.pyplot as plt\n'), (23, 'datetime.datetime.now', 'dt.datetime.now', True, 'import datetime as dt\n')]