{ "cells": [ { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "%matplotlib inline" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "# Auto-update plot\n\nThis demo shows two possibilities of how to create an auto\nupdating plot, when the data does not come from a device allowing a live plot.\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "from numpy import random\nimport time\nfrom itom import dataObject\nfrom itom import plot1" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Option 1: open plot with fixed interval, the plot shares its values\nfrom a given ``dataObject``, update the ``dataObject`` regularily and call\nthe replot slot of the plot to force an update of the canvas (without that\nslot, the canvas is updated once the user makes a zoom, clicks somewhere...)\n\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "d = dataObject.zeros([1, 3], \"float64\")\n[i, h] = plot1(d, properties={\"yAxisInterval\": (0, 1)})\n\nt = time.time()\nfor i in range(0, 50):\n d[0, :] = random.rand(3)\n h.call(\"replot\")\n time.sleep(0.1)\nprint(\"finished in %.2f s using replot\" % (time.time() - t))" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Option 2: similar to option 1, but the plot is continously given the same\nobject again as source. Some caching mechanism provides a quick replot\nof the data. This option makes an automatic bounds-check of the new source\nand can therefore automatically reset automatic axes intervals\n\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "[i, h] = plot1(d)\n\nt = time.time()\nfor i in range(0, 50):\n d[0, :] = random.rand(3)\n h[\"source\"] = d\n time.sleep(0.1)\nprint(\"finished in %.2f s using autoupdate\" % (time.time() - t))" ] } ], "metadata": { "kernelspec": { "display_name": "Python 3", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.8.10" } }, "nbformat": 4, "nbformat_minor": 0 }