{ "cells": [ { "cell_type": "code", "execution_count": 1, "metadata": {}, "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": {}, "outputs": [ { "data": { "text/html": [ "<b> Daru::DataFrame(6x3) </b>\n", "<table>\n", " <thead>\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", "</thead>\n", " <tbody>\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", "</tbody>\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": {}, "outputs": [ { "data": { "text/plain": [ "#<Daru::View::Plot:0x00000003ec4458 @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:0x00000003ec42f0 @properties={:diagrams=>[#<Nyaplot::Diagram:0x00000003eae720 @properties={:type=>:line, :options=>{:x=>:a, :y=>:c}, :data=>\"dd735a9c-1a93-440f-ab9f-db39f5e11f96\"}, @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": {}, "outputs": [ { "data": { "text/html": [ "<div id='vis-8d7f1c0c-1031-4116-8289-bc028c6ff21e'></div>\n", "<script>\n", "(function(){\n", " var render = function(){\n", " var model = {\"panes\":[{\"diagrams\":[{\"type\":\"line\",\"options\":{\"x\":\"a\",\"y\":\"c\"},\"data\":\"dd735a9c-1a93-440f-ab9f-db39f5e11f96\"}],\"options\":{\"zoom\":true,\"width\":700,\"xrange\":[1,6],\"yrange\":[0,7]}}],\"data\":{\"dd735a9c-1a93-440f-ab9f-db39f5e11f96\":[{\"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-8d7f1c0c-1031-4116-8289-bc028c6ff21e';\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:0x00000003e6b8a8 @properties={:panes=>[#<Nyaplot::Plot:0x00000003ec42f0 @properties={:diagrams=>[#<Nyaplot::Diagram:0x00000003eae720 @properties={:type=>:line, :options=>{:x=>:a, :y=>:c}, :data=>\"dd735a9c-1a93-440f-ab9f-db39f5e11f96\"}, @xrange=[1, 6], @yrange=[0, 7]>], :options=>{:zoom=>true, :width=>700, :xrange=>[1, 6], :yrange=>[0, 7]}}>], :data=>{\"dd735a9c-1a93-440f-ab9f-db39f5e11f96\"=>#<Nyaplot::DataFrame:0x00000003eaec70 @name=\"dd735a9c-1a93-440f-ab9f-db39f5e11f96\", @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": {}, "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": {}, "outputs": [ { "data": { "text/plain": [ "#<Daru::View::Plot:0x00000003dd7d10 @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:0x00000003dd7c20 @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": {}, "outputs": [ { "data": { "text/html": [ "<div id='vis-0431bb9a-fd96-4f57-8662-d16b81d88fd4'></div>\n", "<script>\n", "(function(){\n", " var render = function(){\n", " var model = {\"panes\":[{\"diagrams\":[],\"options\":{}}],\"data\":{},\"extension\":[]}\n", " var id_name = '#vis-0431bb9a-fd96-4f57-8662-d16b81d88fd4';\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:0x00000003d41040 @properties={:panes=>[#<Nyaplot::Plot:0x00000003dd7c20 @properties={:diagrams=>[], :options=>{}}>], :data=>{}, :extension=>[]}>" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "plt2.show_in_iruby" ] }, { "cell_type": "code", "execution_count": 8, "metadata": {}, "outputs": [ { "data": { "text/html": [ "<b> Daru::Vector(3) </b>\n", "<table>\n", " <thead>\n", " \n", "</thead>\n", " <tbody>\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", "</tbody>\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": 9, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "#<Daru::View::Plot:0x00000003ca2ad0 @data=#<Daru::Vector(3)>\n", " 0 1\n", " 1 2\n", " 2 3, @options={}, @adapter=Daru::View::Adapter::NyaplotAdapter, @chart=#<Nyaplot::Plot:0x00000003ca2990 @properties={:diagrams=>[#<Nyaplot::Diagram:0x00000003ca1bd0 @properties={:type=>:scatter, :options=>{:x=>\"data0\", :y=>\"data1\"}, :data=>\"56256933-852f-4161-9749-01d058a05cd0\"}, @xrange=[0, 2], @yrange=[1, 3]>], :options=>{}}>>" ] }, "execution_count": 9, "metadata": {}, "output_type": "execute_result" } ], "source": [ "plt3 = Daru::View::Plot.new(dv)" ] }, { "cell_type": "code", "execution_count": 10, "metadata": {}, "outputs": [ { "data": { "text/html": [ "<div id='vis-285676b7-35fa-4168-880b-a6bb460238b8'></div>\n", "<script>\n", "(function(){\n", " var render = function(){\n", " var model = {\"panes\":[{\"diagrams\":[{\"type\":\"scatter\",\"options\":{\"x\":\"data0\",\"y\":\"data1\"},\"data\":\"56256933-852f-4161-9749-01d058a05cd0\"}],\"options\":{\"zoom\":true,\"width\":700,\"xrange\":[0,2],\"yrange\":[1,3]}}],\"data\":{\"56256933-852f-4161-9749-01d058a05cd0\":[{\"data0\":0,\"data1\":1},{\"data0\":1,\"data1\":2},{\"data0\":2,\"data1\":3}]},\"extension\":[]}\n", " var id_name = '#vis-285676b7-35fa-4168-880b-a6bb460238b8';\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:0x00000003c3edc8 @properties={:panes=>[#<Nyaplot::Plot:0x00000003ca2990 @properties={:diagrams=>[#<Nyaplot::Diagram:0x00000003ca1bd0 @properties={:type=>:scatter, :options=>{:x=>\"data0\", :y=>\"data1\"}, :data=>\"56256933-852f-4161-9749-01d058a05cd0\"}, @xrange=[0, 2], @yrange=[1, 3]>], :options=>{:zoom=>true, :width=>700, :xrange=>[0, 2], :yrange=>[1, 3]}}>], :data=>{\"56256933-852f-4161-9749-01d058a05cd0\"=>#<Nyaplot::DataFrame:0x00000003ca2440 @name=\"56256933-852f-4161-9749-01d058a05cd0\", @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": 11, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "#<Daru::View::Plot:0x00000003c1c7f0 @data=#<Daru::Vector(3)>\n", " 0 1\n", " 1 2\n", " 2 3, @options={:type=>:line}, @adapter=Daru::View::Adapter::NyaplotAdapter, @chart=#<Nyaplot::Plot:0x00000003c1c700 @properties={:diagrams=>[#<Nyaplot::Diagram:0x00000003c17c78 @properties={:type=>:line, :options=>{:x=>\"data0\", :y=>\"data1\"}, :data=>\"dd9c528c-6fb4-44ef-abc9-0f9cabc53149\"}, @xrange=[0, 2], @yrange=[1, 3]>], :options=>{}}>>" ] }, "execution_count": 11, "metadata": {}, "output_type": "execute_result" } ], "source": [ "plt3 = Daru::View::Plot.new(dv, type: :line)" ] }, { "cell_type": "code", "execution_count": 12, "metadata": {}, "outputs": [ { "data": { "text/html": [ "<div id='vis-76da29fa-ddd1-4289-9d49-e25b712ff538'></div>\n", "<script>\n", "(function(){\n", " var render = function(){\n", " var model = {\"panes\":[{\"diagrams\":[{\"type\":\"line\",\"options\":{\"x\":\"data0\",\"y\":\"data1\"},\"data\":\"dd9c528c-6fb4-44ef-abc9-0f9cabc53149\"}],\"options\":{\"zoom\":true,\"width\":700,\"xrange\":[0,2],\"yrange\":[1,3]}}],\"data\":{\"dd9c528c-6fb4-44ef-abc9-0f9cabc53149\":[{\"data0\":0,\"data1\":1},{\"data0\":1,\"data1\":2},{\"data0\":2,\"data1\":3}]},\"extension\":[]}\n", " var id_name = '#vis-76da29fa-ddd1-4289-9d49-e25b712ff538';\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:0x00000003beedf0 @properties={:panes=>[#<Nyaplot::Plot:0x00000003c1c700 @properties={:diagrams=>[#<Nyaplot::Diagram:0x00000003c17c78 @properties={:type=>:line, :options=>{:x=>\"data0\", :y=>\"data1\"}, :data=>\"dd9c528c-6fb4-44ef-abc9-0f9cabc53149\"}, @xrange=[0, 2], @yrange=[1, 3]>], :options=>{:zoom=>true, :width=>700, :xrange=>[0, 2], :yrange=>[1, 3]}}>], :data=>{\"dd9c528c-6fb4-44ef-abc9-0f9cabc53149\"=>#<Nyaplot::DataFrame:0x00000003c1c200 @name=\"dd9c528c-6fb4-44ef-abc9-0f9cabc53149\", @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": {}, "outputs": [], "source": [] } ], "metadata": { "kernelspec": { "display_name": "Ruby 2.4.1", "language": "ruby", "name": "ruby" }, "language_info": { "file_extension": ".rb", "mimetype": "application/x-ruby", "name": "ruby", "version": "2.4.1" } }, "nbformat": 4, "nbformat_minor": 2 }