Skip to content

Instantly share code, notes, and snippets.

@johanndt
Created February 18, 2016 06:01
Show Gist options
  • Save johanndt/b42cf7190e914b8df515 to your computer and use it in GitHub Desktop.
Save johanndt/b42cf7190e914b8df515 to your computer and use it in GitHub Desktop.

Revisions

  1. johanndt created this gist Feb 18, 2016.
    196 changes: 196 additions & 0 deletions alignment5.ipynb
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,196 @@
    {
    "cells": [
    {
    "cell_type": "code",
    "execution_count": 13,
    "metadata": {
    "collapsed": true
    },
    "outputs": [],
    "source": [
    "import toyplot"
    ]
    },
    {
    "cell_type": "code",
    "execution_count": 14,
    "metadata": {
    "collapsed": false
    },
    "outputs": [],
    "source": [
    "charts = 5\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": 15,
    "metadata": {
    "collapsed": false
    },
    "outputs": [
    {
    "data": {
    "text/html": [
    "<div align=\"center\" class=\"toyplot\" id=\"tc3269aa963e5479aa04c1bf49d483633\"><svg height=\"300.0px\" id=\"t8f98c1d34ff54a968fb1d9b1d0744aeb\" 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=\"t02de3cd010f943b18deebd44a0c8b600\"><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=\"t3bc03fe003b84468880c4a200e8bd714\"><clipPath id=\"tb6c3d3d5dc2548318069fa6a20949c20\"><rect height=\"176.66666666666671\" width=\"260.0\" x=\"295.0\" y=\"78.333333333333343\"></rect></clipPath><g class=\"toyplot-coordinate-events\" clip-path=\"url(#tb6c3d3d5dc2548318069fa6a20949c20)\" style=\"cursor:crosshair\"><rect height=\"176.66666666666671\" style=\"pointer-events:all;visibility:hidden\" width=\"260.0\" x=\"295.0\" y=\"78.333333333333343\"></rect><g class=\"toyplot-mark-BarMagnitudes\" id=\"t0f009e82d41640acb8e86bb27ce42317\" style=\"stroke:rgb(100%,100%,100%);stroke-opacity:1.0;stroke-width:1.0\"><g class=\"toyplot-Series\"><rect class=\"toyplot-Datum\" height=\"33.333333333333343\" 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=\"216.66666666666671\"></rect><rect class=\"toyplot-Datum\" height=\"33.333333333333343\" 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=\"183.33333333333337\"></rect><rect class=\"toyplot-Datum\" height=\"33.333333333333343\" 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.00000000000003\"></rect><rect class=\"toyplot-Datum\" height=\"33.333333333333357\" 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=\"116.66666666666667\"></rect><rect class=\"toyplot-Datum\" height=\"33.333333333333329\" 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=\"83.333333333333343\"></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=\"66.666666666666671\">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,66.666666666666671)\" x=\"425.0\" y=\"66.666666666666671\">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=\"100.00000000000001\">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=\"133.33333333333337\">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=\"166.66666666666669\">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=\"200.00000000000006\">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=\"233.33333333333337\">Chart 4</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=\"83.333333333333343\" y2=\"83.333333333333343\"></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(\"#tc3269aa963e5479aa04c1bf49d483633 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(\"#tc3269aa963e5479aa04c1bf49d483633 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], [0.5, 1.5, 2.5, 3.5, 4.5], [0.0, 0.0, 0.0, 0.0, 0.0], [1.0, 1.0, 1.0, 1.0, 1.0]], \"title\": \"Bar Data\", \"names\": [\"left\", \"right\", \"baseline\", \"magnitude0\"], \"id\": \"t0f009e82d41640acb8e86bb27ce42317\", \"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(\"#tc3269aa963e5479aa04c1bf49d483633 .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 0x4528ac8>"
    ]
    },
    "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
    }