{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "This is an interactive demo, not intended for proper viewing on a static page." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "import random" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "random.seed(None)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "VPython example (does not run in notebook):\n", "\n", "```python\n", "import vpython as vp\n", "jmax = 100\n", "x = 0.0\n", "y = 0.0\n", "pts = vp.gcurve()\n", "pts.plot(pos=(x,y))\n", " \n", "for i in range(0, jmax+1):\n", " x += (random.random() - 0.5)*2\n", " y += (random.random() - 0.5)*2\n", " pts.plot(pos=(x,y))\n", " vp.rate(5)\n", "```" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# Uncomment if in widget mode available\n", "#%matplotlib widget" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "import matplotlib.pyplot as plt\n", "import time\n", "import numpy as np" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "fig, ax = plt.subplots()\n", "line, = plt.plot([0], [0], '.-')\n", "ax.set_xlim(-5,5)\n", "ax.set_ylim(-5,5)\n", "plt.show()" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "jmax = 100\n", "x = 0.0\n", "y = 0.0\n", "plt.ion()\n", "\n", "for i in range(0, jmax+1):\n", " x += (random.random() - 0.5)*2\n", " y += (random.random() - 0.5)*2\n", " xs, ys = line.get_data()\n", " xs = np.append(xs, [x])\n", " ys = np.append(ys, [y])\n", " line.set_data(xs, ys)\n", " time.sleep(.2)\n", " print(i, end=\" \")" ] } ], "metadata": { "kernelspec": { "display_name": "compclass", "language": "python", "name": "compclass" }, "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.2" } }, "nbformat": 4, "nbformat_minor": 4 }