Created
June 15, 2015 21:48
-
-
Save martindurant/a9f002421900cc65c340 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| { | |
| "cells": [ | |
| { | |
| "cell_type": "code", | |
| "execution_count": 98, | |
| "metadata": { | |
| "collapsed": false | |
| }, | |
| "outputs": [], | |
| "source": [ | |
| "# imports widget side\n", | |
| "# see https://github.com/ipython/ipython/blob/2.x/examples/Interactive%20Widgets/Custom%20Widgets.ipynb\n", | |
| "# and https://github.com/ipython/ipython/blob/master/examples/Interactive%20Widgets/Custom%20Widget%20-%20Hello%20World.ipynb\n", | |
| "\n", | |
| "from __future__ import print_function # For py 2.7 compat\n", | |
| "\n", | |
| "from IPython.html import widgets # Widget definitions\n", | |
| "from IPython.display import display, Javascript # Used to display widgets in the notebook\n", | |
| "from IPython.utils.traitlets import Unicode # Used to declare attributes of our widget\n", | |
| "from IPython.html.widgets import interact, interactive, fixed" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": 99, | |
| "metadata": { | |
| "collapsed": false | |
| }, | |
| "outputs": [], | |
| "source": [ | |
| "# imports render side\n", | |
| "# see http://mpld3.github.io/examples/drag_points.html\n", | |
| "\n", | |
| "import numpy as np\n", | |
| "import matplotlib.pyplot as plt\n", | |
| "import matplotlib as mpl\n", | |
| "\n", | |
| "import mpld3\n", | |
| "from mpld3 import plugins, utils" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": 100, | |
| "metadata": { | |
| "collapsed": false | |
| }, | |
| "outputs": [], | |
| "source": [ | |
| "# widget sync'd python side\n", | |
| "class GraphWidget(widgets.DOMWidget):\n", | |
| " _view_name = Unicode('GraphView', sync=True)\n", | |
| " description = 'coord' \n", | |
| " value = Unicode(sync=True)\n", | |
| " js = \"\"\"require([\"widgets/js/widget\", \"widgets/js/manager\"], function(widget, manager){\n", | |
| " // is based on the DatePickerView\n", | |
| " var GraphView = widget.DOMWidgetView.extend({\n", | |
| " render: function() {\n", | |
| " //@ attr id : this is the id we reach to in the dragended function in the DragPlugin\n", | |
| " this.$text = $('<input />')\n", | |
| " .attr('type', 'text')\n", | |
| " .attr('id', 'feedback_widget') \n", | |
| " .appendTo(this.$el);\n", | |
| " },\n", | |
| " \n", | |
| " update: function() {\n", | |
| " this.$text.val(this.model.get('value'));\n", | |
| " return GraphView.__super__.update.apply(this);\n", | |
| " },\n", | |
| " \n", | |
| " events: {\"change\": \"handle_change\"},\n", | |
| " \n", | |
| " handle_change: function(event) {\n", | |
| " this.model.set('value', this.$text.val());\n", | |
| " this.touch();\n", | |
| " },\n", | |
| " });\n", | |
| " \n", | |
| " manager.WidgetManager.register_widget_view('GraphView', GraphView);\n", | |
| "});\"\"\"\n", | |
| " def cascase_events(self):\n", | |
| " for dep in self.dependents:\n", | |
| " display(Javascript(\"\"\"$('#{}').val(\"{}\").trigger(\"change\").hide();\"\"\".format(dep.ref_name, self.value)))\n", | |
| "\n", | |
| " def __init__(self, *args, **kwarg):\n", | |
| " if kwarg.get('widgen_name'):\n", | |
| " self._view_name = kwarg.get('widgen_name')\n", | |
| " self.js = self.js.replace('GraphView', kwarg.pop('widgen_name'))\n", | |
| " self.ref_name = self._view_name + \"_id\"\n", | |
| " self.js = self.js.replace('feedback_widget', self.ref_name)\n", | |
| " self.dependents = [] # other GraphWidget-like objects to cascade events to\n", | |
| " self.on_trait_change(self.cascase_events)\n", | |
| " display(Javascript(self.js))\n", | |
| " widgets.DOMWidget.__init__(self, *args, **kwarg)" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": 101, | |
| "metadata": { | |
| "collapsed": false | |
| }, | |
| "outputs": [ | |
| { | |
| "data": { | |
| "application/javascript": [ | |
| "require([\"widgets/js/widget\", \"widgets/js/manager\"], function(widget, manager){\n", | |
| " // is based on the DatePickerView\n", | |
| " var GraphView01 = widget.DOMWidgetView.extend({\n", | |
| " render: function() {\n", | |
| " //@ attr id : this is the id we reach to in the dragended function in the DragPlugin\n", | |
| " this.$text = $('<input />')\n", | |
| " .attr('type', 'text')\n", | |
| " .attr('id', 'GraphView01_id') \n", | |
| " .appendTo(this.$el);\n", | |
| " },\n", | |
| " \n", | |
| " update: function() {\n", | |
| " this.$text.val(this.model.get('value'));\n", | |
| " return GraphView01.__super__.update.apply(this);\n", | |
| " },\n", | |
| " \n", | |
| " events: {\"change\": \"handle_change\"},\n", | |
| " \n", | |
| " handle_change: function(event) {\n", | |
| " this.model.set('value', this.$text.val());\n", | |
| " this.touch();\n", | |
| " },\n", | |
| " });\n", | |
| " \n", | |
| " manager.WidgetManager.register_widget_view('GraphView01', GraphView01);\n", | |
| "});" | |
| ], | |
| "text/plain": [ | |
| "<IPython.core.display.Javascript object>" | |
| ] | |
| }, | |
| "metadata": {}, | |
| "output_type": "display_data" | |
| } | |
| ], | |
| "source": [ | |
| "w = GraphWidget(widgen_name='GraphView01')" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": 102, | |
| "metadata": { | |
| "collapsed": false | |
| }, | |
| "outputs": [], | |
| "source": [ | |
| "# visu plugin\n", | |
| "# based on DragPlugin\n", | |
| "class DragPlugin(plugins.PluginBase):\n", | |
| " JAVASCRIPT = r\"\"\"\n", | |
| "$('#feedback_widget').hide();\n", | |
| "mpld3.register_plugin(\"drag\", DragPlugin);\n", | |
| "DragPlugin.prototype = Object.create(mpld3.Plugin.prototype);\n", | |
| "DragPlugin.prototype.constructor = DragPlugin;\n", | |
| "DragPlugin.prototype.requiredProps = [\"id\"];\n", | |
| "DragPlugin.prototype.defaultProps = {}\n", | |
| "function DragPlugin(fig, props){\n", | |
| " mpld3.Plugin.call(this, fig, props);\n", | |
| " mpld3.insert_css(\"#\" + fig.figid + \" path.dragging\",\n", | |
| " {\"fill-opacity\": \"1.0 !important\",\n", | |
| " \"stroke-opacity\": \"1.0 !important\"});\n", | |
| "};$\n", | |
| "\n", | |
| "DragPlugin.prototype.draw = function(){\n", | |
| " var obj = mpld3.get_element(this.props.id);\n", | |
| "\n", | |
| " var drag = d3.behavior.drag()\n", | |
| " .origin(function(d) { return {x:obj.ax.x(d[0]),\n", | |
| " y:obj.ax.y(d[1])}; })\n", | |
| " .on(\"dragstart\", dragstarted)\n", | |
| " .on(\"drag\", dragged)\n", | |
| " .on(\"dragend\", dragended);\n", | |
| "\n", | |
| " obj.elements()\n", | |
| " .data(obj.offsets)\n", | |
| " .style(\"cursor\", \"default\")\n", | |
| " .call(drag);\n", | |
| "\n", | |
| " function dragstarted(d) {\n", | |
| " d3.event.sourceEvent.stopPropagation();\n", | |
| " d3.select(this).classed(\"dragging\", true);\n", | |
| " }\n", | |
| "\n", | |
| " function dragged(d, i) {\n", | |
| " d[0] = obj.ax.x.invert(d3.event.x);\n", | |
| " d[1] = obj.ax.y.invert(d3.event.y);\n", | |
| " d3.select(this)\n", | |
| " .attr(\"transform\", \"translate(\" + [d3.event.x,d3.event.y] + \")\");\n", | |
| " }\n", | |
| "\n", | |
| " function dragended(d,i) {\n", | |
| " d3.select(this).classed(\"dragging\", false);\n", | |
| " // feed back the new position to python, triggering 'change' on the widget\n", | |
| " $('#feedback_widget').val(\"\" + i + \",\" + d[0] + \",\" + d[1]).trigger(\"change\");\n", | |
| " }\n", | |
| "}\"\"\"\n", | |
| "\n", | |
| " def __init__(self, points, ref=None):\n", | |
| " if ref:\n", | |
| " self.JAVASCRIPT = self.JAVASCRIPT.replace('feedback_widget', ref)\n", | |
| " if isinstance(points, mpl.lines.Line2D):\n", | |
| " suffix = \"pts\"\n", | |
| " else:\n", | |
| " suffix = None\n", | |
| "\n", | |
| " self.dict_ = {\"type\": \"drag\",\n", | |
| " \"id\": utils.get_id(points, suffix)}" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": 107, | |
| "metadata": { | |
| "collapsed": false | |
| }, | |
| "outputs": [], | |
| "source": [ | |
| "# fit and draw\n", | |
| "from scipy.optimize import fsolve\n", | |
| "\n", | |
| "class Fit(object):\n", | |
| " def __init__(self, simulate, double_seeding=False, widgen_id='GraphView'):\n", | |
| " self.simulate = simulate\n", | |
| " self.ref = widgen_id\n", | |
| " \n", | |
| " # i will draw initial points at random\n", | |
| " # the number of points will increase until we match parity with the function to be fitted\n", | |
| " pseudo_fit = []\n", | |
| " while len(pseudo_fit) < 100:\n", | |
| " # just in case, I want to avoid inifite loops...\n", | |
| " try:\n", | |
| " simulate(0, pseudo_fit)\n", | |
| " print(\"we have %d parameters\"%len(pseudo_fit))\n", | |
| " break\n", | |
| " except IndexError:\n", | |
| " pseudo_fit.append(1)\n", | |
| " \n", | |
| " # we generate a random cloud \n", | |
| " # the dots are distributed in (>0, >0) quadrant \n", | |
| " self.p = np.random.standard_exponential((len(pseudo_fit), 2))\n", | |
| " \n", | |
| " # first guess ! all ones.\n", | |
| " self.fit = np.array(pseudo_fit)\n", | |
| " \n", | |
| " def make_equations(self):\n", | |
| " def equations(params):\n", | |
| " return self.p[:,1] - self.simulate(self.p[:,0], params)\n", | |
| " self.equations = equations\n", | |
| " \n", | |
| " def recalc_param(self):\n", | |
| " self.make_equations()\n", | |
| " self.fit = fsolve(self.equations, np.ones(self.fit.shape), xtol=0.01)\n", | |
| " \n", | |
| " def redraw(self, coord):\n", | |
| " # we have an update !\n", | |
| " \n", | |
| " # record the new position for given point \n", | |
| " if coord != \"\":\n", | |
| " i, x, y = coord.split(\",\")\n", | |
| " i = int(i)\n", | |
| " self.p[i][0] = float(x)\n", | |
| " self.p[i][1] = float(y)\n", | |
| " \n", | |
| " # recalculate best fit\n", | |
| " self.recalc_param()\n", | |
| " \n", | |
| " # draw things\n", | |
| " x = np.linspace(0, 10, 50) # 50 x points from 0 to 10\n", | |
| " y = self.simulate(x, self.fit)\n", | |
| " \n", | |
| " fig, ax = plt.subplots(figsize=(6,3))\n", | |
| "\n", | |
| " points = ax.plot(self.p[:,0], self.p[:,1],'or', alpha=0.5, markersize=10, markeredgewidth=1)\n", | |
| " \n", | |
| " ax.plot(x,y,'r-')\n", | |
| " ax.set_title(\"Click and Drag\\n, we match on : %s\"%np.array_str(self.fit, precision=2), fontsize=12)\n", | |
| "\n", | |
| " plugins.connect(fig, DragPlugin(points[0], ref=self.ref))\n", | |
| "\n", | |
| " fig_h = mpld3.display(fig=fig)\n", | |
| " display(fig_h)" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": 108, | |
| "metadata": { | |
| "collapsed": false, | |
| "scrolled": false | |
| }, | |
| "outputs": [ | |
| { | |
| "data": { | |
| "text/html": [ | |
| "\n", | |
| "\n", | |
| "<style>\n", | |
| "\n", | |
| "</style>\n", | |
| "\n", | |
| "<div id=\"fig_el324261403260775081289086030123\"></div>\n", | |
| "<script>\n", | |
| "function mpld3_load_lib(url, callback){\n", | |
| " var s = document.createElement('script');\n", | |
| " s.src = url;\n", | |
| " s.async = true;\n", | |
| " s.onreadystatechange = s.onload = callback;\n", | |
| " s.onerror = function(){console.warn(\"failed to load library \" + url);};\n", | |
| " document.getElementsByTagName(\"head\")[0].appendChild(s);\n", | |
| "}\n", | |
| "\n", | |
| "if(typeof(mpld3) !== \"undefined\" && mpld3._mpld3IsLoaded){\n", | |
| " // already loaded: just create the figure\n", | |
| " !function(mpld3){\n", | |
| " \n", | |
| "$('#GraphView01_id').hide();\n", | |
| "mpld3.register_plugin(\"drag\", DragPlugin);\n", | |
| "DragPlugin.prototype = Object.create(mpld3.Plugin.prototype);\n", | |
| "DragPlugin.prototype.constructor = DragPlugin;\n", | |
| "DragPlugin.prototype.requiredProps = [\"id\"];\n", | |
| "DragPlugin.prototype.defaultProps = {}\n", | |
| "function DragPlugin(fig, props){\n", | |
| " mpld3.Plugin.call(this, fig, props);\n", | |
| " mpld3.insert_css(\"#\" + fig.figid + \" path.dragging\",\n", | |
| " {\"fill-opacity\": \"1.0 !important\",\n", | |
| " \"stroke-opacity\": \"1.0 !important\"});\n", | |
| "};$\n", | |
| "\n", | |
| "DragPlugin.prototype.draw = function(){\n", | |
| " var obj = mpld3.get_element(this.props.id);\n", | |
| "\n", | |
| " var drag = d3.behavior.drag()\n", | |
| " .origin(function(d) { return {x:obj.ax.x(d[0]),\n", | |
| " y:obj.ax.y(d[1])}; })\n", | |
| " .on(\"dragstart\", dragstarted)\n", | |
| " .on(\"drag\", dragged)\n", | |
| " .on(\"dragend\", dragended);\n", | |
| "\n", | |
| " obj.elements()\n", | |
| " .data(obj.offsets)\n", | |
| " .style(\"cursor\", \"default\")\n", | |
| " .call(drag);\n", | |
| "\n", | |
| " function dragstarted(d) {\n", | |
| " d3.event.sourceEvent.stopPropagation();\n", | |
| " d3.select(this).classed(\"dragging\", true);\n", | |
| " }\n", | |
| "\n", | |
| " function dragged(d, i) {\n", | |
| " d[0] = obj.ax.x.invert(d3.event.x);\n", | |
| " d[1] = obj.ax.y.invert(d3.event.y);\n", | |
| " d3.select(this)\n", | |
| " .attr(\"transform\", \"translate(\" + [d3.event.x,d3.event.y] + \")\");\n", | |
| " }\n", | |
| "\n", | |
| " function dragended(d,i) {\n", | |
| " d3.select(this).classed(\"dragging\", false);\n", | |
| " // feed back the new position to python, triggering 'change' on the widget\n", | |
| " $('#GraphView01_id').val(\"\" + i + \",\" + d[0] + \",\" + d[1]).trigger(\"change\");\n", | |
| " }\n", | |
| "}\n", | |
| " mpld3.draw_figure(\"fig_el324261403260775081289086030123\", {\"height\": 240.0, \"data\": {\"data01\": [[5.285566674332074, 3.8304170405840052], [2.4421450620461194, 3.239889534710601], [1.0789219606138425, 1.8824830041905845]], \"data02\": [[0.0, -1.2275585415969057], [0.20408163265306123, -0.6312410552765161], [0.40816326530612246, 0.032158642930433017], [0.6122448979591837, 0.691852122414116], [0.8163265306122449, 1.2792357596853972], [1.0204081632653061, 1.7625854212124106], [1.2244897959183674, 2.144744660124238], [1.4285714285714286, 2.443557339584657], [1.6326530612244898, 2.6783783886638752], [1.836734693877551, 2.865206686357047], [2.0408163265306123, 3.016076349229062], [2.2448979591836737, 3.1397529526459174], [2.4489795918367347, 3.2425860300746634], [2.6530612244897958, 3.3292047991428433], [2.857142857142857, 3.403024153899514], [3.0612244897959187, 3.4665982326108407], [3.2653061224489797, 3.5218648357670532], [3.4693877551020407, 3.5703148028613785], [3.673469387755102, 3.613110412062255], [3.8775510204081636, 3.6511691110786915], [4.081632653061225, 3.6852234928379852], [4.285714285714286, 3.71586482053464], [4.4897959183673475, 3.7435750229293774], [4.6938775510204085, 3.7687505073064673], [4.8979591836734695, 3.7917200929324637], [5.1020408163265305, 3.8127586681967935], [5.3061224489795915, 3.8320977009926405], [5.510204081632653, 3.849933407641196], [5.714285714285714, 3.866433161093829], [5.918367346938775, 3.8817405618287517], [6.122448979591837, 3.895979483414301], [6.326530612244898, 3.9092573249063216], [6.530612244897959, 3.921667644503618], [6.73469387755102, 3.933292306687915], [6.938775510204081, 3.9442032439443118], [7.142857142857143, 3.9544639109842796], [7.346938775510204, 3.9641304919934175], [7.551020408163265, 3.973252908254589], [7.755102040816327, 3.9818756634484354], [7.959183673469388, 3.9900385562102074], [8.16326530612245, 3.9977772835442438], [8.36734693877551, 4.0051239540396475], [8.571428571428571, 4.012107526178062], [8.775510204081632, 4.018754184142539], [8.979591836734695, 4.025087661249438], [9.183673469387756, 4.031129519300158], [9.387755102040817, 4.03689939068531], [9.591836734693878, 4.042415188893274], [9.795918367346939, 4.047693292118434], [10.0, 4.052748703885634]]}, \"axes\": [{\"xscale\": \"linear\", \"ydomain\": [-2.0, 5.0], \"zoomable\": true, \"sharey\": [], \"texts\": [{\"alpha\": 1, \"text\": \"Click and Drag\\n, we match on : [ 2.73 1.21 -0.48]\", \"v_baseline\": \"auto\", \"fontsize\": 12.0, \"zorder\": 3, \"position\": [0.5, 1.0289351851851851], \"h_anchor\": \"middle\", \"id\": \"el32426140326077850008\", \"rotation\": -0.0, \"color\": \"#262626\", \"coordinates\": \"axes\"}], \"id\": \"el32426140326084427056\", \"axesbgalpha\": null, \"paths\": [], \"images\": [], \"axes\": [{\"nticks\": 6, \"position\": \"bottom\", \"tickformat\": null, \"scale\": \"linear\", \"grid\": {\"dasharray\": \"none\", \"gridOn\": true, \"alpha\": 1.0, \"color\": \"#FFFFFF\"}, \"tickvalues\": null, \"fontsize\": 13.0}, {\"nticks\": 8, \"position\": \"left\", \"tickformat\": null, \"scale\": \"linear\", \"grid\": {\"dasharray\": \"none\", \"gridOn\": true, \"alpha\": 1.0, \"color\": \"#FFFFFF\"}, \"tickvalues\": null, \"fontsize\": 13.0}], \"xdomain\": [0.0, 10.0], \"lines\": [{\"yindex\": 1, \"alpha\": 1, \"color\": \"#FF0000\", \"dasharray\": \"none\", \"id\": \"el32426140326083340216\", \"linewidth\": 2.275, \"data\": \"data02\", \"zorder\": 2, \"coordinates\": \"data\", \"xindex\": 0}], \"axesbg\": \"#EAEAF2\", \"collections\": [], \"yscale\": \"linear\", \"ylim\": [-2.0, 5.0], \"sharex\": [], \"xlim\": [0.0, 10.0], \"markers\": [{\"yindex\": 1, \"alpha\": 0.5, \"edgewidth\": 1, \"facecolor\": \"#FF0000\", \"id\": \"el32426140326080458312pts\", \"markerpath\": [[[0.0, 5.0], [1.3260155, 5.0], [2.597899353924267, 4.473168457941209], [3.5355339059327378, 3.5355339059327378], [4.473168457941209, 2.597899353924267], [5.0, 1.3260155], [5.0, 0.0], [5.0, -1.3260155], [4.473168457941209, -2.597899353924267], [3.5355339059327378, -3.5355339059327378], [2.597899353924267, -4.473168457941209], [1.3260155, -5.0], [0.0, -5.0], [-1.3260155, -5.0], [-2.597899353924267, -4.473168457941209], [-3.5355339059327378, -3.5355339059327378], [-4.473168457941209, -2.597899353924267], [-5.0, -1.3260155], [-5.0, 0.0], [-5.0, 1.3260155], [-4.473168457941209, 2.597899353924267], [-3.5355339059327378, 3.5355339059327378], [-2.597899353924267, 4.473168457941209], [-1.3260155, 5.0], [0.0, 5.0]], [\"M\", \"C\", \"C\", \"C\", \"C\", \"C\", \"C\", \"C\", \"C\", \"Z\"]], \"edgecolor\": \"#000000\", \"data\": \"data01\", \"zorder\": 2, \"coordinates\": \"data\", \"xindex\": 0}], \"bbox\": [0.125, 0.09999999999999998, 0.775, 0.8]}], \"id\": \"el32426140326077508128\", \"plugins\": [{\"type\": \"reset\"}, {\"button\": true, \"enabled\": false, \"type\": \"zoom\"}, {\"button\": true, \"enabled\": false, \"type\": \"boxzoom\"}, {\"id\": \"el32426140326080458312pts\", \"type\": \"drag\"}], \"width\": 480.0});\n", | |
| " }(mpld3);\n", | |
| "}else if(typeof define === \"function\" && define.amd){\n", | |
| " // require.js is available: use it to load d3/mpld3\n", | |
| " require.config({paths: {d3: \"https://mpld3.github.io/js/d3.v3.min\"}});\n", | |
| " require([\"d3\"], function(d3){\n", | |
| " window.d3 = d3;\n", | |
| " mpld3_load_lib(\"https://mpld3.github.io/js/mpld3.v0.3git.js\", function(){\n", | |
| " \n", | |
| "$('#GraphView01_id').hide();\n", | |
| "mpld3.register_plugin(\"drag\", DragPlugin);\n", | |
| "DragPlugin.prototype = Object.create(mpld3.Plugin.prototype);\n", | |
| "DragPlugin.prototype.constructor = DragPlugin;\n", | |
| "DragPlugin.prototype.requiredProps = [\"id\"];\n", | |
| "DragPlugin.prototype.defaultProps = {}\n", | |
| "function DragPlugin(fig, props){\n", | |
| " mpld3.Plugin.call(this, fig, props);\n", | |
| " mpld3.insert_css(\"#\" + fig.figid + \" path.dragging\",\n", | |
| " {\"fill-opacity\": \"1.0 !important\",\n", | |
| " \"stroke-opacity\": \"1.0 !important\"});\n", | |
| "};$\n", | |
| "\n", | |
| "DragPlugin.prototype.draw = function(){\n", | |
| " var obj = mpld3.get_element(this.props.id);\n", | |
| "\n", | |
| " var drag = d3.behavior.drag()\n", | |
| " .origin(function(d) { return {x:obj.ax.x(d[0]),\n", | |
| " y:obj.ax.y(d[1])}; })\n", | |
| " .on(\"dragstart\", dragstarted)\n", | |
| " .on(\"drag\", dragged)\n", | |
| " .on(\"dragend\", dragended);\n", | |
| "\n", | |
| " obj.elements()\n", | |
| " .data(obj.offsets)\n", | |
| " .style(\"cursor\", \"default\")\n", | |
| " .call(drag);\n", | |
| "\n", | |
| " function dragstarted(d) {\n", | |
| " d3.event.sourceEvent.stopPropagation();\n", | |
| " d3.select(this).classed(\"dragging\", true);\n", | |
| " }\n", | |
| "\n", | |
| " function dragged(d, i) {\n", | |
| " d[0] = obj.ax.x.invert(d3.event.x);\n", | |
| " d[1] = obj.ax.y.invert(d3.event.y);\n", | |
| " d3.select(this)\n", | |
| " .attr(\"transform\", \"translate(\" + [d3.event.x,d3.event.y] + \")\");\n", | |
| " }\n", | |
| "\n", | |
| " function dragended(d,i) {\n", | |
| " d3.select(this).classed(\"dragging\", false);\n", | |
| " // feed back the new position to python, triggering 'change' on the widget\n", | |
| " $('#GraphView01_id').val(\"\" + i + \",\" + d[0] + \",\" + d[1]).trigger(\"change\");\n", | |
| " }\n", | |
| "}\n", | |
| " mpld3.draw_figure(\"fig_el324261403260775081289086030123\", {\"height\": 240.0, \"data\": {\"data01\": [[5.285566674332074, 3.8304170405840052], [2.4421450620461194, 3.239889534710601], [1.0789219606138425, 1.8824830041905845]], \"data02\": [[0.0, -1.2275585415969057], [0.20408163265306123, -0.6312410552765161], [0.40816326530612246, 0.032158642930433017], [0.6122448979591837, 0.691852122414116], [0.8163265306122449, 1.2792357596853972], [1.0204081632653061, 1.7625854212124106], [1.2244897959183674, 2.144744660124238], [1.4285714285714286, 2.443557339584657], [1.6326530612244898, 2.6783783886638752], [1.836734693877551, 2.865206686357047], [2.0408163265306123, 3.016076349229062], [2.2448979591836737, 3.1397529526459174], [2.4489795918367347, 3.2425860300746634], [2.6530612244897958, 3.3292047991428433], [2.857142857142857, 3.403024153899514], [3.0612244897959187, 3.4665982326108407], [3.2653061224489797, 3.5218648357670532], [3.4693877551020407, 3.5703148028613785], [3.673469387755102, 3.613110412062255], [3.8775510204081636, 3.6511691110786915], [4.081632653061225, 3.6852234928379852], [4.285714285714286, 3.71586482053464], [4.4897959183673475, 3.7435750229293774], [4.6938775510204085, 3.7687505073064673], [4.8979591836734695, 3.7917200929324637], [5.1020408163265305, 3.8127586681967935], [5.3061224489795915, 3.8320977009926405], [5.510204081632653, 3.849933407641196], [5.714285714285714, 3.866433161093829], [5.918367346938775, 3.8817405618287517], [6.122448979591837, 3.895979483414301], [6.326530612244898, 3.9092573249063216], [6.530612244897959, 3.921667644503618], [6.73469387755102, 3.933292306687915], [6.938775510204081, 3.9442032439443118], [7.142857142857143, 3.9544639109842796], [7.346938775510204, 3.9641304919934175], [7.551020408163265, 3.973252908254589], [7.755102040816327, 3.9818756634484354], [7.959183673469388, 3.9900385562102074], [8.16326530612245, 3.9977772835442438], [8.36734693877551, 4.0051239540396475], [8.571428571428571, 4.012107526178062], [8.775510204081632, 4.018754184142539], [8.979591836734695, 4.025087661249438], [9.183673469387756, 4.031129519300158], [9.387755102040817, 4.03689939068531], [9.591836734693878, 4.042415188893274], [9.795918367346939, 4.047693292118434], [10.0, 4.052748703885634]]}, \"axes\": [{\"xscale\": \"linear\", \"ydomain\": [-2.0, 5.0], \"zoomable\": true, \"sharey\": [], \"texts\": [{\"alpha\": 1, \"text\": \"Click and Drag\\n, we match on : [ 2.73 1.21 -0.48]\", \"v_baseline\": \"auto\", \"fontsize\": 12.0, \"zorder\": 3, \"position\": [0.5, 1.0289351851851851], \"h_anchor\": \"middle\", \"id\": \"el32426140326077850008\", \"rotation\": -0.0, \"color\": \"#262626\", \"coordinates\": \"axes\"}], \"id\": \"el32426140326084427056\", \"axesbgalpha\": null, \"paths\": [], \"images\": [], \"axes\": [{\"nticks\": 6, \"position\": \"bottom\", \"tickformat\": null, \"scale\": \"linear\", \"grid\": {\"dasharray\": \"none\", \"gridOn\": true, \"alpha\": 1.0, \"color\": \"#FFFFFF\"}, \"tickvalues\": null, \"fontsize\": 13.0}, {\"nticks\": 8, \"position\": \"left\", \"tickformat\": null, \"scale\": \"linear\", \"grid\": {\"dasharray\": \"none\", \"gridOn\": true, \"alpha\": 1.0, \"color\": \"#FFFFFF\"}, \"tickvalues\": null, \"fontsize\": 13.0}], \"xdomain\": [0.0, 10.0], \"lines\": [{\"yindex\": 1, \"alpha\": 1, \"color\": \"#FF0000\", \"dasharray\": \"none\", \"id\": \"el32426140326083340216\", \"linewidth\": 2.275, \"data\": \"data02\", \"zorder\": 2, \"coordinates\": \"data\", \"xindex\": 0}], \"axesbg\": \"#EAEAF2\", \"collections\": [], \"yscale\": \"linear\", \"ylim\": [-2.0, 5.0], \"sharex\": [], \"xlim\": [0.0, 10.0], \"markers\": [{\"yindex\": 1, \"alpha\": 0.5, \"edgewidth\": 1, \"facecolor\": \"#FF0000\", \"id\": \"el32426140326080458312pts\", \"markerpath\": [[[0.0, 5.0], [1.3260155, 5.0], [2.597899353924267, 4.473168457941209], [3.5355339059327378, 3.5355339059327378], [4.473168457941209, 2.597899353924267], [5.0, 1.3260155], [5.0, 0.0], [5.0, -1.3260155], [4.473168457941209, -2.597899353924267], [3.5355339059327378, -3.5355339059327378], [2.597899353924267, -4.473168457941209], [1.3260155, -5.0], [0.0, -5.0], [-1.3260155, -5.0], [-2.597899353924267, -4.473168457941209], [-3.5355339059327378, -3.5355339059327378], [-4.473168457941209, -2.597899353924267], [-5.0, -1.3260155], [-5.0, 0.0], [-5.0, 1.3260155], [-4.473168457941209, 2.597899353924267], [-3.5355339059327378, 3.5355339059327378], [-2.597899353924267, 4.473168457941209], [-1.3260155, 5.0], [0.0, 5.0]], [\"M\", \"C\", \"C\", \"C\", \"C\", \"C\", \"C\", \"C\", \"C\", \"Z\"]], \"edgecolor\": \"#000000\", \"data\": \"data01\", \"zorder\": 2, \"coordinates\": \"data\", \"xindex\": 0}], \"bbox\": [0.125, 0.09999999999999998, 0.775, 0.8]}], \"id\": \"el32426140326077508128\", \"plugins\": [{\"type\": \"reset\"}, {\"button\": true, \"enabled\": false, \"type\": \"zoom\"}, {\"button\": true, \"enabled\": false, \"type\": \"boxzoom\"}, {\"id\": \"el32426140326080458312pts\", \"type\": \"drag\"}], \"width\": 480.0});\n", | |
| " });\n", | |
| " });\n", | |
| "}else{\n", | |
| " // require.js not available: dynamically load d3 & mpld3\n", | |
| " mpld3_load_lib(\"https://mpld3.github.io/js/d3.v3.min.js\", function(){\n", | |
| " mpld3_load_lib(\"https://mpld3.github.io/js/mpld3.v0.3git.js\", function(){\n", | |
| " \n", | |
| "$('#GraphView01_id').hide();\n", | |
| "mpld3.register_plugin(\"drag\", DragPlugin);\n", | |
| "DragPlugin.prototype = Object.create(mpld3.Plugin.prototype);\n", | |
| "DragPlugin.prototype.constructor = DragPlugin;\n", | |
| "DragPlugin.prototype.requiredProps = [\"id\"];\n", | |
| "DragPlugin.prototype.defaultProps = {}\n", | |
| "function DragPlugin(fig, props){\n", | |
| " mpld3.Plugin.call(this, fig, props);\n", | |
| " mpld3.insert_css(\"#\" + fig.figid + \" path.dragging\",\n", | |
| " {\"fill-opacity\": \"1.0 !important\",\n", | |
| " \"stroke-opacity\": \"1.0 !important\"});\n", | |
| "};$\n", | |
| "\n", | |
| "DragPlugin.prototype.draw = function(){\n", | |
| " var obj = mpld3.get_element(this.props.id);\n", | |
| "\n", | |
| " var drag = d3.behavior.drag()\n", | |
| " .origin(function(d) { return {x:obj.ax.x(d[0]),\n", | |
| " y:obj.ax.y(d[1])}; })\n", | |
| " .on(\"dragstart\", dragstarted)\n", | |
| " .on(\"drag\", dragged)\n", | |
| " .on(\"dragend\", dragended);\n", | |
| "\n", | |
| " obj.elements()\n", | |
| " .data(obj.offsets)\n", | |
| " .style(\"cursor\", \"default\")\n", | |
| " .call(drag);\n", | |
| "\n", | |
| " function dragstarted(d) {\n", | |
| " d3.event.sourceEvent.stopPropagation();\n", | |
| " d3.select(this).classed(\"dragging\", true);\n", | |
| " }\n", | |
| "\n", | |
| " function dragged(d, i) {\n", | |
| " d[0] = obj.ax.x.invert(d3.event.x);\n", | |
| " d[1] = obj.ax.y.invert(d3.event.y);\n", | |
| " d3.select(this)\n", | |
| " .attr(\"transform\", \"translate(\" + [d3.event.x,d3.event.y] + \")\");\n", | |
| " }\n", | |
| "\n", | |
| " function dragended(d,i) {\n", | |
| " d3.select(this).classed(\"dragging\", false);\n", | |
| " // feed back the new position to python, triggering 'change' on the widget\n", | |
| " $('#GraphView01_id').val(\"\" + i + \",\" + d[0] + \",\" + d[1]).trigger(\"change\");\n", | |
| " }\n", | |
| "}\n", | |
| " mpld3.draw_figure(\"fig_el324261403260775081289086030123\", {\"height\": 240.0, \"data\": {\"data01\": [[5.285566674332074, 3.8304170405840052], [2.4421450620461194, 3.239889534710601], [1.0789219606138425, 1.8824830041905845]], \"data02\": [[0.0, -1.2275585415969057], [0.20408163265306123, -0.6312410552765161], [0.40816326530612246, 0.032158642930433017], [0.6122448979591837, 0.691852122414116], [0.8163265306122449, 1.2792357596853972], [1.0204081632653061, 1.7625854212124106], [1.2244897959183674, 2.144744660124238], [1.4285714285714286, 2.443557339584657], [1.6326530612244898, 2.6783783886638752], [1.836734693877551, 2.865206686357047], [2.0408163265306123, 3.016076349229062], [2.2448979591836737, 3.1397529526459174], [2.4489795918367347, 3.2425860300746634], [2.6530612244897958, 3.3292047991428433], [2.857142857142857, 3.403024153899514], [3.0612244897959187, 3.4665982326108407], [3.2653061224489797, 3.5218648357670532], [3.4693877551020407, 3.5703148028613785], [3.673469387755102, 3.613110412062255], [3.8775510204081636, 3.6511691110786915], [4.081632653061225, 3.6852234928379852], [4.285714285714286, 3.71586482053464], [4.4897959183673475, 3.7435750229293774], [4.6938775510204085, 3.7687505073064673], [4.8979591836734695, 3.7917200929324637], [5.1020408163265305, 3.8127586681967935], [5.3061224489795915, 3.8320977009926405], [5.510204081632653, 3.849933407641196], [5.714285714285714, 3.866433161093829], [5.918367346938775, 3.8817405618287517], [6.122448979591837, 3.895979483414301], [6.326530612244898, 3.9092573249063216], [6.530612244897959, 3.921667644503618], [6.73469387755102, 3.933292306687915], [6.938775510204081, 3.9442032439443118], [7.142857142857143, 3.9544639109842796], [7.346938775510204, 3.9641304919934175], [7.551020408163265, 3.973252908254589], [7.755102040816327, 3.9818756634484354], [7.959183673469388, 3.9900385562102074], [8.16326530612245, 3.9977772835442438], [8.36734693877551, 4.0051239540396475], [8.571428571428571, 4.012107526178062], [8.775510204081632, 4.018754184142539], [8.979591836734695, 4.025087661249438], [9.183673469387756, 4.031129519300158], [9.387755102040817, 4.03689939068531], [9.591836734693878, 4.042415188893274], [9.795918367346939, 4.047693292118434], [10.0, 4.052748703885634]]}, \"axes\": [{\"xscale\": \"linear\", \"ydomain\": [-2.0, 5.0], \"zoomable\": true, \"sharey\": [], \"texts\": [{\"alpha\": 1, \"text\": \"Click and Drag\\n, we match on : [ 2.73 1.21 -0.48]\", \"v_baseline\": \"auto\", \"fontsize\": 12.0, \"zorder\": 3, \"position\": [0.5, 1.0289351851851851], \"h_anchor\": \"middle\", \"id\": \"el32426140326077850008\", \"rotation\": -0.0, \"color\": \"#262626\", \"coordinates\": \"axes\"}], \"id\": \"el32426140326084427056\", \"axesbgalpha\": null, \"paths\": [], \"images\": [], \"axes\": [{\"nticks\": 6, \"position\": \"bottom\", \"tickformat\": null, \"scale\": \"linear\", \"grid\": {\"dasharray\": \"none\", \"gridOn\": true, \"alpha\": 1.0, \"color\": \"#FFFFFF\"}, \"tickvalues\": null, \"fontsize\": 13.0}, {\"nticks\": 8, \"position\": \"left\", \"tickformat\": null, \"scale\": \"linear\", \"grid\": {\"dasharray\": \"none\", \"gridOn\": true, \"alpha\": 1.0, \"color\": \"#FFFFFF\"}, \"tickvalues\": null, \"fontsize\": 13.0}], \"xdomain\": [0.0, 10.0], \"lines\": [{\"yindex\": 1, \"alpha\": 1, \"color\": \"#FF0000\", \"dasharray\": \"none\", \"id\": \"el32426140326083340216\", \"linewidth\": 2.275, \"data\": \"data02\", \"zorder\": 2, \"coordinates\": \"data\", \"xindex\": 0}], \"axesbg\": \"#EAEAF2\", \"collections\": [], \"yscale\": \"linear\", \"ylim\": [-2.0, 5.0], \"sharex\": [], \"xlim\": [0.0, 10.0], \"markers\": [{\"yindex\": 1, \"alpha\": 0.5, \"edgewidth\": 1, \"facecolor\": \"#FF0000\", \"id\": \"el32426140326080458312pts\", \"markerpath\": [[[0.0, 5.0], [1.3260155, 5.0], [2.597899353924267, 4.473168457941209], [3.5355339059327378, 3.5355339059327378], [4.473168457941209, 2.597899353924267], [5.0, 1.3260155], [5.0, 0.0], [5.0, -1.3260155], [4.473168457941209, -2.597899353924267], [3.5355339059327378, -3.5355339059327378], [2.597899353924267, -4.473168457941209], [1.3260155, -5.0], [0.0, -5.0], [-1.3260155, -5.0], [-2.597899353924267, -4.473168457941209], [-3.5355339059327378, -3.5355339059327378], [-4.473168457941209, -2.597899353924267], [-5.0, -1.3260155], [-5.0, 0.0], [-5.0, 1.3260155], [-4.473168457941209, 2.597899353924267], [-3.5355339059327378, 3.5355339059327378], [-2.597899353924267, 4.473168457941209], [-1.3260155, 5.0], [0.0, 5.0]], [\"M\", \"C\", \"C\", \"C\", \"C\", \"C\", \"C\", \"C\", \"C\", \"Z\"]], \"edgecolor\": \"#000000\", \"data\": \"data01\", \"zorder\": 2, \"coordinates\": \"data\", \"xindex\": 0}], \"bbox\": [0.125, 0.09999999999999998, 0.775, 0.8]}], \"id\": \"el32426140326077508128\", \"plugins\": [{\"type\": \"reset\"}, {\"button\": true, \"enabled\": false, \"type\": \"zoom\"}, {\"button\": true, \"enabled\": false, \"type\": \"boxzoom\"}, {\"id\": \"el32426140326080458312pts\", \"type\": \"drag\"}], \"width\": 480.0});\n", | |
| " })\n", | |
| " });\n", | |
| "}\n", | |
| "</script>" | |
| ], | |
| "text/plain": [ | |
| "<IPython.core.display.HTML object>" | |
| ] | |
| }, | |
| "metadata": {}, | |
| "output_type": "display_data" | |
| }, | |
| { | |
| "data": { | |
| "application/javascript": [ | |
| "$('#GraphView02_id').val(\"2,1.0789219606138425,1.8824830041905845\").trigger(\"change\").hide();" | |
| ], | |
| "text/plain": [ | |
| "<IPython.core.display.Javascript object>" | |
| ] | |
| }, | |
| "metadata": {}, | |
| "output_type": "display_data" | |
| }, | |
| { | |
| "data": { | |
| "application/javascript": [ | |
| "$('#GraphView02_id').val(\"2,1.0789219606138425,1.8824830041905845\").trigger(\"change\").hide();" | |
| ], | |
| "text/plain": [ | |
| "<IPython.core.display.Javascript object>" | |
| ] | |
| }, | |
| "metadata": {}, | |
| "output_type": "display_data" | |
| }, | |
| { | |
| "data": { | |
| "application/javascript": [ | |
| "$('#GraphView02_id').val(\"2,1.0789219606138425,1.8824830041905845\").trigger(\"change\").hide();" | |
| ], | |
| "text/plain": [ | |
| "<IPython.core.display.Javascript object>" | |
| ] | |
| }, | |
| "metadata": {}, | |
| "output_type": "display_data" | |
| }, | |
| { | |
| "data": { | |
| "application/javascript": [ | |
| "$('#GraphView02_id').val(\"2,1.0789219606138425,1.8824830041905845\").trigger(\"change\").hide();" | |
| ], | |
| "text/plain": [ | |
| "<IPython.core.display.Javascript object>" | |
| ] | |
| }, | |
| "metadata": {}, | |
| "output_type": "display_data" | |
| } | |
| ], | |
| "source": [ | |
| "w2 = GraphWidget(widgen_name='GraphView02')\n", | |
| "w.dependents.append(w2)\n", | |
| "\n", | |
| "def arctan(x, params):\n", | |
| " return params[0] * np.arctan(params[1] * x + params[2])\n", | |
| "\n", | |
| "my_fit = Fit(arctan, widgen_id=w.ref_name)\n", | |
| "\n", | |
| "def f(coord):\n", | |
| " return my_fit.redraw(coord)\n", | |
| " \n", | |
| "interact(f, coord=w)" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": 109, | |
| "metadata": { | |
| "collapsed": false | |
| }, | |
| "outputs": [ | |
| { | |
| "data": { | |
| "text/html": [ | |
| "\n", | |
| "\n", | |
| "<style>\n", | |
| "\n", | |
| "</style>\n", | |
| "\n", | |
| "<div id=\"fig_el324261403260817324486312718479\"></div>\n", | |
| "<script>\n", | |
| "function mpld3_load_lib(url, callback){\n", | |
| " var s = document.createElement('script');\n", | |
| " s.src = url;\n", | |
| " s.async = true;\n", | |
| " s.onreadystatechange = s.onload = callback;\n", | |
| " s.onerror = function(){console.warn(\"failed to load library \" + url);};\n", | |
| " document.getElementsByTagName(\"head\")[0].appendChild(s);\n", | |
| "}\n", | |
| "\n", | |
| "if(typeof(mpld3) !== \"undefined\" && mpld3._mpld3IsLoaded){\n", | |
| " // already loaded: just create the figure\n", | |
| " !function(mpld3){\n", | |
| " \n", | |
| " mpld3.draw_figure(\"fig_el324261403260817324486312718479\", {\"height\": 240.0, \"data\": {\"data03\": [[3.0, -0.4828307034992681], [3.8, -0.4828307034992681], [3.8, 0.0], [3.0, 0.0]], \"data01\": [[1.0, 0.0], [1.8, 0.0], [1.8, 2.729011178554245], [1.0, 2.729011178554245]], \"data02\": [[2.0, 0.0], [2.8, 0.0], [2.8, 1.2118073377406386], [2.0, 1.2118073377406386]]}, \"axes\": [{\"xscale\": \"linear\", \"ydomain\": [-0.5, 3.0], \"zoomable\": true, \"sharey\": [], \"texts\": [], \"id\": \"el32426140326084555440\", \"axesbgalpha\": null, \"paths\": [{\"yindex\": 1, \"alpha\": 1, \"pathcodes\": [\"M\", \"L\", \"L\", \"L\", \"Z\"], \"dasharray\": \"none\", \"edgecolor\": \"#000000\", \"zorder\": 1, \"edgewidth\": 0.39, \"id\": \"el32426140326077547128\", \"facecolor\": \"#4C72B0\", \"data\": \"data01\", \"coordinates\": \"data\", \"xindex\": 0}, {\"yindex\": 1, \"alpha\": 1, \"pathcodes\": [\"M\", \"L\", \"L\", \"L\", \"Z\"], \"dasharray\": \"none\", \"edgecolor\": \"#000000\", \"zorder\": 1, \"edgewidth\": 0.39, \"id\": \"el32426140326079349648\", \"facecolor\": \"#4C72B0\", \"data\": \"data02\", \"coordinates\": \"data\", \"xindex\": 0}, {\"yindex\": 1, \"alpha\": 1, \"pathcodes\": [\"M\", \"L\", \"L\", \"L\", \"Z\"], \"dasharray\": \"none\", \"edgecolor\": \"#000000\", \"zorder\": 1, \"edgewidth\": 0.39, \"id\": \"el32426140326079351104\", \"facecolor\": \"#4C72B0\", \"data\": \"data03\", \"coordinates\": \"data\", \"xindex\": 0}], \"images\": [], \"axes\": [{\"nticks\": 7, \"position\": \"bottom\", \"tickformat\": null, \"scale\": \"linear\", \"grid\": {\"dasharray\": \"none\", \"gridOn\": true, \"alpha\": 1.0, \"color\": \"#FFFFFF\"}, \"tickvalues\": null, \"fontsize\": 13.0}, {\"nticks\": 8, \"position\": \"left\", \"tickformat\": null, \"scale\": \"linear\", \"grid\": {\"dasharray\": \"none\", \"gridOn\": true, \"alpha\": 1.0, \"color\": \"#FFFFFF\"}, \"tickvalues\": null, \"fontsize\": 13.0}], \"xdomain\": [1.0, 4.0], \"lines\": [], \"axesbg\": \"#EAEAF2\", \"collections\": [], \"yscale\": \"linear\", \"ylim\": [-0.5, 3.0], \"sharex\": [], \"xlim\": [1.0, 4.0], \"markers\": [], \"bbox\": [0.125, 0.09999999999999998, 0.775, 0.8]}], \"id\": \"el32426140326081732448\", \"plugins\": [{\"type\": \"reset\"}, {\"button\": true, \"enabled\": false, \"type\": \"zoom\"}, {\"button\": true, \"enabled\": false, \"type\": \"boxzoom\"}], \"width\": 480.0});\n", | |
| " }(mpld3);\n", | |
| "}else if(typeof define === \"function\" && define.amd){\n", | |
| " // require.js is available: use it to load d3/mpld3\n", | |
| " require.config({paths: {d3: \"https://mpld3.github.io/js/d3.v3.min\"}});\n", | |
| " require([\"d3\"], function(d3){\n", | |
| " window.d3 = d3;\n", | |
| " mpld3_load_lib(\"https://mpld3.github.io/js/mpld3.v0.3git.js\", function(){\n", | |
| " \n", | |
| " mpld3.draw_figure(\"fig_el324261403260817324486312718479\", {\"height\": 240.0, \"data\": {\"data03\": [[3.0, -0.4828307034992681], [3.8, -0.4828307034992681], [3.8, 0.0], [3.0, 0.0]], \"data01\": [[1.0, 0.0], [1.8, 0.0], [1.8, 2.729011178554245], [1.0, 2.729011178554245]], \"data02\": [[2.0, 0.0], [2.8, 0.0], [2.8, 1.2118073377406386], [2.0, 1.2118073377406386]]}, \"axes\": [{\"xscale\": \"linear\", \"ydomain\": [-0.5, 3.0], \"zoomable\": true, \"sharey\": [], \"texts\": [], \"id\": \"el32426140326084555440\", \"axesbgalpha\": null, \"paths\": [{\"yindex\": 1, \"alpha\": 1, \"pathcodes\": [\"M\", \"L\", \"L\", \"L\", \"Z\"], \"dasharray\": \"none\", \"edgecolor\": \"#000000\", \"zorder\": 1, \"edgewidth\": 0.39, \"id\": \"el32426140326077547128\", \"facecolor\": \"#4C72B0\", \"data\": \"data01\", \"coordinates\": \"data\", \"xindex\": 0}, {\"yindex\": 1, \"alpha\": 1, \"pathcodes\": [\"M\", \"L\", \"L\", \"L\", \"Z\"], \"dasharray\": \"none\", \"edgecolor\": \"#000000\", \"zorder\": 1, \"edgewidth\": 0.39, \"id\": \"el32426140326079349648\", \"facecolor\": \"#4C72B0\", \"data\": \"data02\", \"coordinates\": \"data\", \"xindex\": 0}, {\"yindex\": 1, \"alpha\": 1, \"pathcodes\": [\"M\", \"L\", \"L\", \"L\", \"Z\"], \"dasharray\": \"none\", \"edgecolor\": \"#000000\", \"zorder\": 1, \"edgewidth\": 0.39, \"id\": \"el32426140326079351104\", \"facecolor\": \"#4C72B0\", \"data\": \"data03\", \"coordinates\": \"data\", \"xindex\": 0}], \"images\": [], \"axes\": [{\"nticks\": 7, \"position\": \"bottom\", \"tickformat\": null, \"scale\": \"linear\", \"grid\": {\"dasharray\": \"none\", \"gridOn\": true, \"alpha\": 1.0, \"color\": \"#FFFFFF\"}, \"tickvalues\": null, \"fontsize\": 13.0}, {\"nticks\": 8, \"position\": \"left\", \"tickformat\": null, \"scale\": \"linear\", \"grid\": {\"dasharray\": \"none\", \"gridOn\": true, \"alpha\": 1.0, \"color\": \"#FFFFFF\"}, \"tickvalues\": null, \"fontsize\": 13.0}], \"xdomain\": [1.0, 4.0], \"lines\": [], \"axesbg\": \"#EAEAF2\", \"collections\": [], \"yscale\": \"linear\", \"ylim\": [-0.5, 3.0], \"sharex\": [], \"xlim\": [1.0, 4.0], \"markers\": [], \"bbox\": [0.125, 0.09999999999999998, 0.775, 0.8]}], \"id\": \"el32426140326081732448\", \"plugins\": [{\"type\": \"reset\"}, {\"button\": true, \"enabled\": false, \"type\": \"zoom\"}, {\"button\": true, \"enabled\": false, \"type\": \"boxzoom\"}], \"width\": 480.0});\n", | |
| " });\n", | |
| " });\n", | |
| "}else{\n", | |
| " // require.js not available: dynamically load d3 & mpld3\n", | |
| " mpld3_load_lib(\"https://mpld3.github.io/js/d3.v3.min.js\", function(){\n", | |
| " mpld3_load_lib(\"https://mpld3.github.io/js/mpld3.v0.3git.js\", function(){\n", | |
| " \n", | |
| " mpld3.draw_figure(\"fig_el324261403260817324486312718479\", {\"height\": 240.0, \"data\": {\"data03\": [[3.0, -0.4828307034992681], [3.8, -0.4828307034992681], [3.8, 0.0], [3.0, 0.0]], \"data01\": [[1.0, 0.0], [1.8, 0.0], [1.8, 2.729011178554245], [1.0, 2.729011178554245]], \"data02\": [[2.0, 0.0], [2.8, 0.0], [2.8, 1.2118073377406386], [2.0, 1.2118073377406386]]}, \"axes\": [{\"xscale\": \"linear\", \"ydomain\": [-0.5, 3.0], \"zoomable\": true, \"sharey\": [], \"texts\": [], \"id\": \"el32426140326084555440\", \"axesbgalpha\": null, \"paths\": [{\"yindex\": 1, \"alpha\": 1, \"pathcodes\": [\"M\", \"L\", \"L\", \"L\", \"Z\"], \"dasharray\": \"none\", \"edgecolor\": \"#000000\", \"zorder\": 1, \"edgewidth\": 0.39, \"id\": \"el32426140326077547128\", \"facecolor\": \"#4C72B0\", \"data\": \"data01\", \"coordinates\": \"data\", \"xindex\": 0}, {\"yindex\": 1, \"alpha\": 1, \"pathcodes\": [\"M\", \"L\", \"L\", \"L\", \"Z\"], \"dasharray\": \"none\", \"edgecolor\": \"#000000\", \"zorder\": 1, \"edgewidth\": 0.39, \"id\": \"el32426140326079349648\", \"facecolor\": \"#4C72B0\", \"data\": \"data02\", \"coordinates\": \"data\", \"xindex\": 0}, {\"yindex\": 1, \"alpha\": 1, \"pathcodes\": [\"M\", \"L\", \"L\", \"L\", \"Z\"], \"dasharray\": \"none\", \"edgecolor\": \"#000000\", \"zorder\": 1, \"edgewidth\": 0.39, \"id\": \"el32426140326079351104\", \"facecolor\": \"#4C72B0\", \"data\": \"data03\", \"coordinates\": \"data\", \"xindex\": 0}], \"images\": [], \"axes\": [{\"nticks\": 7, \"position\": \"bottom\", \"tickformat\": null, \"scale\": \"linear\", \"grid\": {\"dasharray\": \"none\", \"gridOn\": true, \"alpha\": 1.0, \"color\": \"#FFFFFF\"}, \"tickvalues\": null, \"fontsize\": 13.0}, {\"nticks\": 8, \"position\": \"left\", \"tickformat\": null, \"scale\": \"linear\", \"grid\": {\"dasharray\": \"none\", \"gridOn\": true, \"alpha\": 1.0, \"color\": \"#FFFFFF\"}, \"tickvalues\": null, \"fontsize\": 13.0}], \"xdomain\": [1.0, 4.0], \"lines\": [], \"axesbg\": \"#EAEAF2\", \"collections\": [], \"yscale\": \"linear\", \"ylim\": [-0.5, 3.0], \"sharex\": [], \"xlim\": [1.0, 4.0], \"markers\": [], \"bbox\": [0.125, 0.09999999999999998, 0.775, 0.8]}], \"id\": \"el32426140326081732448\", \"plugins\": [{\"type\": \"reset\"}, {\"button\": true, \"enabled\": false, \"type\": \"zoom\"}, {\"button\": true, \"enabled\": false, \"type\": \"boxzoom\"}], \"width\": 480.0});\n", | |
| " })\n", | |
| " });\n", | |
| "}\n", | |
| "</script>" | |
| ], | |
| "text/plain": [ | |
| "<IPython.core.display.HTML object>" | |
| ] | |
| }, | |
| "metadata": {}, | |
| "output_type": "display_data" | |
| } | |
| ], | |
| "source": [ | |
| "def out(c):\n", | |
| " fig, ax = plt.subplots(figsize=(6,3))\n", | |
| " ax.bar([1,2,3],my_fit.fit)\n", | |
| " fig_h = mpld3.display(fig=fig)\n", | |
| " display(fig_h) \n", | |
| " \n", | |
| "interact(out, c=w2)" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": null, | |
| "metadata": { | |
| "collapsed": true | |
| }, | |
| "outputs": [], | |
| "source": [] | |
| } | |
| ], | |
| "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.4.3" | |
| } | |
| }, | |
| "nbformat": 4, | |
| "nbformat_minor": 0 | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment