{ "metadata": {}, "nbformat": 3, "nbformat_minor": 0, "worksheets": [ { "cells": [ { "cell_type": "code", "collapsed": false, "input": [ "\"\"\"\n", "Matplotlib Animation Example\n", "\n", "author: Jake Vanderplas\n", "email: vanderplas@astro.washington.edu\n", "website: http://jakevdp.github.com\n", "license: BSD\n", "Please feel free to use and modify this, but keep the above information. Thanks!\n", "\"\"\"\n", "# reference: http://matplotlib.sourceforge.net/api/animation_api.html\n", "import numpy as np\n", "from matplotlib import pyplot as plt\n", "from matplotlib import animation\n", "from mpl_toolkits.mplot3d import Axes3D\n", "import matplotlib.pyplot as plt\n", "import matplotlib.patches as mpatches\n", "import pylab as pylab\n", "\n", "tauMax = 30\n", "tauMin = 2\n", "neuronFiringThreshold = 10\n", "Rm = 80\n", "tauM = .03\n", "\n", "class Anim3dWTauRPlot:\n", " def create3dBarChart(self):\n", "\n", " fig = plt.figure()\n", " ax1 = fig.add_subplot(131, projection='3d')\n", " ax2 = fig.add_subplot(132, projection='3d')\n", " ax3 = fig.add_subplot(133, projection='3d')\n", "\n", " ax1.view_init(elev=10.0, azim=85)\n", " ax2.view_init(elev=10.0, azim=85) \n", " ax3.view_init(elev=10.0, azim=85) \n", "\n", " xpos = np.array([0.0])\n", " ypos = np.array([0.0])\n", " zpos = np.array([0.0])\n", " dx = np.array([1.0])\n", " dy = np.array([1.0])\n", "\n", " def generateLine(timePoint):\n", " ax1.clear()\n", " ax1.grid(b=False)\n", " ax2.clear()\n", " ax2.grid(b=False)\n", " ax3.clear()\n", " ax3.grid(b=False)\n", " ax1.set_title('Weight')\n", " ax2.set_title('Tau')\n", " ax3.set_title('Resistance')\n", " ax1.set_zlim([0.0, 1.0]) \n", " ax2.set_zlim([0.0, 30.0]) \n", " ax3.set_zlim([0.0, 3.5])\n", "\n", " w = 1-(timePoint * .01)\n", " tau = (tauMax - (abs(w) * (tauMax - tauMin)))\n", " r = (((tau * neuronFiringThreshold) / Rm) * ((tauM / tau) ** (tauM / (tauM - tau))))\n", "\n", " ax1.bar3d(xpos, ypos, zpos, dx, dy, w, color=['r'], alpha=0.5)\n", " ax2.bar3d(xpos, ypos, zpos, dx, dy, tau, color=['g'], alpha=0.5)\n", " ax3.bar3d(xpos, ypos, zpos, dx, dy, r, color=['b'], alpha=0.5)\n", "\n", " if timePoint == 10 or timePoint == 20 or timePoint == 40 or timePoint == 60 or timePoint == 80:\n", " print 'rendering timePoint:\\t',timePoint\n", "\n", " line_ani = animation.FuncAnimation(fig, generateLine, frames=100, interval=1, blit=False) \n", " ext = 'mp4'\n", " fps = 30\n", " codec = {'mp4': 'libx264', 'webm': 'libvpx'}.get(ext, 'mpeg4')\n", " line_ani.save('WeightTauRes.mp4', fps=30, extra_args=['-vcodec', 'libx264'])\n", "\n", " plt.show()\n", "\n", " def __init__(self):\n", " self.create3dBarChart()\n", "\n", "def main():\n", " run3dAnim = Anim3dWTauRPlot()\n", "\n", "if __name__ =='__main__':main()\n", "\n", "print 'done'" ], "language": "python", "metadata": {}, "outputs": [] } ], "metadata": {} } ] }