Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save aflaxman/988cb466117430e8ba1b to your computer and use it in GitHub Desktop.
Save aflaxman/988cb466117430e8ba1b to your computer and use it in GitHub Desktop.
Display the source blob
Display the rendered blob
Raw
{
"metadata": {
"name": "",
"signature": "sha256:d5560713990ad26493d1beb4c66bd954bd11b2fad455409570800b994d5cc911"
},
"nbformat": 3,
"nbformat_minor": 0,
"worksheets": [
{
"cells": [
{
"cell_type": "code",
"collapsed": false,
"input": [
"!date"
],
"language": "python",
"metadata": {},
"outputs": [
{
"output_type": "stream",
"stream": "stdout",
"text": [
"Mon Jun 2 10:19:47 PDT 2014\r\n"
]
}
],
"prompt_number": 1
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"import matplotlib.pyplot as plt\n",
"import mpld3\n",
"%matplotlib inline"
],
"language": "python",
"metadata": {},
"outputs": [],
"prompt_number": 2
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"class HelloWorld(mpld3.plugins.PluginBase): # inherit from PluginBase\n",
" \"\"\"Hello World plugin\"\"\"\n",
" \n",
" JAVASCRIPT = \"\"\"\n",
" mpld3.register_plugin(\"helloworld\", HelloWorld);\n",
" HelloWorld.prototype = Object.create(mpld3.Plugin.prototype);\n",
" HelloWorld.prototype.constructor = HelloWorld;\n",
" function HelloWorld(fig, props){\n",
" mpld3.Plugin.call(this, fig, props);\n",
" };\n",
" \n",
" HelloWorld.prototype.draw = function(){\n",
" // FIXME: this is a very brittle way to select the y-axis element\n",
" var ax = this.fig.axes[0].elements[1];\n",
"\n",
" // see https://github.com/mbostock/d3/wiki/Formatting#d3_format\n",
" // for d3js formating documentation\n",
" ax.axis.tickFormat(d3.format(\"d\"));\n",
"\n",
" // TODO: use a function for tick values that\n",
" // updates when values pan and zoom\n",
" ax.axis.tickValues([1,100,1000]);\n",
"\n",
" // HACK: use reset to redraw figure\n",
" this.fig.reset(); \n",
" }\n",
" \"\"\"\n",
" def __init__(self):\n",
" self.dict_ = {\"type\": \"helloworld\"}\n"
],
"language": "python",
"metadata": {},
"outputs": [],
"prompt_number": 3
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"fig, ax = plt.subplots()\n",
"ax.set_yscale('log')\n",
"ax.plot([3,1,4,1,5,9,100,1000], 'ko-', mfc='k', mew=2, mec='w', ms=10)\n",
"\n",
"ax_fmt = HelloWorld()\n",
"mpld3.plugins.connect(fig, ax_fmt)\n",
"\n",
"mpld3.display()"
],
"language": "python",
"metadata": {},
"outputs": [
{
"html": [
"\n",
"\n",
"<style>\n",
"\n",
"</style>\n",
"\n",
"<div id=\"fig_el15826544437283481749289\"></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.register_plugin(\"helloworld\", HelloWorld);\n",
" HelloWorld.prototype = Object.create(mpld3.Plugin.prototype);\n",
" HelloWorld.prototype.constructor = HelloWorld;\n",
" function HelloWorld(fig, props){\n",
" mpld3.Plugin.call(this, fig, props);\n",
" };\n",
" \n",
" HelloWorld.prototype.draw = function(){\n",
" // FIXME: this is a very brittle way to select the y-axis element\n",
" var ax = this.fig.axes[0].elements[1];\n",
"\n",
" // see https://github.com/mbostock/d3/wiki/Formatting#d3_format\n",
" // for d3js formating documentation\n",
" ax.axis.tickFormat(d3.format(\"d\"));\n",
"\n",
" // TODO: use a function for tick values that\n",
" // updates when values pan and zoom\n",
" ax.axis.tickValues([1,100,1000]);\n",
"\n",
" // HACK: use reset to redraw figure\n",
" this.fig.reset(); \n",
" }\n",
" \n",
" mpld3.draw_figure(\"fig_el15826544437283481749289\", {\"axes\": [{\"xlim\": [0.0, 7.0], \"yscale\": \"log\", \"axesbg\": \"#FFFFFF\", \"texts\": [], \"zoomable\": true, \"images\": [], \"xdomain\": [0.0, 7.0], \"ylim\": [1.0, 1000.0], \"paths\": [], \"sharey\": [], \"sharex\": [], \"axesbgalpha\": null, \"axes\": [{\"scale\": \"linear\", \"tickformat\": null, \"grid\": {\"gridOn\": false}, \"fontsize\": 10.0, \"position\": \"bottom\", \"nticks\": 8, \"tickvalues\": null}, {\"scale\": \"log\", \"tickformat\": null, \"grid\": {\"gridOn\": false}, \"fontsize\": 10.0, \"position\": \"left\", \"nticks\": 6, \"tickvalues\": null}], \"lines\": [{\"color\": \"#000000\", \"yindex\": 1, \"coordinates\": \"data\", \"dasharray\": \"none\", \"zorder\": 2, \"alpha\": 1, \"xindex\": 0, \"linewidth\": 1.0, \"data\": \"data01\", \"id\": \"el1582654814864\"}], \"markers\": [{\"edgecolor\": \"#FFFFFF\", \"facecolor\": \"#000000\", \"edgewidth\": 2, \"yindex\": 1, \"coordinates\": \"data\", \"zorder\": 2, \"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\"]], \"alpha\": 1, \"xindex\": 0, \"data\": \"data01\", \"id\": \"el1582654814864pts\"}], \"id\": \"el1582627806736\", \"ydomain\": [1.0, 1000.0], \"collections\": [], \"xscale\": \"linear\", \"bbox\": [0.125, 0.125, 0.77500000000000002, 0.77500000000000002]}], \"height\": 320.0, \"width\": 480.0, \"plugins\": [{\"type\": \"reset\"}, {\"enabled\": false, \"button\": true, \"type\": \"zoom\"}, {\"enabled\": false, \"button\": true, \"type\": \"boxzoom\"}, {\"type\": \"helloworld\"}], \"data\": {\"data01\": [[0.0, 3.0], [1.0, 1.0], [2.0, 4.0], [3.0, 1.0], [4.0, 5.0], [5.0, 9.0], [6.0, 100.0], [7.0, 1000.0]]}, \"id\": \"el1582654443728\"});\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.register_plugin(\"helloworld\", HelloWorld);\n",
" HelloWorld.prototype = Object.create(mpld3.Plugin.prototype);\n",
" HelloWorld.prototype.constructor = HelloWorld;\n",
" function HelloWorld(fig, props){\n",
" mpld3.Plugin.call(this, fig, props);\n",
" };\n",
" \n",
" HelloWorld.prototype.draw = function(){\n",
" // FIXME: this is a very brittle way to select the y-axis element\n",
" var ax = this.fig.axes[0].elements[1];\n",
"\n",
" // see https://github.com/mbostock/d3/wiki/Formatting#d3_format\n",
" // for d3js formating documentation\n",
" ax.axis.tickFormat(d3.format(\"d\"));\n",
"\n",
" // TODO: use a function for tick values that\n",
" // updates when values pan and zoom\n",
" ax.axis.tickValues([1,100,1000]);\n",
"\n",
" // HACK: use reset to redraw figure\n",
" this.fig.reset(); \n",
" }\n",
" \n",
" mpld3.draw_figure(\"fig_el15826544437283481749289\", {\"axes\": [{\"xlim\": [0.0, 7.0], \"yscale\": \"log\", \"axesbg\": \"#FFFFFF\", \"texts\": [], \"zoomable\": true, \"images\": [], \"xdomain\": [0.0, 7.0], \"ylim\": [1.0, 1000.0], \"paths\": [], \"sharey\": [], \"sharex\": [], \"axesbgalpha\": null, \"axes\": [{\"scale\": \"linear\", \"tickformat\": null, \"grid\": {\"gridOn\": false}, \"fontsize\": 10.0, \"position\": \"bottom\", \"nticks\": 8, \"tickvalues\": null}, {\"scale\": \"log\", \"tickformat\": null, \"grid\": {\"gridOn\": false}, \"fontsize\": 10.0, \"position\": \"left\", \"nticks\": 6, \"tickvalues\": null}], \"lines\": [{\"color\": \"#000000\", \"yindex\": 1, \"coordinates\": \"data\", \"dasharray\": \"none\", \"zorder\": 2, \"alpha\": 1, \"xindex\": 0, \"linewidth\": 1.0, \"data\": \"data01\", \"id\": \"el1582654814864\"}], \"markers\": [{\"edgecolor\": \"#FFFFFF\", \"facecolor\": \"#000000\", \"edgewidth\": 2, \"yindex\": 1, \"coordinates\": \"data\", \"zorder\": 2, \"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\"]], \"alpha\": 1, \"xindex\": 0, \"data\": \"data01\", \"id\": \"el1582654814864pts\"}], \"id\": \"el1582627806736\", \"ydomain\": [1.0, 1000.0], \"collections\": [], \"xscale\": \"linear\", \"bbox\": [0.125, 0.125, 0.77500000000000002, 0.77500000000000002]}], \"height\": 320.0, \"width\": 480.0, \"plugins\": [{\"type\": \"reset\"}, {\"enabled\": false, \"button\": true, \"type\": \"zoom\"}, {\"enabled\": false, \"button\": true, \"type\": \"boxzoom\"}, {\"type\": \"helloworld\"}], \"data\": {\"data01\": [[0.0, 3.0], [1.0, 1.0], [2.0, 4.0], [3.0, 1.0], [4.0, 5.0], [5.0, 9.0], [6.0, 100.0], [7.0, 1000.0]]}, \"id\": \"el1582654443728\"});\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.register_plugin(\"helloworld\", HelloWorld);\n",
" HelloWorld.prototype = Object.create(mpld3.Plugin.prototype);\n",
" HelloWorld.prototype.constructor = HelloWorld;\n",
" function HelloWorld(fig, props){\n",
" mpld3.Plugin.call(this, fig, props);\n",
" };\n",
" \n",
" HelloWorld.prototype.draw = function(){\n",
" // FIXME: this is a very brittle way to select the y-axis element\n",
" var ax = this.fig.axes[0].elements[1];\n",
"\n",
" // see https://github.com/mbostock/d3/wiki/Formatting#d3_format\n",
" // for d3js formating documentation\n",
" ax.axis.tickFormat(d3.format(\"d\"));\n",
"\n",
" // TODO: use a function for tick values that\n",
" // updates when values pan and zoom\n",
" ax.axis.tickValues([1,100,1000]);\n",
"\n",
" // HACK: use reset to redraw figure\n",
" this.fig.reset(); \n",
" }\n",
" \n",
" mpld3.draw_figure(\"fig_el15826544437283481749289\", {\"axes\": [{\"xlim\": [0.0, 7.0], \"yscale\": \"log\", \"axesbg\": \"#FFFFFF\", \"texts\": [], \"zoomable\": true, \"images\": [], \"xdomain\": [0.0, 7.0], \"ylim\": [1.0, 1000.0], \"paths\": [], \"sharey\": [], \"sharex\": [], \"axesbgalpha\": null, \"axes\": [{\"scale\": \"linear\", \"tickformat\": null, \"grid\": {\"gridOn\": false}, \"fontsize\": 10.0, \"position\": \"bottom\", \"nticks\": 8, \"tickvalues\": null}, {\"scale\": \"log\", \"tickformat\": null, \"grid\": {\"gridOn\": false}, \"fontsize\": 10.0, \"position\": \"left\", \"nticks\": 6, \"tickvalues\": null}], \"lines\": [{\"color\": \"#000000\", \"yindex\": 1, \"coordinates\": \"data\", \"dasharray\": \"none\", \"zorder\": 2, \"alpha\": 1, \"xindex\": 0, \"linewidth\": 1.0, \"data\": \"data01\", \"id\": \"el1582654814864\"}], \"markers\": [{\"edgecolor\": \"#FFFFFF\", \"facecolor\": \"#000000\", \"edgewidth\": 2, \"yindex\": 1, \"coordinates\": \"data\", \"zorder\": 2, \"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\"]], \"alpha\": 1, \"xindex\": 0, \"data\": \"data01\", \"id\": \"el1582654814864pts\"}], \"id\": \"el1582627806736\", \"ydomain\": [1.0, 1000.0], \"collections\": [], \"xscale\": \"linear\", \"bbox\": [0.125, 0.125, 0.77500000000000002, 0.77500000000000002]}], \"height\": 320.0, \"width\": 480.0, \"plugins\": [{\"type\": \"reset\"}, {\"enabled\": false, \"button\": true, \"type\": \"zoom\"}, {\"enabled\": false, \"button\": true, \"type\": \"boxzoom\"}, {\"type\": \"helloworld\"}], \"data\": {\"data01\": [[0.0, 3.0], [1.0, 1.0], [2.0, 4.0], [3.0, 1.0], [4.0, 5.0], [5.0, 9.0], [6.0, 100.0], [7.0, 1000.0]]}, \"id\": \"el1582654443728\"});\n",
" })\n",
" });\n",
"}\n",
"</script>"
],
"metadata": {},
"output_type": "pyout",
"prompt_number": 4,
"text": [
"<IPython.core.display.HTML at 0x3442250>"
]
}
],
"prompt_number": 4
}
],
"metadata": {}
}
]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment