Created
May 9, 2016 02:24
-
-
Save obelisk68/a8d271a84f2bf48f8bc6e9b7b21d81cf 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": 1, | |
"metadata": { | |
"collapsed": false | |
}, | |
"outputs": [ | |
{ | |
"data": { | |
"application/javascript": [ | |
"if(window['d3'] === undefined ||\n", | |
" window['Nyaplot'] === undefined){\n", | |
" var path = {\"d3\":\"https://cdnjs.cloudflare.com/ajax/libs/d3/3.5.5/d3.min\",\"downloadable\":\"http://cdn.rawgit.com/domitry/d3-downloadable/master/d3-downloadable\"};\n", | |
"\n", | |
"\n", | |
"\n", | |
" var shim = {\"d3\":{\"exports\":\"d3\"},\"downloadable\":{\"exports\":\"downloadable\"}};\n", | |
"\n", | |
" require.config({paths: path, shim:shim});\n", | |
"\n", | |
"\n", | |
"require(['d3'], function(d3){window['d3']=d3;console.log('finished loading d3');require(['downloadable'], function(downloadable){window['downloadable']=downloadable;console.log('finished loading downloadable');\n", | |
"\n", | |
"\tvar script = d3.select(\"head\")\n", | |
"\t .append(\"script\")\n", | |
"\t .attr(\"src\", \"http://cdn.rawgit.com/domitry/Nyaplotjs/master/release/nyaplot.js\")\n", | |
"\t .attr(\"async\", true);\n", | |
"\n", | |
"\tscript[0][0].onload = script[0][0].onreadystatechange = function(){\n", | |
"\n", | |
"\n", | |
"\t var event = document.createEvent(\"HTMLEvents\");\n", | |
"\t event.initEvent(\"load_nyaplot\",false,false);\n", | |
"\t window.dispatchEvent(event);\n", | |
"\t console.log('Finished loading Nyaplotjs');\n", | |
"\n", | |
"\t};\n", | |
"\n", | |
"\n", | |
"});});\n", | |
"}\n" | |
], | |
"text/plain": [ | |
"\"if(window['d3'] === undefined ||\\n window['Nyaplot'] === undefined){\\n var path = {\\\"d3\\\":\\\"https://cdnjs.cloudflare.com/ajax/libs/d3/3.5.5/d3.min\\\",\\\"downloadable\\\":\\\"http://cdn.rawgit.com/domitry/d3-downloadable/master/d3-downloadable\\\"};\\n\\n\\n\\n var shim = {\\\"d3\\\":{\\\"exports\\\":\\\"d3\\\"},\\\"downloadable\\\":{\\\"exports\\\":\\\"downloadable\\\"}};\\n\\n require.config({paths: path, shim:shim});\\n\\n\\nrequire(['d3'], function(d3){window['d3']=d3;console.log('finished loading d3');require(['downloadable'], function(downloadable){window['downloadable']=downloadable;console.log('finished loading downloadable');\\n\\n\\tvar script = d3.select(\\\"head\\\")\\n\\t .append(\\\"script\\\")\\n\\t .attr(\\\"src\\\", \\\"http://cdn.rawgit.com/domitry/Nyaplotjs/master/release/nyaplot.js\\\")\\n\\t .attr(\\\"async\\\", true);\\n\\n\\tscript[0][0].onload = script[0][0].onreadystatechange = function(){\\n\\n\\n\\t var event = document.createEvent(\\\"HTMLEvents\\\");\\n\\t event.initEvent(\\\"load_nyaplot\\\",false,false);\\n\\t window.dispatchEvent(event);\\n\\t console.log('Finished loading Nyaplotjs');\\n\\n\\t};\\n\\n\\n});});\\n}\\n\"" | |
] | |
}, | |
"metadata": {}, | |
"output_type": "display_data" | |
}, | |
{ | |
"data": { | |
"text/plain": [ | |
"true" | |
] | |
}, | |
"execution_count": 1, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
], | |
"source": [ | |
"require 'nyaplot'" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 2, | |
"metadata": { | |
"collapsed": false | |
}, | |
"outputs": [ | |
{ | |
"data": { | |
"text/plain": [ | |
"#<Nyaplot::Diagram:0x007f3fd6a5ea98 @properties={:type=>:bar, :options=>{:x=>\"data0\", :y=>\"data1\"}, :data=>\"fcdb4e42-a4ac-484a-bd78-8422e6896bd1\"}, @xrange=[\"Persian\", \"Maine Coon\", \"American Shorthair\"], @yrange=[0, 30]>" | |
] | |
}, | |
"execution_count": 2, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
], | |
"source": [ | |
"plot = Nyaplot::Plot.new\n", | |
"bar = plot.add(:bar, ['Persian', 'Maine Coon', 'American Shorthair'], [10,20,30])" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 3, | |
"metadata": { | |
"collapsed": false | |
}, | |
"outputs": [ | |
{ | |
"data": { | |
"text/html": [ | |
"<div id='vis-0970a422-d622-4f64-9eb8-2d587c2ff0f3'></div>\n", | |
"<script>\n", | |
"(function(){\n", | |
" var render = function(){\n", | |
" var model = {\"panes\":[{\"diagrams\":[{\"type\":\"bar\",\"options\":{\"x\":\"data0\",\"y\":\"data1\"},\"data\":\"fcdb4e42-a4ac-484a-bd78-8422e6896bd1\"}],\"options\":{\"width\":700,\"xrange\":[\"Persian\",\"Maine Coon\",\"American Shorthair\"],\"yrange\":[0,30]}}],\"data\":{\"fcdb4e42-a4ac-484a-bd78-8422e6896bd1\":[{\"data0\":\"Persian\",\"data1\":10},{\"data0\":\"Maine Coon\",\"data1\":20},{\"data0\":\"American Shorthair\",\"data1\":30}]},\"extension\":[]}\n", | |
" var id_name = '#vis-0970a422-d622-4f64-9eb8-2d587c2ff0f3';\n", | |
" Nyaplot.core.parse(model, id_name);\n", | |
"\n", | |
" require(['downloadable'], function(downloadable){\n", | |
" var svg = d3.select(id_name).select(\"svg\");\n", | |
"\t if(!svg.empty())\n", | |
"\t svg.call(downloadable().filename('fig'));\n", | |
"\t});\n", | |
" };\n", | |
" if(window['Nyaplot']==undefined){\n", | |
" window.addEventListener('load_nyaplot', render, false);\n", | |
"\treturn;\n", | |
" } else {\n", | |
" render();\n", | |
" }\n", | |
"})();\n", | |
"</script>\n" | |
], | |
"text/plain": [ | |
"#<Nyaplot::Frame:0x007f3fd6a3fcb0 @properties={:panes=>[#<Nyaplot::Plot:0x007f3fd6a60190 @properties={:diagrams=>[#<Nyaplot::Diagram:0x007f3fd6a5ea98 @properties={:type=>:bar, :options=>{:x=>\"data0\", :y=>\"data1\"}, :data=>\"fcdb4e42-a4ac-484a-bd78-8422e6896bd1\"}, @xrange=[\"Persian\", \"Maine Coon\", \"American Shorthair\"], @yrange=[0, 30]>], :options=>{:width=>700, :xrange=>[\"Persian\", \"Maine Coon\", \"American Shorthair\"], :yrange=>[0, 30]}}>], :data=>{\"fcdb4e42-a4ac-484a-bd78-8422e6896bd1\"=>#<Nyaplot::DataFrame:0x007f3fd6a5f560 @name=\"fcdb4e42-a4ac-484a-bd78-8422e6896bd1\", @rows=[{:data0=>\"Persian\", :data1=>10}, {:data0=>\"Maine Coon\", :data1=>20}, {:data0=>\"American Shorthair\", :data1=>30}]>}, :extension=>[]}>" | |
] | |
}, | |
"metadata": {}, | |
"output_type": "display_data" | |
} | |
], | |
"source": [ | |
"plot.show" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 4, | |
"metadata": { | |
"collapsed": false | |
}, | |
"outputs": [ | |
{ | |
"data": { | |
"text/html": [ | |
"<div id='vis-a890449f-bcd4-4656-abe5-32d7895e0f8b'></div>\n", | |
"<script>\n", | |
"(function(){\n", | |
" var render = function(){\n", | |
" var model = {\"panes\":[{\"diagrams\":[{\"type\":\"bar\",\"options\":{\"x\":\"data0\",\"y\":\"data1\"},\"data\":\"fcdb4e42-a4ac-484a-bd78-8422e6896bd1\"}],\"options\":{\"width\":700,\"xrange\":[\"Persian\",\"Maine Coon\",\"American Shorthair\"],\"yrange\":[0,30],\"x_label\":\"Species\",\"y_label\":\"Number\"}}],\"data\":{\"fcdb4e42-a4ac-484a-bd78-8422e6896bd1\":[{\"data0\":\"Persian\",\"data1\":10},{\"data0\":\"Maine Coon\",\"data1\":20},{\"data0\":\"American Shorthair\",\"data1\":30}]},\"extension\":[]}\n", | |
" var id_name = '#vis-a890449f-bcd4-4656-abe5-32d7895e0f8b';\n", | |
" Nyaplot.core.parse(model, id_name);\n", | |
"\n", | |
" require(['downloadable'], function(downloadable){\n", | |
" var svg = d3.select(id_name).select(\"svg\");\n", | |
"\t if(!svg.empty())\n", | |
"\t svg.call(downloadable().filename('fig'));\n", | |
"\t});\n", | |
" };\n", | |
" if(window['Nyaplot']==undefined){\n", | |
" window.addEventListener('load_nyaplot', render, false);\n", | |
"\treturn;\n", | |
" } else {\n", | |
" render();\n", | |
" }\n", | |
"})();\n", | |
"</script>\n" | |
], | |
"text/plain": [ | |
"#<Nyaplot::Frame:0x007f3fd6940e40 @properties={:panes=>[#<Nyaplot::Plot:0x007f3fd6a60190 @properties={:diagrams=>[#<Nyaplot::Diagram:0x007f3fd6a5ea98 @properties={:type=>:bar, :options=>{:x=>\"data0\", :y=>\"data1\"}, :data=>\"fcdb4e42-a4ac-484a-bd78-8422e6896bd1\"}, @xrange=[\"Persian\", \"Maine Coon\", \"American Shorthair\"], @yrange=[0, 30]>], :options=>{:width=>700, :xrange=>[\"Persian\", \"Maine Coon\", \"American Shorthair\"], :yrange=>[0, 30], :x_label=>\"Species\", :y_label=>\"Number\"}}>], :data=>{\"fcdb4e42-a4ac-484a-bd78-8422e6896bd1\"=>#<Nyaplot::DataFrame:0x007f3fd6a5f560 @name=\"fcdb4e42-a4ac-484a-bd78-8422e6896bd1\", @rows=[{:data0=>\"Persian\", :data1=>10}, {:data0=>\"Maine Coon\", :data1=>20}, {:data0=>\"American Shorthair\", :data1=>30}]>}, :extension=>[]}>" | |
] | |
}, | |
"metadata": {}, | |
"output_type": "display_data" | |
} | |
], | |
"source": [ | |
"plot.x_label(\"Species\")\n", | |
"plot.y_label(\"Number\")\n", | |
"plot.show" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 5, | |
"metadata": { | |
"collapsed": false | |
}, | |
"outputs": [ | |
{ | |
"data": { | |
"text/html": [ | |
"<table><tr><th>rgb(228,26,28)</th><th>rgb(55,126,184)</th><th>rgb(77,175,74)</th><th>rgb(152,78,163)</th><th>rgb(255,127,0)</th><th>rgb(255,255,51)</th><th>rgb(166,86,40)</th><th>rgb(247,129,191)</th><th>rgb(153,153,153)</th></tr><tr><td style=\"background-color:rgb(228,26,28);\"> </td><td style=\"background-color:rgb(55,126,184);\"> </td><td style=\"background-color:rgb(77,175,74);\"> </td><td style=\"background-color:rgb(152,78,163);\"> </td><td style=\"background-color:rgb(255,127,0);\"> </td><td style=\"background-color:rgb(255,255,51);\"> </td><td style=\"background-color:rgb(166,86,40);\"> </td><td style=\"background-color:rgb(247,129,191);\"> </td><td style=\"background-color:rgb(153,153,153);\"> </td></tr></table>" | |
], | |
"text/plain": [ | |
"#<Nyaplot::Color:0x007f3fd691e750 @source=[\"rgb(228,26,28)\", \"rgb(55,126,184)\", \"rgb(77,175,74)\", \"rgb(152,78,163)\", \"rgb(255,127,0)\", \"rgb(255,255,51)\", \"rgb(166,86,40)\", \"rgb(247,129,191)\", \"rgb(153,153,153)\"]>" | |
] | |
}, | |
"execution_count": 5, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
], | |
"source": [ | |
"colors = Nyaplot::Colors.qual" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 6, | |
"metadata": { | |
"collapsed": false | |
}, | |
"outputs": [ | |
{ | |
"data": { | |
"text/html": [ | |
"<div id='vis-380cf28a-b2e4-4609-b5ec-47f7508f92b5'></div>\n", | |
"<script>\n", | |
"(function(){\n", | |
" var render = function(){\n", | |
" var model = {\"panes\":[{\"diagrams\":[{\"type\":\"bar\",\"options\":{\"x\":\"data0\",\"y\":\"data1\",\"color\":[\"rgb(228,26,28)\",\"rgb(55,126,184)\",\"rgb(77,175,74)\",\"rgb(152,78,163)\",\"rgb(255,127,0)\",\"rgb(255,255,51)\",\"rgb(166,86,40)\",\"rgb(247,129,191)\",\"rgb(153,153,153)\"]},\"data\":\"fcdb4e42-a4ac-484a-bd78-8422e6896bd1\"}],\"options\":{\"width\":700,\"xrange\":[\"Persian\",\"Maine Coon\",\"American Shorthair\"],\"yrange\":[0,30],\"x_label\":\"Species\",\"y_label\":\"Number\"}}],\"data\":{\"fcdb4e42-a4ac-484a-bd78-8422e6896bd1\":[{\"data0\":\"Persian\",\"data1\":10},{\"data0\":\"Maine Coon\",\"data1\":20},{\"data0\":\"American Shorthair\",\"data1\":30}]},\"extension\":[]}\n", | |
" var id_name = '#vis-380cf28a-b2e4-4609-b5ec-47f7508f92b5';\n", | |
" Nyaplot.core.parse(model, id_name);\n", | |
"\n", | |
" require(['downloadable'], function(downloadable){\n", | |
" var svg = d3.select(id_name).select(\"svg\");\n", | |
"\t if(!svg.empty())\n", | |
"\t svg.call(downloadable().filename('fig'));\n", | |
"\t});\n", | |
" };\n", | |
" if(window['Nyaplot']==undefined){\n", | |
" window.addEventListener('load_nyaplot', render, false);\n", | |
"\treturn;\n", | |
" } else {\n", | |
" render();\n", | |
" }\n", | |
"})();\n", | |
"</script>\n" | |
], | |
"text/plain": [ | |
"#<Nyaplot::Frame:0x007f3fd6901b78 @properties={:panes=>[#<Nyaplot::Plot:0x007f3fd6a60190 @properties={:diagrams=>[#<Nyaplot::Diagram:0x007f3fd6a5ea98 @properties={:type=>:bar, :options=>{:x=>\"data0\", :y=>\"data1\", :color=>#<Nyaplot::Color:0x007f3fd691e750 @source=[\"rgb(228,26,28)\", \"rgb(55,126,184)\", \"rgb(77,175,74)\", \"rgb(152,78,163)\", \"rgb(255,127,0)\", \"rgb(255,255,51)\", \"rgb(166,86,40)\", \"rgb(247,129,191)\", \"rgb(153,153,153)\"]>}, :data=>\"fcdb4e42-a4ac-484a-bd78-8422e6896bd1\"}, @xrange=[\"Persian\", \"Maine Coon\", \"American Shorthair\"], @yrange=[0, 30]>], :options=>{:width=>700, :xrange=>[\"Persian\", \"Maine Coon\", \"American Shorthair\"], :yrange=>[0, 30], :x_label=>\"Species\", :y_label=>\"Number\"}}>], :data=>{\"fcdb4e42-a4ac-484a-bd78-8422e6896bd1\"=>#<Nyaplot::DataFrame:0x007f3fd6a5f560 @name=\"fcdb4e42-a4ac-484a-bd78-8422e6896bd1\", @rows=[{:data0=>\"Persian\", :data1=>10}, {:data0=>\"Maine Coon\", :data1=>20}, {:data0=>\"American Shorthair\", :data1=>30}]>}, :extension=>[]}>" | |
] | |
}, | |
"metadata": {}, | |
"output_type": "display_data" | |
} | |
], | |
"source": [ | |
"bar.color(colors)\n", | |
"plot.show" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 7, | |
"metadata": { | |
"collapsed": false | |
}, | |
"outputs": [ | |
{ | |
"data": { | |
"text/html": [ | |
"<table><tr><th>species</th><th>number</th></tr><tr><td>Persian</td><td>10</td></tr><tr><td>Maine Coon</td><td>20</td></tr><tr><td>American Shorthair</td><td>30</td></tr></table>" | |
], | |
"text/plain": [ | |
"#<Nyaplot::DataFrame:0x007f3fd68dd3e0 @name=\"fdbf86fe-b7dc-44ad-a336-35eefac964de\", @rows=[{:species=>\"Persian\", :number=>10}, {:species=>\"Maine Coon\", :number=>20}, {:species=>\"American Shorthair\", :number=>30}]>" | |
] | |
}, | |
"execution_count": 7, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
], | |
"source": [ | |
"df = Nyaplot::DataFrame.new({species: ['Persian', 'Maine Coon', 'American Shorthair'], number: [10,20,30]})" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": null, | |
"metadata": { | |
"collapsed": true | |
}, | |
"outputs": [], | |
"source": [] | |
} | |
], | |
"metadata": { | |
"kernelspec": { | |
"display_name": "Ruby 2.2.3", | |
"language": "ruby", | |
"name": "ruby" | |
}, | |
"language_info": { | |
"file_extension": ".rb", | |
"mimetype": "application/x-ruby", | |
"name": "ruby", | |
"version": "2.2.3" | |
} | |
}, | |
"nbformat": 4, | |
"nbformat_minor": 0 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment