Created
February 18, 2016 06:00
-
-
Save johanndt/de3debde4a027915a5d4 to your computer and use it in GitHub Desktop.
Revisions
-
johanndt created this gist
Feb 18, 2016 .There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,196 @@ { "cells": [ { "cell_type": "code", "execution_count": 7, "metadata": { "collapsed": true }, "outputs": [], "source": [ "import toyplot" ] }, { "cell_type": "code", "execution_count": 8, "metadata": { "collapsed": false }, "outputs": [], "source": [ "charts = 6\n", "names = [\"Chart {}\".format(i) for i in range(charts)]\n", "bars = [1.0 for name in names]\n", "data_table = [('Name', names), ('Value', bars)]\n" ] }, { "cell_type": "code", "execution_count": 9, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/html": [ "<div align=\"center\" class=\"toyplot\" id=\"t721d71b81d4f4d9bbd12f401d9383a0f\"><svg height=\"300.0px\" id=\"t08a496dc4bb7497f9052443c23922871\" preserveAspectRatio=\"xMidYMid meet\" style=\"background-color:transparent;fill:rgb(16.1%,15.3%,14.1%);fill-opacity:1.0;font-family:helvetica;font-size:12px;opacity:1.0;stroke:rgb(16.1%,15.3%,14.1%);stroke-opacity:1.0;stroke-width:1.0\" viewBox=\"0 0 600.0 300.0\" width=\"600.0px\" xmlns=\"http://www.w3.org/2000/svg\" xmlns:toyplot=\"http://www.sandia.gov/toyplot\"><g class=\"toyplot-axes-Table\" id=\"t73fb288df5ca46e3919f39887ba44a3a\"><text style=\"alignment-baseline:middle;baseline-shift:100%;font-size:14px;font-weight:bold;stroke:none;text-anchor:middle\" x=\"300.0\" y=\"50.0\">Example Table</text><g class=\"toyplot-axes-Cartesian\" id=\"tcd80895142fb4bf6b941b2ec642342c4\"><clipPath id=\"t680dde7009bb4af29da35775772375ef\"><rect height=\"181.4285714285715\" width=\"260.0\" x=\"295.0\" y=\"73.571428571428569\"></rect></clipPath><g class=\"toyplot-coordinate-events\" clip-path=\"url(#t680dde7009bb4af29da35775772375ef)\" style=\"cursor:crosshair\"><rect height=\"181.4285714285715\" style=\"pointer-events:all;visibility:hidden\" width=\"260.0\" x=\"295.0\" y=\"73.571428571428569\"></rect><g class=\"toyplot-mark-BarMagnitudes\" id=\"td3c970b81c9848a2ad0164af7e52d741\" style=\"stroke:rgb(100%,100%,100%);stroke-opacity:1.0;stroke-width:1.0\"><g class=\"toyplot-Series\"><rect class=\"toyplot-Datum\" height=\"26.373626373626394\" style=\"fill:rgb(40%,76.1%,64.7%);fill-opacity:1.0;opacity:1.0;stroke:rgb(100%,100%,100%);stroke-opacity:1.0;stroke-width:1.0\" width=\"208.33333333333331\" x=\"300.0\" y=\"223.62637362637366\"></rect><rect class=\"toyplot-Datum\" height=\"26.373626373626365\" style=\"fill:rgb(40%,76.1%,64.7%);fill-opacity:1.0;opacity:1.0;stroke:rgb(100%,100%,100%);stroke-opacity:1.0;stroke-width:1.0\" width=\"208.33333333333331\" x=\"300.0\" y=\"197.2527472527473\"></rect><rect class=\"toyplot-Datum\" height=\"26.373626373626394\" style=\"fill:rgb(40%,76.1%,64.7%);fill-opacity:1.0;opacity:1.0;stroke:rgb(100%,100%,100%);stroke-opacity:1.0;stroke-width:1.0\" width=\"208.33333333333331\" x=\"300.0\" y=\"170.8791208791209\"></rect><rect class=\"toyplot-Datum\" height=\"26.373626373626394\" style=\"fill:rgb(40%,76.1%,64.7%);fill-opacity:1.0;opacity:1.0;stroke:rgb(100%,100%,100%);stroke-opacity:1.0;stroke-width:1.0\" width=\"208.33333333333331\" x=\"300.0\" y=\"144.50549450549451\"></rect><rect class=\"toyplot-Datum\" height=\"26.373626373626379\" style=\"fill:rgb(40%,76.1%,64.7%);fill-opacity:1.0;opacity:1.0;stroke:rgb(100%,100%,100%);stroke-opacity:1.0;stroke-width:1.0\" width=\"208.33333333333331\" x=\"300.0\" y=\"118.13186813186813\"></rect><rect class=\"toyplot-Datum\" height=\"26.373626373626379\" style=\"fill:rgb(40%,76.1%,64.7%);fill-opacity:1.0;opacity:1.0;stroke:rgb(100%,100%,100%);stroke-opacity:1.0;stroke-width:1.0\" width=\"208.33333333333331\" x=\"300.0\" y=\"91.758241758241752\"></rect></g></g></g></g><text style=\"alignment-baseline:middle;fill:rgb(16.1%,15.3%,14.1%);fill-opacity:1.0;font-size:12px;font-weight:bold;stroke:none;text-anchor:begin\" x=\"55.0\" y=\"64.285714285714278\">Name</text><text style=\"alignment-baseline:middle;fill:rgb(16.1%,15.3%,14.1%);fill-opacity:1.0;font-size:12px;font-weight:bold;stroke:none;text-anchor:middle\" transform=\"rotate(0,425.0,64.285714285714278)\" x=\"425.0\" y=\"64.285714285714278\">Value</text><text style=\"alignment-baseline:middle;fill:rgb(16.1%,15.3%,14.1%);fill-opacity:1.0;font-size:12px;stroke:none;text-anchor:begin\" x=\"55.0\" y=\"92.857142857142861\">Chart 0</text><text style=\"alignment-baseline:middle;fill:rgb(16.1%,15.3%,14.1%);fill-opacity:1.0;font-size:12px;stroke:none;text-anchor:begin\" x=\"55.0\" y=\"121.42857142857143\">Chart 1</text><text style=\"alignment-baseline:middle;fill:rgb(16.1%,15.3%,14.1%);fill-opacity:1.0;font-size:12px;stroke:none;text-anchor:begin\" x=\"55.0\" y=\"150.0\">Chart 2</text><text style=\"alignment-baseline:middle;fill:rgb(16.1%,15.3%,14.1%);fill-opacity:1.0;font-size:12px;stroke:none;text-anchor:begin\" x=\"55.0\" y=\"178.57142857142861\">Chart 3</text><text style=\"alignment-baseline:middle;fill:rgb(16.1%,15.3%,14.1%);fill-opacity:1.0;font-size:12px;stroke:none;text-anchor:begin\" x=\"55.0\" y=\"207.14285714285717\">Chart 4</text><text style=\"alignment-baseline:middle;fill:rgb(16.1%,15.3%,14.1%);fill-opacity:1.0;font-size:12px;stroke:none;text-anchor:begin\" x=\"55.0\" y=\"235.71428571428578\">Chart 5</text><line style=\"stroke:rgb(16.1%,15.3%,14.1%);stroke-opacity:1.0;stroke-width:0.5\" x1=\"50.0\" x2=\"550.0\" y1=\"78.571428571428569\" y2=\"78.571428571428569\"></line></g></svg><div class=\"toyplot-controls\"><ul class=\"toyplot-mark-popup\" onmouseleave=\"this.style.visibility='hidden'\" style=\"background:rgba(0%,0%,0%,0.75);border:0;border-radius:6px;color:white;cursor:default;list-style:none;margin:0;padding:5px;position:fixed;visibility:hidden\"><li class=\"toyplot-mark-popup-title\" style=\"color:lightgray;cursor:default;padding:5px;list-style:none;margin:0;\"></li><li class=\"toyplot-mark-popup-save-csv\" onmouseout=\"this.style.color='white';this.style.background='steelblue'\" onmouseover=\"this.style.color='steelblue';this.style.background='white'\" style=\"border-radius:3px;padding:5px;list-style:none;margin:0;\">Save as .csv</li></ul><script>\n", "(function()\n", "{\n", " if(window.CSS !== undefined && window.CSS.supports !== undefined)\n", " {\n", " if(!window.CSS.supports(\"alignment-baseline\", \"middle\"))\n", " {\n", " var re = /\\s*alignment-baseline\\s*:\\s*([^;\\s]*)\\s*/;\n", " var text = document.querySelectorAll(\"#t721d71b81d4f4d9bbd12f401d9383a0f text\");\n", " for(var i = 0; i != text.length; ++i)\n", " {\n", " var match = re.exec(text[i].attributes.style.value);\n", " if(match)\n", " {\n", " if(match[1] == \"middle\")\n", " {\n", " var style = getComputedStyle(text[i]);\n", " var font_size = style.fontSize.substr(0, style.fontSize.length - 2);\n", " var dy = text[i].dy.baseVal.length ? text[i].dy.baseVal[0].value : 0;\n", " dy += 0.4 * font_size;\n", " text[i].setAttribute(\"dy\", dy);\n", " }\n", " }\n", " }\n", " }\n", " if(!window.CSS.supports(\"baseline-shift\", \"0\"))\n", " {\n", " var re = /\\s*baseline-shift\\s*:\\s*([^;\\s]*)\\s*/;\n", " var text = document.querySelectorAll(\"#t721d71b81d4f4d9bbd12f401d9383a0f text\");\n", " for(var i = 0; i != text.length; ++i)\n", " {\n", " var match = re.exec(text[i].attributes.style.value);\n", " if(match)\n", " {\n", " var style = getComputedStyle(text[i]);\n", " var font_size = style.fontSize.substr(0, style.fontSize.length - 2);\n", " var percent = 0.01 * match[1].substr(0, match[1].length-1);\n", " var dy = text[i].dy.baseVal.length ? text[i].dy.baseVal[0].value : 0;\n", " dy -= percent * font_size\n", " text[i].setAttribute(\"dy\", dy);\n", " }\n", " }\n", " }\n", " }\n", "})();\n", "</script><script>\n", "(function()\n", "{\n", " var data_tables = [{\"data\": [[-0.5, 0.5, 1.5, 2.5, 3.5, 4.5], [0.5, 1.5, 2.5, 3.5, 4.5, 5.5], [0.0, 0.0, 0.0, 0.0, 0.0, 0.0], [1.0, 1.0, 1.0, 1.0, 1.0, 1.0]], \"title\": \"Bar Data\", \"names\": [\"left\", \"right\", \"baseline\", \"magnitude0\"], \"id\": \"td3c970b81c9848a2ad0164af7e52d741\", \"filename\": \"toyplot\"}];\n", "\n", " function save_csv(data_table)\n", " {\n", " var uri = \"data:text/csv;charset=utf-8,\";\n", " uri += data_table.names.join(\",\") + \"\\n\";\n", " for(var i = 0; i != data_table.data[0].length; ++i)\n", " {\n", " for(var j = 0; j != data_table.data.length; ++j)\n", " {\n", " if(j)\n", " uri += \",\";\n", " uri += data_table.data[j][i];\n", " }\n", " uri += \"\\n\";\n", " }\n", " uri = encodeURI(uri);\n", "\n", " var link = document.createElement(\"a\");\n", " if(typeof link.download != \"undefined\")\n", " {\n", " link.href = uri;\n", " link.style = \"visibility:hidden\";\n", " link.download = data_table.filename + \".csv\";\n", "\n", " document.body.appendChild(link);\n", " link.click();\n", " document.body.removeChild(link);\n", " }\n", " else\n", " {\n", " window.open(uri);\n", " }\n", " }\n", "\n", " function open_popup(data_table)\n", " {\n", " return function(e)\n", " {\n", " var popup = document.querySelector(\"#t721d71b81d4f4d9bbd12f401d9383a0f .toyplot-mark-popup\");\n", " popup.querySelector(\".toyplot-mark-popup-title\").innerHTML = data_table.title;\n", " popup.querySelector(\".toyplot-mark-popup-save-csv\").onclick = function() { popup.style.visibility = \"hidden\"; save_csv(data_table); }\n", " popup.style.left = (e.clientX - 50) + \"px\";\n", " popup.style.top = (e.clientY - 20) + \"px\";\n", " popup.style.visibility = \"visible\";\n", " e.stopPropagation();\n", " e.preventDefault();\n", " }\n", "\n", " }\n", "\n", " for(var i = 0; i != data_tables.length; ++i)\n", " {\n", " var data_table = data_tables[i];\n", " var event_target = document.querySelector(\"#\" + data_table.id);\n", " event_target.oncontextmenu = open_popup(data_table);\n", " }\n", "})();\n", "</script></div></div>" ], "text/plain": [ "<toyplot.canvas.Canvas at 0x45d6518>" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "canvas = toyplot.Canvas(width=600, height=300)\n", "table = canvas.table(\n", " data_table,\n", " columns=2,\n", " hrows=1,\n", " label=\"Example Table\")\n", "axes = table.body.column(1).merge().axes(xmin=0.0, xmax=1.1)\n", "bar = axes.bars(bars, along='y')" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": true }, "outputs": [], "source": [] } ], "metadata": { "kernelspec": { "display_name": "Python 2", "language": "python", "name": "python2" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 2 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython2", "version": "2.7.10" } }, "nbformat": 4, "nbformat_minor": 0 }