{ "cells": [ { "cell_type": "code", "execution_count": 1, "metadata": { "collapsed": false }, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "\n", "Install the spreadsheet gem version ~>1.1.1 for using spreadsheet functions.\n", "\n", "Install the mechanize gem version ~>2.7.5 for using mechanize functions.\n" ] }, { "data": { "text/plain": [ "true" ] }, "execution_count": 1, "metadata": {}, "output_type": "execute_result" } ], "source": [ "require 'daru/view'" ] }, { "cell_type": "code", "execution_count": 2, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/html": [ "<table>\n", " <tr>\n", " <th colspan='4'>Daru::DataFrame(6x3)</th>\n", " </tr>\n", "\n", " \n", " <tr>\n", " <th></th>\n", " \n", " <th>a</th>\n", " \n", " <th>b</th>\n", " \n", " <th>c</th>\n", " \n", " </tr>\n", " \n", "\n", " \n", " <tr>\n", " <td>a</td>\n", " \n", " <td>1</td>\n", " \n", " <td>1</td>\n", " \n", " <td>1</td>\n", " \n", " </tr>\n", " \n", " <tr>\n", " <td>b</td>\n", " \n", " <td>2</td>\n", " \n", " <td>5</td>\n", " \n", " <td>6</td>\n", " \n", " </tr>\n", " \n", " <tr>\n", " <td>c</td>\n", " \n", " <td>3</td>\n", " \n", " <td>2</td>\n", " \n", " <td>7</td>\n", " \n", " </tr>\n", " \n", " <tr>\n", " <td>d</td>\n", " \n", " <td>4</td>\n", " \n", " <td>5</td>\n", " \n", " <td>2</td>\n", " \n", " </tr>\n", " \n", " <tr>\n", " <td>e</td>\n", " \n", " <td>5</td>\n", " \n", " <td>1</td>\n", " \n", " <td>6</td>\n", " \n", " </tr>\n", " \n", " <tr>\n", " <td>f</td>\n", " \n", " <td>6</td>\n", " \n", " <td>0</td>\n", " \n", " <td>0</td>\n", " \n", " </tr>\n", " \n", "\n", " \n", "</table>" ], "text/plain": [ "#<Daru::DataFrame(6x3)>\n", " a b c\n", " a 1 1 1\n", " b 2 5 6\n", " c 3 2 7\n", " d 4 5 2\n", " e 5 1 6\n", " f 6 0 0" ] }, "execution_count": 2, "metadata": {}, "output_type": "execute_result" } ], "source": [ "df = Daru::DataFrame.new(\n", " {\n", " a: [1, 2, 3, 4, 5, 6],\n", " b: [1, 5, 2, 5, 1, 0],\n", " c: [1, 6, 7, 2, 6, 0]\n", " }, index: 'a'..'f'\n", " )" ] }, { "cell_type": "code", "execution_count": 3, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/plain": [ "#<Daru::View::Plot:0x007f8af499c998 @data=#<Daru::DataFrame(6x3)>\n", " a b c\n", " a 1 1 1\n", " b 2 5 6\n", " c 3 2 7\n", " d 4 5 2\n", " e 5 1 6\n", " f 6 0 0, @options={:type=>:line, :x=>:a, :y=>:c}, @adapter=Daru::View::Adapter::NyaplotAdapter, @chart=#<Nyaplot::Plot:0x007f8af499c650 @properties={:diagrams=>[#<Nyaplot::Diagram:0x007f8af4987750 @properties={:type=>:line, :options=>{:x=>:a, :y=>:c}, :data=>\"a3543f81-f8a5-4b47-ad01-4b67fca08ad2\"}, @xrange=[1, 6], @yrange=[0, 7]>], :options=>{}}>>" ] }, "execution_count": 3, "metadata": {}, "output_type": "execute_result" } ], "source": [ "plt = Daru::View::Plot.new(df, type: :line, x: :a, y: :c) " ] }, { "cell_type": "code", "execution_count": 4, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/html": [ "<div id='vis-867b55af-9220-41c4-904c-be20e719ff37'></div>\n", "<script>\n", "(function(){\n", " var render = function(){\n", " var model = {\"panes\":[{\"diagrams\":[{\"type\":\"line\",\"options\":{\"x\":\"a\",\"y\":\"c\"},\"data\":\"a3543f81-f8a5-4b47-ad01-4b67fca08ad2\"}],\"options\":{\"zoom\":true,\"width\":700,\"xrange\":[1,6],\"yrange\":[0,7]}}],\"data\":{\"a3543f81-f8a5-4b47-ad01-4b67fca08ad2\":[{\"a\":1,\"b\":1,\"c\":1},{\"a\":2,\"b\":5,\"c\":6},{\"a\":3,\"b\":2,\"c\":7},{\"a\":4,\"b\":5,\"c\":2},{\"a\":5,\"b\":1,\"c\":6},{\"a\":6,\"b\":0,\"c\":0}]},\"extension\":[]}\n", " var id_name = '#vis-867b55af-9220-41c4-904c-be20e719ff37';\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:0x007f8af3960098 @properties={:panes=>[#<Nyaplot::Plot:0x007f8af499c650 @properties={:diagrams=>[#<Nyaplot::Diagram:0x007f8af4987750 @properties={:type=>:line, :options=>{:x=>:a, :y=>:c}, :data=>\"a3543f81-f8a5-4b47-ad01-4b67fca08ad2\"}, @xrange=[1, 6], @yrange=[0, 7]>], :options=>{:zoom=>true, :width=>700, :xrange=>[1, 6], :yrange=>[0, 7]}}>], :data=>{\"a3543f81-f8a5-4b47-ad01-4b67fca08ad2\"=>#<Nyaplot::DataFrame:0x007f8af498c250 @name=\"a3543f81-f8a5-4b47-ad01-4b67fca08ad2\", @rows=[{:a=>1, :b=>1, :c=>1}, {:a=>2, :b=>5, :c=>6}, {:a=>3, :b=>2, :c=>7}, {:a=>4, :b=>5, :c=>2}, {:a=>5, :b=>1, :c=>6}, {:a=>6, :b=>0, :c=>0}]>}, :extension=>[]}>" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "plt.show_in_iruby" ] }, { "cell_type": "code", "execution_count": 5, "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": [ ":nyaplot" ] }, "execution_count": 5, "metadata": {}, "output_type": "execute_result" } ], "source": [ "Daru::View.plotting_library = :nyaplot" ] }, { "cell_type": "code", "execution_count": 6, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/plain": [ "#<Daru::View::Plot:0x007f8af48c66e0 @data=#<Daru::DataFrame(6x3)>\n", " a b c\n", " a 1 1 1\n", " b 2 5 6\n", " c 3 2 7\n", " d 4 5 2\n", " e 5 1 6\n", " f 6 0 0, @options={}, @adapter=Daru::View::Adapter::NyaplotAdapter, @chart=#<Nyaplot::Plot:0x007f8af48c65f0 @properties={:diagrams=>[], :options=>{}}>>" ] }, "execution_count": 6, "metadata": {}, "output_type": "execute_result" } ], "source": [ "plt2 = Daru::View::Plot.new(df) " ] }, { "cell_type": "code", "execution_count": 7, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/html": [ "<div id='vis-9736816b-3bb9-4828-9fa6-a020d9708931'></div>\n", "<script>\n", "(function(){\n", " var render = function(){\n", " var model = {\"panes\":[{\"diagrams\":[],\"options\":{}}],\"data\":{},\"extension\":[]}\n", " var id_name = '#vis-9736816b-3bb9-4828-9fa6-a020d9708931';\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:0x007f8af40b8110 @properties={:panes=>[#<Nyaplot::Plot:0x007f8af48c65f0 @properties={:diagrams=>[], :options=>{}}>], :data=>{}, :extension=>[]}>" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "plt2.show_in_iruby" ] }, { "cell_type": "code", "execution_count": 8, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/html": [ "<table>\n", " <tr>\n", " <th colspan=\"2\">Daru::Vector(3)</th>\n", " </tr>\n", " \n", "\n", " \n", " <tr>\n", " <td>0</td>\n", " <td>1</td>\n", " </tr>\n", " \n", " <tr>\n", " <td>1</td>\n", " <td>2</td>\n", " </tr>\n", " \n", " <tr>\n", " <td>2</td>\n", " <td>3</td>\n", " </tr>\n", " \n", "\n", " \n", "</table>" ], "text/plain": [ "#<Daru::Vector(3)>\n", " 0 1\n", " 1 2\n", " 2 3" ] }, "execution_count": 8, "metadata": {}, "output_type": "execute_result" } ], "source": [ "dv = Daru::Vector.new [1, 2, 3] " ] }, { "cell_type": "code", "execution_count": 10, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/plain": [ "#<Daru::View::Plot:0x007f8af42ac980 @data=#<Daru::Vector(3)>\n", " 0 1\n", " 1 2\n", " 2 3, @options={}, @adapter=Daru::View::Adapter::NyaplotAdapter, @chart=#<Nyaplot::Plot:0x007f8af42ac778 @properties={:diagrams=>[#<Nyaplot::Diagram:0x007f8af42a61e8 @properties={:type=>:scatter, :options=>{:x=>\"data0\", :y=>\"data1\"}, :data=>\"c7cc03ef-6209-4ed4-97ec-23826905f930\"}, @xrange=[0, 2], @yrange=[1, 3]>], :options=>{}}>>" ] }, "execution_count": 10, "metadata": {}, "output_type": "execute_result" } ], "source": [ "plt3 = Daru::View::Plot.new(dv)" ] }, { "cell_type": "code", "execution_count": 11, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/html": [ "<div id='vis-6b319c22-ad91-408b-9667-b9acae518e42'></div>\n", "<script>\n", "(function(){\n", " var render = function(){\n", " var model = {\"panes\":[{\"diagrams\":[{\"type\":\"scatter\",\"options\":{\"x\":\"data0\",\"y\":\"data1\"},\"data\":\"c7cc03ef-6209-4ed4-97ec-23826905f930\"}],\"options\":{\"zoom\":true,\"width\":700,\"xrange\":[0,2],\"yrange\":[1,3]}}],\"data\":{\"c7cc03ef-6209-4ed4-97ec-23826905f930\":[{\"data0\":0,\"data1\":1},{\"data0\":1,\"data1\":2},{\"data0\":2,\"data1\":3}]},\"extension\":[]}\n", " var id_name = '#vis-6b319c22-ad91-408b-9667-b9acae518e42';\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:0x007f8af3be0700 @properties={:panes=>[#<Nyaplot::Plot:0x007f8af42ac778 @properties={:diagrams=>[#<Nyaplot::Diagram:0x007f8af42a61e8 @properties={:type=>:scatter, :options=>{:x=>\"data0\", :y=>\"data1\"}, :data=>\"c7cc03ef-6209-4ed4-97ec-23826905f930\"}, @xrange=[0, 2], @yrange=[1, 3]>], :options=>{:zoom=>true, :width=>700, :xrange=>[0, 2], :yrange=>[1, 3]}}>], :data=>{\"c7cc03ef-6209-4ed4-97ec-23826905f930\"=>#<Nyaplot::DataFrame:0x007f8af42a77f0 @name=\"c7cc03ef-6209-4ed4-97ec-23826905f930\", @rows=[{:data0=>0, :data1=>1}, {:data0=>1, :data1=>2}, {:data0=>2, :data1=>3}]>}, :extension=>[]}>" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "plt3.show_in_iruby" ] }, { "cell_type": "code", "execution_count": 15, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/plain": [ "#<Daru::View::Plot:0x007f8af52d25a8 @data=#<Daru::Vector(3)>\n", " 0 1\n", " 1 2\n", " 2 3, @options={:type=>:line}, @adapter=Daru::View::Adapter::NyaplotAdapter, @chart=#<Nyaplot::Plot:0x007f8af52d2418 @properties={:diagrams=>[#<Nyaplot::Diagram:0x007f8af52d1158 @properties={:type=>:line, :options=>{:x=>\"data0\", :y=>\"data1\"}, :data=>\"8a647dc7-e7c4-4f30-b573-aeedeacefc2d\"}, @xrange=[0, 2], @yrange=[1, 3]>], :options=>{}}>>" ] }, "execution_count": 15, "metadata": {}, "output_type": "execute_result" } ], "source": [ "plt3 = Daru::View::Plot.new(dv, type: :line)" ] }, { "cell_type": "code", "execution_count": 16, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/html": [ "<div id='vis-136cae6c-f747-4520-86f4-b795e7fa0269'></div>\n", "<script>\n", "(function(){\n", " var render = function(){\n", " var model = {\"panes\":[{\"diagrams\":[{\"type\":\"line\",\"options\":{\"x\":\"data0\",\"y\":\"data1\"},\"data\":\"8a647dc7-e7c4-4f30-b573-aeedeacefc2d\"}],\"options\":{\"zoom\":true,\"width\":700,\"xrange\":[0,2],\"yrange\":[1,3]}}],\"data\":{\"8a647dc7-e7c4-4f30-b573-aeedeacefc2d\":[{\"data0\":0,\"data1\":1},{\"data0\":1,\"data1\":2},{\"data0\":2,\"data1\":3}]},\"extension\":[]}\n", " var id_name = '#vis-136cae6c-f747-4520-86f4-b795e7fa0269';\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:0x007f8af52b33b0 @properties={:panes=>[#<Nyaplot::Plot:0x007f8af52d2418 @properties={:diagrams=>[#<Nyaplot::Diagram:0x007f8af52d1158 @properties={:type=>:line, :options=>{:x=>\"data0\", :y=>\"data1\"}, :data=>\"8a647dc7-e7c4-4f30-b573-aeedeacefc2d\"}, @xrange=[0, 2], @yrange=[1, 3]>], :options=>{:zoom=>true, :width=>700, :xrange=>[0, 2], :yrange=>[1, 3]}}>], :data=>{\"8a647dc7-e7c4-4f30-b573-aeedeacefc2d\"=>#<Nyaplot::DataFrame:0x007f8af52d1ae0 @name=\"8a647dc7-e7c4-4f30-b573-aeedeacefc2d\", @rows=[{:data0=>0, :data1=>1}, {:data0=>1, :data1=>2}, {:data0=>2, :data1=>3}]>}, :extension=>[]}>" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "plt3.show_in_iruby" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": true }, "outputs": [], "source": [] } ], "metadata": { "kernelspec": { "display_name": "Ruby 2.3.1", "language": "ruby", "name": "ruby" }, "language_info": { "file_extension": ".rb", "mimetype": "application/x-ruby", "name": "ruby", "version": "2.3.1" } }, "nbformat": 4, "nbformat_minor": 2 }