{ "cells": [ { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "%matplotlib inline" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "\nExample demonstrating the Visualization Module. \n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "import matplotlib.pyplot as plt\nfrom prog_models.visualize import plot_timeseries\nfrom prog_models.models.thrown_object import ThrownObject\n\ndef run_example():\n print('Visualize Module Example')\n m = ThrownObject()\n\n # Step 2: Setup for simulation \n def future_load(t, x=None):\n return {}\n\n # Step 3: Simulate to impact\n event = 'impact'\n options={'dt':0.005, 'save_freq':1}\n simulated_results = m.simulate_to_threshold(future_load,\n threshold_keys=[event], \n **options)\n \n\n # Display states\n # ==============\n plot_timeseries(simulated_results.times, simulated_results.states, \n options = {'compact': False, 'suptitle': 'state evolution', 'title': True,\n 'xlabel': 'time', 'ylabel': {'x': 'position', 'v': 'velocity'}, 'display_labels': 'minimal'},\n legend = {'display': True, 'display_at_subplot': 'all'} )\n plot_timeseries(simulated_results.times, simulated_results.states, options = {'compact': True, 'suptitle': 'state evolution', 'title': 'example title',\n 'xlabel': 'time', 'ylabel':'position'})\n plt.show()\n\nif __name__ == '__main__':\n run_example()" ] } ], "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.9" } }, "nbformat": 4, "nbformat_minor": 0 }