{ "metadata": { "name": "", "signature": "sha256:97ecd13824080429b51cddf328f1440206d788d48078730d445f25c679e6a7ff" }, "nbformat": 3, "nbformat_minor": 0, "worksheets": [ { "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "A very incomplete example showing how to make some interactive and javascript widgets for examining parameter space" ] }, { "cell_type": "code", "collapsed": false, "input": [ "from IPython.html.widgets import interact, interactive, fixed\n", "from IPython.html import widgets\n", "from IPython.display import clear_output, display, HTML\n", "from ipywidgets import StaticInteract, RangeWidget, RadioWidget" ], "language": "python", "metadata": {}, "outputs": [], "prompt_number": 1 }, { "cell_type": "code", "collapsed": false, "input": [ "%run ph2co_grid_computation.py" ], "language": "python", "metadata": {}, "outputs": [ { "output_type": "stream", "stream": "stderr", "text": [ "/Users/adam/repos/astroquery/astroquery/lamda/__init__.py:21: UserWarning: Experimental: LAMDA has not yet been refactored to have its API match the rest of astroquery.\n", " warnings.warn(\"Experimental: LAMDA has not yet been refactored to have its API match the rest of astroquery.\")\n", "WARNING:astropy:AstropyDeprecationWarning: 'dtypes' has been renamed to the singular 'dtype'.\n" ] }, { "output_type": "stream", "stream": "stdout", "text": [ "WARNING: AstropyDeprecationWarning: 'dtypes' has been renamed to the singular 'dtype'. [astropy.table.table]\n", " Tex tau ... brightness T_B " ] }, { "output_type": "stream", "stream": "stdout", "text": [ "\n", " K ... erg / (cm2 Hz s sr) K \n", "---------------- ----------------- ... ------------------- ---------------\n", "-0.0817529700928 -0.0342780871976 ... 1.56037207206e-22 0.100352601934\n", " 6.09190527741 41.9634499416 ... 1.73595925381e-14 2.66518509246\n", " -0.171716538322 -0.00182074261889 ... 2.06896749361e-22 0.0053264336307\n" ] }, { "output_type": "stream", "stream": "stderr", "text": [ "/Users/adam/repos/astropy/astropy/units/quantity.py:608: RuntimeWarning: invalid value encountered in true_divide\n", " return np.true_divide(self, other)\n" ] } ], "prompt_number": 2 }, { "cell_type": "code", "collapsed": false, "input": [ "import sys\n", "sys.path += ['/Users/adam/virtual-python/lib/python2.7/site-packages/mpld3-0.0.1-py2.7.egg']\n", "sys.path += ['/Users/adam/virtual-python/lib/python2.7/site-packages/JSAnimation-0.1-py2.7.egg-info']" ], "language": "python", "metadata": {}, "outputs": [], "prompt_number": 53 }, { "cell_type": "code", "collapsed": false, "input": [ "class LinkedView(plugins.PluginBase):\n", " \"\"\"A simple plugin showing how multiple axes can be linked\"\"\"\n", " \n", " FIG_JS = jinja2.Template(\"\"\"\n", " var linedata{{ id }} = {{ linedata }};\n", "\n", " ax{{ axid }}.axes.selectAll(\".paths{{ collid }}\")\n", "\t .on(\"mouseover\", function(d, i){\n", " line{{ elid }}.data = linedata{{ id }}[i];\n", " line{{ elid }}.lineobj.transition()\n", " .attr(\"d\", line{{ elid }}.line(line{{ elid }}.data))\n", " .style(\"stroke\", this.style.fill);})\n", " \"\"\")\n", "\n", " def __init__(self, points, line, linedata):\n", " self.points = points\n", " self.line = line\n", " self.linedata = linedata\n", " self.id = self.generate_unique_id()\n", "\n", " def _fig_js_args(self):\n", " points = self._get_d3obj(self.points)\n", " line = self._get_d3obj(self.line)\n", " return dict(id=self.id,\n", " axid=points.axid,\n", " collid=points.collid,\n", " elid=line.elid,\n", " lineaxid=line.axid,\n", " lineid=line.lineid,\n", " linedata=json.dumps(self.linedata))\n", " \n", " \n", "class Slider(plugins.PluginBase):\n", " FIG_JS = jinja2.Template(\"\"\"\n", " fig.root.append(\"div\")\n", " .append(\"slider\")\n", " .on(\"slide\", function(evt,value) {\n", " d3.select('#slider3text').text(value);\n", " }\n", " );\n", " \"\"\")\n", " \n", " # line = ax{{ axid }}.axes.selectAll(\".line{{ elid }}\");\n", " # line.data = linedata{{ id }}[value];\n", " " ], "language": "python", "metadata": {}, "outputs": [], "prompt_number": 34 }, { "cell_type": "code", "collapsed": false, "input": [ "fig, ((ax1,ax2),(ax3,ax4)) = plt.subplots(2,2)\n", "d3fig = fig_to_d3(fig)\n", "\n", "#lines1 = ax1.plot(temperatures, taugrid_71M)\n", "points1 = ax1.scatter(temperatures, taugrid_71M[:,10])\n", "lines2 = ax2.plot(temperatures, texgrid_71M, 'w')\n", "ax2.set_ylim(0,50)\n", "lines3 = ax3.plot(densities, taugrid_71M.T,'w')\n", "lines4 = ax4.plot(densities, taugrid_71M.T,'w')\n", "\n", "linedata = np.array([(temperatures,tx) for tx in texgrid_71M]).swapaxes(1,2)\n", "plugins.connect(fig, LinkedView(points1, lines2[0], linedata.tolist()))\n", "\n", "linedata = np.array([(densities,tx) for tx in taugrid_71M]).swapaxes(1,2)\n", "plugins.connect(fig, LinkedView(points1, lines3[0], linedata.tolist()))\n", "\n", "linedata = np.array([(densities,tx) for tx in texgrid_71M]).swapaxes(1,2)\n", "plugins.connect(fig, LinkedView(points1, lines4[0], linedata.tolist()))\n", "\n", "plugins.connect(fig, plugins.ResetButton())\n", "#plugins.connect(fig, Slider())\n", "\n", "display_d3(fig)\n", "\n", "# transpose line data and add plugin\n", "#linedata = data.transpose(0, 2, 1).tolist()\n", "\n", "#show_d3()" ], "language": "python", "metadata": {}, "outputs": [ { "html": [ "\n", "\n", "\n", "\n", "\n", "\n", " \n", "\n", "\n", "\n", "