Created
November 4, 2015 21:42
-
-
Save johanndt/cd961901c1977763fb70 to your computer and use it in GitHub Desktop.
Toyplot - Moved y axis to the right
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": 53, | |
| "metadata": { | |
| "collapsed": false | |
| }, | |
| "outputs": [], | |
| "source": [ | |
| "import numpy\n", | |
| "import toyplot" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": 54, | |
| "metadata": { | |
| "collapsed": true | |
| }, | |
| "outputs": [], | |
| "source": [ | |
| "x1 = numpy.linspace(0, 10, 10)\n", | |
| "y1 = x ** 2\n", | |
| "y2 = x * 2" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": 67, | |
| "metadata": { | |
| "collapsed": false | |
| }, | |
| "outputs": [ | |
| { | |
| "data": { | |
| "text/plain": [ | |
| "<toyplot.mark.Plot at 0x44965c0>" | |
| ] | |
| }, | |
| "execution_count": 67, | |
| "metadata": {}, | |
| "output_type": "execute_result" | |
| }, | |
| { | |
| "data": { | |
| "text/html": [ | |
| "<div align=\"center\" class=\"toyplot\" id=\"t14c42adb8e0e4148b87df432316a5a42\"><svg height=\"600px\" id=\"t01ad3c51d1984ad192042be6e56a95ad\" 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 600\" width=\"600px\" xmlns=\"http://www.w3.org/2000/svg\" xmlns:toyplot=\"http://www.sandia.gov/toyplot\"><g class=\"toyplot-axes-Cartesian\" id=\"t2dc13c08e2c24d329c39fc84dff684cc\"><clipPath id=\"t387a937553bf47e9b6880df4dece56fc\"><rect height=\"500.0\" width=\"500.0\" x=\"50.0\" y=\"50.0\"></rect></clipPath><g class=\"toyplot-coordinate-events\" clip-path=\"url(#t387a937553bf47e9b6880df4dece56fc)\" style=\"cursor:crosshair\"><rect height=\"500.0\" style=\"pointer-events:all;visibility:hidden\" width=\"500.0\" x=\"50.0\" y=\"50.0\"></rect><g class=\"toyplot-mark-BarMagnitudes\" id=\"t0e9833270d924df09e5d21b4b34879c4\" style=\"stroke:rgb(100%,100%,100%);stroke-opacity:1.0;stroke-width:1.0\"><g class=\"toyplot-Series\"><rect class=\"toyplot-Datum\" height=\"0.0\" style=\"fill:rgb(27.5%,51%,70.6%);fill-opacity:1.0;opacity:1.0;stroke:rgb(100%,100%,100%);stroke-opacity:1.0;stroke-width:1.0\" width=\"48.0\" x=\"60.0\" y=\"540.0\"></rect><rect class=\"toyplot-Datum\" height=\"53.333333333333314\" style=\"fill:rgb(27.5%,51%,70.6%);fill-opacity:1.0;opacity:1.0;stroke:rgb(100%,100%,100%);stroke-opacity:1.0;stroke-width:1.0\" width=\"48.0\" x=\"108.0\" y=\"486.66666666666669\"></rect><rect class=\"toyplot-Datum\" height=\"106.66666666666669\" style=\"fill:rgb(27.5%,51%,70.6%);fill-opacity:1.0;opacity:1.0;stroke:rgb(100%,100%,100%);stroke-opacity:1.0;stroke-width:1.0\" width=\"48.0\" x=\"156.0\" y=\"433.33333333333331\"></rect><rect class=\"toyplot-Datum\" height=\"160.0\" style=\"fill:rgb(27.5%,51%,70.6%);fill-opacity:1.0;opacity:1.0;stroke:rgb(100%,100%,100%);stroke-opacity:1.0;stroke-width:1.0\" width=\"48.0\" x=\"204.0\" y=\"380.0\"></rect><rect class=\"toyplot-Datum\" height=\"213.33333333333331\" style=\"fill:rgb(27.5%,51%,70.6%);fill-opacity:1.0;opacity:1.0;stroke:rgb(100%,100%,100%);stroke-opacity:1.0;stroke-width:1.0\" width=\"48.0\" x=\"252.0\" y=\"326.66666666666669\"></rect><rect class=\"toyplot-Datum\" height=\"266.66666666666669\" style=\"fill:rgb(27.5%,51%,70.6%);fill-opacity:1.0;opacity:1.0;stroke:rgb(100%,100%,100%);stroke-opacity:1.0;stroke-width:1.0\" width=\"48.0\" x=\"300.0\" y=\"273.33333333333331\"></rect><rect class=\"toyplot-Datum\" height=\"320.0\" style=\"fill:rgb(27.5%,51%,70.6%);fill-opacity:1.0;opacity:1.0;stroke:rgb(100%,100%,100%);stroke-opacity:1.0;stroke-width:1.0\" width=\"48.000000000000057\" x=\"348.0\" y=\"219.99999999999997\"></rect><rect class=\"toyplot-Datum\" height=\"373.33333333333337\" style=\"fill:rgb(27.5%,51%,70.6%);fill-opacity:1.0;opacity:1.0;stroke:rgb(100%,100%,100%);stroke-opacity:1.0;stroke-width:1.0\" width=\"47.999999999999943\" x=\"396.00000000000006\" y=\"166.6666666666666\"></rect><rect class=\"toyplot-Datum\" height=\"426.66666666666669\" style=\"fill:rgb(27.5%,51%,70.6%);fill-opacity:1.0;opacity:1.0;stroke:rgb(100%,100%,100%);stroke-opacity:1.0;stroke-width:1.0\" width=\"48.0\" x=\"444.0\" y=\"113.3333333333333\"></rect><rect class=\"toyplot-Datum\" height=\"480.0\" style=\"fill:rgb(27.5%,51%,70.6%);fill-opacity:1.0;opacity:1.0;stroke:rgb(100%,100%,100%);stroke-opacity:1.0;stroke-width:1.0\" width=\"48.0\" x=\"492.0\" y=\"60.0\"></rect></g></g></g><g class=\"toyplot-coordinates\" style=\"visibility:hidden\"><rect height=\"14.0\" style=\"fill:rgb(100%,100%,100%);fill-opacity:1.0;opacity:0.75;stroke:none\" width=\"90.0\" x=\"450.0\" y=\"60.0\"></rect><text style=\"alignment-baseline:middle;font-size:10px;font-weight:normal;stroke:none;text-anchor:middle\" x=\"495.0\" y=\"67.0\"></text></g><line style=\"\" x1=\"60.0\" x2=\"540.0\" y1=\"550.0\" y2=\"550.0\"></line><g><text style=\"alignment-baseline:middle;baseline-shift:-80%;font-size:10px;font-weight:normal;stroke:none;text-anchor:middle\" x=\"84.0\" y=\"550.0\">0</text><text style=\"alignment-baseline:middle;baseline-shift:-80%;font-size:10px;font-weight:normal;stroke:none;text-anchor:middle\" x=\"300.0\" y=\"550.0\">5</text><text style=\"alignment-baseline:middle;baseline-shift:-80%;font-size:10px;font-weight:normal;stroke:none;text-anchor:middle\" x=\"516.0\" y=\"550.0\">10</text></g><line style=\"\" x1=\"50.0\" x2=\"50.0\" y1=\"60.0\" y2=\"540.0\"></line><g><text style=\"alignment-baseline:middle;baseline-shift:80%;font-size:10px;font-weight:normal;stroke:none;text-anchor:middle\" transform=\"rotate(-90, 50.0, 540.0)\" x=\"50.0\" y=\"540.0\">0</text><text style=\"alignment-baseline:middle;baseline-shift:80%;font-size:10px;font-weight:normal;stroke:none;text-anchor:middle\" transform=\"rotate(-90, 50.0, 420.0)\" x=\"50.0\" y=\"420.0\">5</text><text style=\"alignment-baseline:middle;baseline-shift:80%;font-size:10px;font-weight:normal;stroke:none;text-anchor:middle\" transform=\"rotate(-90, 50.0, 300.0)\" x=\"50.0\" y=\"300.0\">10</text><text style=\"alignment-baseline:middle;baseline-shift:80%;font-size:10px;font-weight:normal;stroke:none;text-anchor:middle\" transform=\"rotate(-90, 50.0, 180.0)\" x=\"50.0\" y=\"180.0\">15</text><text style=\"alignment-baseline:middle;baseline-shift:80%;font-size:10px;font-weight:normal;stroke:none;text-anchor:middle\" transform=\"rotate(-90, 50.0, 60.0)\" x=\"50.0\" y=\"60.0\">20</text></g><text style=\"alignment-baseline:middle;baseline-shift:200%;font-weight:bold;stroke:none;text-anchor:middle\" transform=\"rotate(-90, 50.0, 300.0)\" x=\"50.0\" y=\"300.0\">Axis 2</text></g><g class=\"toyplot-axes-Cartesian\" id=\"ta0d09ee97dca45f79bbd3b1f76ba01de\"><clipPath id=\"t4c3a0f7cd18e4a6eb907a9e736430d39\"><rect height=\"500.0\" width=\"500.0\" x=\"50.0\" y=\"50.0\"></rect></clipPath><g class=\"toyplot-coordinate-events\" clip-path=\"url(#t4c3a0f7cd18e4a6eb907a9e736430d39)\" style=\"cursor:crosshair\"><rect height=\"500.0\" style=\"pointer-events:all;visibility:hidden\" width=\"500.0\" x=\"50.0\" y=\"50.0\"></rect><g class=\"toyplot-mark-Plot\" id=\"t2d838bfe4ea6479db411d064934c6883\" style=\"fill:none\"><g class=\"toyplot-Series\"><path d=\"M 60.0 540.0 L 113.33333333333334 534.07407407407402 L 166.66666666666669 516.2962962962963 L 220.00000000000003 486.66666666666669 L 273.33333333333337 445.18518518518516 L 326.66666666666669 391.85185185185185 L 380.00000000000006 326.66666666666669 L 433.33333333333337 249.62962962962956 L 486.66666666666674 160.7407407407407 L 540.0 60.0\" style=\"fill:none;stroke:rgb(54.5%,0%,0%);stroke-opacity:1.0;stroke-width:2.0\"></path></g></g></g><g class=\"toyplot-coordinates\" style=\"visibility:hidden\"><rect height=\"14.0\" style=\"fill:rgb(100%,100%,100%);fill-opacity:1.0;opacity:0.75;stroke:none\" width=\"90.0\" x=\"450.0\" y=\"60.0\"></rect><text style=\"alignment-baseline:middle;font-size:10px;font-weight:normal;stroke:none;text-anchor:middle\" x=\"495.0\" y=\"67.0\"></text></g><line style=\"\" x1=\"60.0\" x2=\"540.0\" y1=\"550.0\" y2=\"550.0\"></line><g><text style=\"alignment-baseline:middle;baseline-shift:-80%;font-size:10px;font-weight:normal;stroke:none;text-anchor:middle\" x=\"60.0\" y=\"550.0\">0</text><text style=\"alignment-baseline:middle;baseline-shift:-80%;font-size:10px;font-weight:normal;stroke:none;text-anchor:middle\" x=\"300.0\" y=\"550.0\">5</text><text style=\"alignment-baseline:middle;baseline-shift:-80%;font-size:10px;font-weight:normal;stroke:none;text-anchor:middle\" x=\"540.0\" y=\"550.0\">10</text></g><line style=\"\" x1=\"550.0\" x2=\"550.0\" y1=\"60.0\" y2=\"540.0\"></line><g><text style=\"alignment-baseline:middle;baseline-shift:80%;font-size:10px;font-weight:normal;stroke:none;text-anchor:middle\" transform=\"rotate(-90, 570.0, 540.0)\" x=\"570.0\" y=\"540.0\">0</text><text style=\"alignment-baseline:middle;baseline-shift:80%;font-size:10px;font-weight:normal;stroke:none;text-anchor:middle\" transform=\"rotate(-90, 570.0, 300.0)\" x=\"570.0\" y=\"300.0\">50</text><text style=\"alignment-baseline:middle;baseline-shift:80%;font-size:10px;font-weight:normal;stroke:none;text-anchor:middle\" transform=\"rotate(-90, 570.0, 60.0)\" x=\"570.0\" y=\"60.0\">100</text></g><text style=\"alignment-baseline:middle;baseline-shift:-530.0;font-weight:bold;stroke:none;text-anchor:middle\" transform=\"rotate(-90, 50.0, 300.0)\" x=\"50.0\" y=\"300.0\">Axis 1</text></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(\"#t14c42adb8e0e4148b87df432316a5a42 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(\"#t14c42adb8e0e4148b87df432316a5a42 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.5555555555555556, 0.5555555555555556, 1.6666666666666667, 2.7777777777777777, 3.8888888888888893, 5.0, 6.111111111111111, 7.222222222222223, 8.333333333333334, 9.444444444444445], [0.5555555555555556, 1.6666666666666667, 2.7777777777777777, 3.8888888888888893, 5.0, 6.111111111111111, 7.222222222222223, 8.333333333333334, 9.444444444444445, 10.555555555555555], [0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0], [0.0, 2.2222222222222223, 4.444444444444445, 6.666666666666667, 8.88888888888889, 11.11111111111111, 13.333333333333334, 15.555555555555557, 17.77777777777778, 20.0]], \"title\": \"Bar Data\", \"names\": [\"left\", \"right\", \"baseline\", \"magnitude0\"], \"id\": \"t0e9833270d924df09e5d21b4b34879c4\", \"filename\": \"toyplot\"}, {\"data\": [[0.0, 1.1111111111111112, 2.2222222222222223, 3.3333333333333335, 4.444444444444445, 5.555555555555555, 6.666666666666667, 7.777777777777779, 8.88888888888889, 10.0], [0.0, 1.234567901234568, 4.938271604938272, 11.111111111111112, 19.75308641975309, 30.864197530864196, 44.44444444444445, 60.49382716049384, 79.01234567901236, 100.0]], \"title\": \"Plot Data\", \"names\": [\"x\", \"y0\"], \"id\": \"t2d838bfe4ea6479db411d064934c6883\", \"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(\"#t14c42adb8e0e4148b87df432316a5a42 .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><script>\n", | |
| "(function()\n", | |
| "{\n", | |
| " var axes = {\"t2dc13c08e2c24d329c39fc84dff684cc\": {\"x\": [{\"domain\": {\"bounds\": {\"max\": Infinity, \"min\": -Infinity}, \"max\": 10.555555555555555, \"min\": -0.55555555555555558}, \"range\": {\"bounds\": {\"max\": Infinity, \"min\": -Infinity}, \"max\": 540.0, \"min\": 60.0}, \"scale\": \"linear\"}], \"y\": [{\"domain\": {\"bounds\": {\"max\": Infinity, \"min\": -Infinity}, \"max\": 20.0, \"min\": 0.0}, \"range\": {\"bounds\": {\"max\": -Infinity, \"min\": Infinity}, \"max\": 60.0, \"min\": 540.0}, \"scale\": \"linear\"}]}, \"ta0d09ee97dca45f79bbd3b1f76ba01de\": {\"x\": [{\"domain\": {\"bounds\": {\"max\": Infinity, \"min\": -Infinity}, \"max\": 10.0, \"min\": 0.0}, \"range\": {\"bounds\": {\"max\": Infinity, \"min\": -Infinity}, \"max\": 540.0, \"min\": 60.0}, \"scale\": \"linear\"}], \"y\": [{\"domain\": {\"bounds\": {\"max\": Infinity, \"min\": -Infinity}, \"max\": 100.0, \"min\": 0.0}, \"range\": {\"bounds\": {\"max\": -Infinity, \"min\": Infinity}, \"max\": 60.0, \"min\": 540.0}, \"scale\": \"linear\"}]}};\n", | |
| "\n", | |
| " function sign(x)\n", | |
| " {\n", | |
| " return x < 0 ? -1 : x > 0 ? 1 : 0;\n", | |
| " }\n", | |
| "\n", | |
| " function _mix(a, b, amount)\n", | |
| " {\n", | |
| " return ((1.0 - amount) * a) + (amount * b);\n", | |
| " }\n", | |
| "\n", | |
| " function _log(x, base)\n", | |
| " {\n", | |
| " return Math.log(Math.abs(x)) / Math.log(base);\n", | |
| " }\n", | |
| "\n", | |
| " function _in_range(a, x, b)\n", | |
| " {\n", | |
| " var left = Math.min(a, b);\n", | |
| " var right = Math.max(a, b);\n", | |
| " return left <= x && x <= right;\n", | |
| " }\n", | |
| "\n", | |
| " function to_domain(projection, range)\n", | |
| " {\n", | |
| " for(var i = 0; i != projection.length; ++i)\n", | |
| " {\n", | |
| " var segment = projection[i];\n", | |
| " if(_in_range(segment.range.bounds.min, range, segment.range.bounds.max))\n", | |
| " {\n", | |
| " if(segment.scale == \"linear\")\n", | |
| " {\n", | |
| " var amount = (range - segment.range.min) / (segment.range.max - segment.range.min);\n", | |
| " return _mix(segment.domain.min, segment.domain.max, amount)\n", | |
| " }\n", | |
| " else if(segment.scale[0] == \"log\")\n", | |
| " {\n", | |
| " var amount = (range - segment.range.min) / (segment.range.max - segment.range.min);\n", | |
| " var base = segment.scale[1];\n", | |
| " return sign(segment.domain.min) * Math.pow(base, _mix(_log(segment.domain.min, base), _log(segment.domain.max, base), amount));\n", | |
| " }\n", | |
| " }\n", | |
| " }\n", | |
| " }\n", | |
| "\n", | |
| " // Compute mouse coordinates relative to a DOM object, with thanks to d3js.org, where this code originated.\n", | |
| " function d3_mousePoint(container, e)\n", | |
| " {\n", | |
| " if (e.changedTouches) e = e.changedTouches[0];\n", | |
| " var svg = container.ownerSVGElement || container;\n", | |
| " if (svg.createSVGPoint) {\n", | |
| " var point = svg.createSVGPoint();\n", | |
| " point.x = e.clientX, point.y = e.clientY;\n", | |
| " point = point.matrixTransform(container.getScreenCTM().inverse());\n", | |
| " return [point.x, point.y];\n", | |
| " }\n", | |
| " var rect = container.getBoundingClientRect();\n", | |
| " return [e.clientX - rect.left - container.clientLeft, e.clientY - rect.top - container.clientTop];\n", | |
| " };\n", | |
| "\n", | |
| " function display_coordinates(e)\n", | |
| " {\n", | |
| " var dom_axes = e.currentTarget.parentElement;\n", | |
| " var data = axes[dom_axes.id];\n", | |
| "\n", | |
| " point = d3_mousePoint(e.target, e);\n", | |
| " var x = Number(to_domain(data[\"x\"], point[0])).toFixed(2);\n", | |
| " var y = Number(to_domain(data[\"y\"], point[1])).toFixed(2);\n", | |
| "\n", | |
| " var coordinates = dom_axes.querySelectorAll(\".toyplot-coordinates\");\n", | |
| " for(var i = 0; i != coordinates.length; ++i)\n", | |
| " {\n", | |
| " coordinates[i].style.visibility = \"visible\";\n", | |
| " coordinates[i].querySelector(\"text\").textContent = \"x=\" + x + \" y=\" + y;\n", | |
| " }\n", | |
| " }\n", | |
| "\n", | |
| " function clear_coordinates(e)\n", | |
| " {\n", | |
| " var dom_axes = e.currentTarget.parentElement;\n", | |
| " var coordinates = dom_axes.querySelectorAll(\".toyplot-coordinates\");\n", | |
| " for(var i = 0; i != coordinates.length; ++i)\n", | |
| " coordinates[i].style.visibility = \"hidden\";\n", | |
| " }\n", | |
| "\n", | |
| " for(var axes_id in axes)\n", | |
| " {\n", | |
| " var event_target = document.querySelector(\"#\" + axes_id + \" .toyplot-coordinate-events\");\n", | |
| " event_target.onmousemove = display_coordinates;\n", | |
| " event_target.onmouseout = clear_coordinates;\n", | |
| " }\n", | |
| "})();\n", | |
| "</script></div></div>" | |
| ], | |
| "text/plain": [ | |
| "<toyplot.canvas.Canvas at 0x4533c50>" | |
| ] | |
| }, | |
| "metadata": {}, | |
| "output_type": "display_data" | |
| } | |
| ], | |
| "source": [ | |
| "canvas = toyplot.Canvas()\n", | |
| "axes = canvas.axes(ylabel=\"Axis 2\")\n", | |
| "axes.bars(x, y2, color=\"steelblue\")\n", | |
| "axes = canvas.axes(ylabel=\"Axis 1\")\n", | |
| "axes.y.spine.position = \"high\"\n", | |
| "offset = -(axes._xmax_range - axes._xmin_range + (2*axes.padding))\n", | |
| "axes.y.ticks.labels.offset = offset\n", | |
| "axes.y.label.style = {\"baseline-shift\": offset - axes.padding}\n", | |
| "axes.plot(x, y1, color=\"darkred\")" | |
| ] | |
| }, | |
| { | |
| "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