Created
          February 18, 2016 06:01 
        
      - 
      
- 
        Save johanndt/97a74ac2f51ce932fd3d 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": 10, | |
| "metadata": { | |
| "collapsed": true | |
| }, | |
| "outputs": [], | |
| "source": [ | |
| "import toyplot" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": 11, | |
| "metadata": { | |
| "collapsed": false | |
| }, | |
| "outputs": [], | |
| "source": [ | |
| "charts = 7\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": 12, | |
| "metadata": { | |
| "collapsed": false | |
| }, | |
| "outputs": [ | |
| { | |
| "data": { | |
| "text/html": [ | |
| "<div align=\"center\" class=\"toyplot\" id=\"t6ba5bcc3809f4d73ad570e754a82f095\"><svg height=\"300.0px\" id=\"t35480dcf808c4838ab411ee40074230e\" 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=\"t0aa533272dbf4846943c0a2107f0ed87\"><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=\"t9fea3556bda3487ab73743307be2d5ba\"><clipPath id=\"teac3b0526b1047599b61b59020ebfa6c\"><rect height=\"185.0\" width=\"260.0\" x=\"295.0\" y=\"70.0\"></rect></clipPath><g class=\"toyplot-coordinate-events\" clip-path=\"url(#teac3b0526b1047599b61b59020ebfa6c)\" style=\"cursor:crosshair\"><rect height=\"185.0\" style=\"pointer-events:all;visibility:hidden\" width=\"260.0\" x=\"295.0\" y=\"70.0\"></rect><g class=\"toyplot-mark-BarMagnitudes\" id=\"t75118d0e2ac64c3da4cf25653c08adbd\" style=\"stroke:rgb(100%,100%,100%);stroke-opacity:1.0;stroke-width:1.0\"><g class=\"toyplot-Series\"><rect class=\"toyplot-Datum\" height=\"24.999999999999972\" 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=\"225.00000000000003\"></rect><rect class=\"toyplot-Datum\" height=\"25.000000000000028\" 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=\"200.0\"></rect><rect class=\"toyplot-Datum\" height=\"25.0\" 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=\"175.0\"></rect><rect class=\"toyplot-Datum\" height=\"25.0\" 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=\"150.0\"></rect><rect class=\"toyplot-Datum\" height=\"25.0\" 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=\"125.0\"></rect><rect class=\"toyplot-Datum\" height=\"25.0\" 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=\"100.0\"></rect><rect class=\"toyplot-Datum\" height=\"25.0\" 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=\"75.0\"></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=\"62.5\">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,62.5)\" x=\"425.0\" y=\"62.5\">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=\"87.5\">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=\"112.5\">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=\"137.5\">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=\"162.5\">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=\"187.5\">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=\"212.5\">Chart 5</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=\"237.5\">Chart 6</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=\"75.0\" y2=\"75.0\"></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(\"#t6ba5bcc3809f4d73ad570e754a82f095 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(\"#t6ba5bcc3809f4d73ad570e754a82f095 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, 5.5], [0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5], [0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0], [1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0]], \"title\": \"Bar Data\", \"names\": [\"left\", \"right\", \"baseline\", \"magnitude0\"], \"id\": \"t75118d0e2ac64c3da4cf25653c08adbd\", \"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(\"#t6ba5bcc3809f4d73ad570e754a82f095 .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 0x455ccf8>" | |
| ] | |
| }, | |
| "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 | |
| } | 
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment