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()




[((237, 249), 'matplotlib.pyplot.figure', 'plt.figure', ([], {}), '()\n', (247, 249), True, 'import matplotlib.pyplot as plt\n'), ((302, 310), 'smbus.SMBus', 'SMBus', (['(1)'], {}), '(1)\n', (307, 310), False, 'from smbus import SMBus\n'), ((320, 339), 'bme280.BME280', 'BME280', ([], {'i2c_dev': 'bus'}), '(i2c_dev=bus)\n', (326, 339), False, 'from bme280 import BME280\n'), ((702, 771), 'matplotlib.animation.FuncAnimation', 'animation.FuncAnimation', (['fig', 'animate'], {'fargs': '(xs, ys)', 'interval': '(60000)'}), '(fig, animate, fargs=(xs, ys), interval=60000)\n', (725, 771), True, 'import matplotlib.animation as animation\n'), ((772, 782), 'matplotlib.pyplot.show', 'plt.show', ([], {}), '()\n', (780, 782), True, 'import matplotlib.pyplot as plt\n'), ((555, 590), 'matplotlib.pyplot.xticks', 'plt.xticks', ([], {'rotation': '(45)', 'ha': '"""right"""'}), "(rotation=45, ha='right')\n", (565, 590), True, 'import matplotlib.pyplot as plt\n'), ((595, 626), 'matplotlib.pyplot.subplots_adjust', 'plt.subplots_adjust', ([], {'bottom': '(0.3)'}), '(bottom=0.3)\n', (614, 626), True, 'import matplotlib.pyplot as plt\n'), ((632, 663), 'matplotlib.pyplot.title', 'plt.title', (['"""Pressure over time"""'], {}), "('Pressure over time')\n", (641, 663), True, 'import matplotlib.pyplot as plt\n'), ((668, 690), 'matplotlib.pyplot.ylabel', 'plt.ylabel', (['"""pressure"""'], {}), "('pressure')\n", (678, 690), True, 'import matplotlib.pyplot as plt\n'), ((416, 433), 'datetime.datetime.now', 'dt.datetime.now', ([], {}), '()\n', (431, 433), True, 'import datetime as dt\n')]