{ "cells": [ { "cell_type": "code", "execution_count": 8, "metadata": {}, "outputs": [], "source": [ "%matplotlib qt\n", "import numpy as np\n", "import matplotlib.pyplot as plt\n", "\n", "n = 10000\n", "\n", "t = np.linspace(0,200*np.pi,n)\n", "omega = 2\n", "f_t = np.sin(omega*t)*np.cos(50/n*t)\n", "\n", "dt_max = 100\n", "x_s = np.full([dt_max,],np.NaN)\n", "y_s = np.full([dt_max,],np.NaN)\n", "\n", "# fig_ref = plt.figure()\n", "# ax_ref = fig_ref.add_subplot(111)\n", "# line_obj_ref = ax_ref.plot(t,f_t, marker='.')\n", "# plt.show(block=False)\n", "# plt.pause(3)\n", "# plt.close(fig_ref)\n", "\n", "fig = plt.figure()\n", "ax1 = fig.add_subplot(211)\n", "ax2 = fig.add_subplot(212)\n", "ax1.set_xlim([0,t[100+50]])\n", "ax1.set_ylim([-1.05,1.05])\n", "ax2.set_xlim([t[0],t[100+50]])\n", "ax2.set_ylim([-1.05,1.05])\n", "line_obj1, = ax1.plot(0,0, marker='.')\n", "line_obj2, = ax2.plot(0,0, marker='.')\n", "plt.show(block=False)\n", "plt.pause(0.01)\n", "\n", "for i in range(n):\n", " if i <= dt_max:\n", " x_s[:i] = t[:i]\n", " y_s[:i] = f_t[:i]\n", " else:\n", " x_s = t[i-dt_max:i]\n", " y_s = f_t[i-dt_max:i]\n", " ax1.set_xlim([t[i-dt_max],t[i]+t[50]])\n", " ax2.set_xlim([t[0],t[i]+(t[i]-t[0])/2])\n", " \n", " line_obj1.set_xdata(x_s)\n", " line_obj1.set_ydata(y_s)\n", " line_obj2.set_xdata(t[:i])\n", " line_obj2.set_ydata(f_t[:i])\n", " ax1.set_title(str(i))\n", " fig.canvas.draw()\n", " plt.pause(0.001)\n", "\n", " \n" ] } ], "metadata": { "interpreter": { "hash": "84fb123bdc47ab647d3782661abcbe80fbb79236dd2f8adf4cef30e8755eb2cd" }, "kernelspec": { "display_name": "Python 3.8.13 ('Georg_DT_Slot3')", "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.13" }, "orig_nbformat": 4 }, "nbformat": 4, "nbformat_minor": 2 }