{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "%matplotlib notebook\n",
    "import matplotlib.pyplot as plt\n",
    "import numpy as np\n",
    "import time\n",
    "from timeit import default_timer as timer\n",
    "from minimal_plot import getTemperatureFromS7\n",
    "\n",
    "print(\"Go...\")\n",
    "\n",
    "fig = plt.figure(num='Temperature from S7-1500 -- OPC-UA')\n",
    "\n",
    "ax = fig.add_subplot(111)\n",
    "plt.xlabel(\"Time since start (s)\")\n",
    "plt.ylabel(\"Temperature (°C)\")\n",
    "\n",
    "plt.ion()\n",
    "fig.show()\n",
    "\n",
    "data_temp1 = []\n",
    "data_temp2 = []\n",
    "timestamp = []\n",
    "\n",
    "while(True):\n",
    "    ax.clear()\n",
    "    temp1c, temp2c = getTemperatureFromS7()\n",
    "    timestamp.append(timer())\n",
    "    data_temp1.append(temp1c)\n",
    "    data_temp2.append(temp2c)\n",
    "    temp1_plot = ax.plot(timestamp, data_temp1, color='blue', label='Temp 1')\n",
    "    temp2_plot = ax.plot(timestamp, data_temp2, color='orange', label='Temp 2')\n",
    "    #plt.xticks(timestamp)\n",
    "    ax.legend(handles=(temp1_plot[0], temp2_plot[0]))\n",
    "    if(len(timestamp) > 30):\n",
    "        timestamp.pop(0)\n",
    "        data_temp1.pop(0)\n",
    "        data_temp2.pop(0)\n",
    "    plt.xlabel(\"Time since start (s)\")\n",
    "    plt.ylabel(\"Temperature (°C)\")\n",
    "    fig.canvas.draw()\n",
    "    time.sleep(1)"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
