{ "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": { "application/javascript": [ "\n", " /* BEGIN google_visualr.js */\n", "\n", "if(!window['googleLT_']){window['googleLT_']=(new Date()).getTime();}if (!window['google']) {\n", "window['google'] = {};\n", "}\n", "if (!window['google']['loader']) {\n", "window['google']['loader'] = {};\n", "google.loader.ServiceBase = 'https://www.google.com/uds';\n", "google.loader.GoogleApisBase = 'https://ajax.googleapis.com/ajax';\n", "google.loader.ApiKey = 'notsupplied';\n", "google.loader.KeyVerified = true;\n", "google.loader.LoadFailure = false;\n", "google.loader.Secure = true;\n", "google.loader.GoogleLocale = 'www.google.com';\n", "google.loader.ClientLocation = null;\n", "google.loader.AdditionalParams = '';\n", "(function() {function g(a){return a in l?l[a]:l[a]=-1!=navigator.userAgent.toLowerCase().indexOf(a)}var l={};function m(a,b){var c=function(){};c.prototype=b.prototype;a.ca=b.prototype;a.prototype=new c}function n(a,b,c){var d=Array.prototype.slice.call(arguments,2)||[];return function(){return a.apply(b,d.concat(Array.prototype.slice.call(arguments)))}}function p(a){a=Error(a);a.toString=function(){return this.message};return a}\n", "function q(a,b){a=a.split(/\\./);for(var c=window,d=0;d\\x3c/script>\"):(g(\"safari\")||g(\"konqueror\"))&&window.setTimeout(B,10)),x.push(a)):y(window,\"load\",a)};t(\"google.setOnLoadCallback\",google.ba);\n", "function y(a,b,c){if(a.addEventListener)a.addEventListener(b,c,!1);else if(a.attachEvent)a.attachEvent(\"on\"+b,c);else{var d=a[\"on\"+b];a[\"on\"+b]=null!=d?C([c,d]):c}}function C(a){return function(){for(var b=0;b\\x3c/script>'):\"css\"==a&&document.write('')};\n", "t(\"google.loader.writeLoadTag\",google.loader.f);google.loader.Z=function(a){w=a};t(\"google.loader.rfm\",google.loader.Z);google.loader.aa=function(a){for(var b in a)\"string\"==typeof b&&b&&\":\"==b.charAt(0)&&!v[b]&&(v[b]=new E(b.substring(1),a[b]))};t(\"google.loader.rpl\",google.loader.aa);google.loader.$=function(a){if((a=a.specs)&&a.length)for(var b=0;b\\x3c/script>')},K.Mi=function(b){var c=K.global.document,d=c.createElement(\"script\");d.type=C;d.src=b;d.defer=!1;d.async=!1;c.head.appendChild(d)},\n", "K.Wl=function(b,c){if(K.tg()){var d=K.global.document;if(!K.Ge&&d.readyState==t){if(/\\bdeps.js$/.test(b))return!1;throw Error('Cannot write \"'+b+'\" after document load');}void 0===c?K.fi?(K.eh=!0,c=\" onreadystatechange='goog.onScriptLoad_(this, \"+ ++K.Sg+\")' \",d.write(n+b+'\"'+c+\">\\x3c/script>\")):K.Ge?K.Mi(b):K.Vl(b):d.write('\n" ], "text/plain": [ "\"
\\n\\n\"" ] }, "execution_count": 4, "metadata": {}, "output_type": "execute_result" } ], "source": [ "histo_table = Daru::View::Table.new(df_dino_length, height: 300, width: 200)\n", "histo_table.show_in_iruby" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "**Note: Histogram chart doesn't work in google_visualr**" ] }, { "cell_type": "code", "execution_count": 6, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/html": [ "
\n", "\n" ], "text/plain": [ "\"
\\n\\n\"" ] }, "execution_count": 6, "metadata": {}, "output_type": "execute_result" } ], "source": [ "histo_options = {\n", " title: 'Lengths of dinosaurs, in meters',\n", " legend: { position: 'none' },\n", " type: :histogram,\n", " height: 400\n", "}\n", "histo_chart = Daru::View::Plot.new(histo_table, histo_options)\n", "histo_chart.show_in_iruby" ] }, { "cell_type": "code", "execution_count": 8, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/html": [ "
\n", "\n" ], "text/plain": [ "\"
\\n\\n\"" ] }, "execution_count": 8, "metadata": {}, "output_type": "execute_result" } ], "source": [ "histo_options = {\n", " title: 'Lengths of dinosaurs, in meters',\n", " colors: ['#e7711c'],\n", " histogram: { lastBucketPercentile: 5 },\n", " vAxis: { scaleType: 'mirrorLog' },\n", " type: :histogram,\n", " height: 400\n", "}\n", "histo_chart = Daru::View::Plot.new(histo_table, histo_options)\n", "histo_chart.show_in_iruby" ] }, { "cell_type": "code", "execution_count": 9, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/html": [ "
\n", "\n" ], "text/plain": [ "\"
\\n\\n\"" ] }, "execution_count": 9, "metadata": {}, "output_type": "execute_result" } ], "source": [ "histo_options = {\n", " title: 'Lengths of dinosaurs, in meters',\n", " colors: ['#e7711c'],\n", " histogram: { bucketSize: 10000000 },\n", " type: :histogram,\n", " height: 400\n", "}\n", "histo_chart = Daru::View::Plot.new(histo_table, histo_options)\n", "histo_chart.show_in_iruby" ] }, { "cell_type": "code", "execution_count": 21, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/plain": [ "[0.9, 1.2, 1.5, 1.8, 2.0, 2.7, 3.4, 4.6, 5.5, 6.1, 7.9, 9.1, 12.2, 15.2, 21.0, 22.9, 27.1, 30.5, 36.6, 45.7]" ] }, "execution_count": 21, "metadata": {}, "output_type": "execute_result" } ], "source": [ "tick = Array df_dino_length['Length'].sort.uniq" ] }, { "cell_type": "code", "execution_count": 22, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/html": [ "
\n", "\n" ], "text/plain": [ "\"
\\n\\n\"" ] }, "execution_count": 22, "metadata": {}, "output_type": "execute_result" } ], "source": [ "histo_options = {\n", " title: 'Lengths of dinosaurs, in meters',\n", " colors: ['#4285F4'],\n", "\n", " chartArea: { width: 401 },\n", " hAxis: {\n", " ticks: tick\n", " },\n", " bar: { gap: 0 },\n", "\n", " histogram: {\n", " bucketSize: 0.02,\n", " maxNumBuckets: 200,\n", " minValue: -1,\n", " maxValue: 1\n", " },\n", " type: :histogram,\n", " height: 400\n", "}\n", "histo_chart = Daru::View::Plot.new(histo_table, histo_options)\n", "histo_chart.show_in_iruby" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "#### Multiple Series" ] }, { "cell_type": "code", "execution_count": 27, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/html": [ " Daru::DataFrame(7x4) \n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "\n", " \n", "\n", "
QuarksLeptonsGauge BosonsScalar Bosons
00.6666666666666666-100
10.6666666666666666-10
20.6666666666666666-10
3-0.333333333333333301
4-0.33333333333333330-1
5-0.33333333333333330
6-0.33333333333333330
" ], "text/plain": [ "#\n", " Quarks Leptons Gauge Boso Scalar Bos\n", " 0 0.66666666 -1 0 0\n", " 1 0.66666666 -1 0 nil\n", " 2 0.66666666 -1 0 nil\n", " 3 -0.3333333 0 1 nil\n", " 4 -0.3333333 0 -1 nil\n", " 5 -0.3333333 0 nil nil\n", " 6 -0.3333333 0 nil nil" ] }, "execution_count": 27, "metadata": {}, "output_type": "execute_result" } ], "source": [ "idx = Daru::Index.new ['Quarks', 'Leptons', 'Gauge Bosons', 'Scalar Bosons']\n", "data_rows = [\n", " [2.0/3, -1, 0, 0],\n", " [2/3.0, -1, 0, nil],\n", " [2/3.0, -1, 0, nil],\n", " [-1.0/3, 0, 1, nil],\n", " [-1/3.0, 0, -1, nil],\n", " [-1.0/3, 0, nil, nil],\n", " [-1.0/3, 0, nil, nil]\n", " ]\n", "df_subatomic = Daru::DataFrame.rows(data_rows)\n", "df_subatomic.vectors = idx\n", "df_subatomic" ] }, { "cell_type": "code", "execution_count": 28, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/html": [ "
\n", "\n" ], "text/plain": [ "\"
\\n\\n\"" ] }, "execution_count": 28, "metadata": {}, "output_type": "execute_result" } ], "source": [ "histo_multiple_options = {\n", " title: 'Charges of subatomic particles',\n", " legend: { position: 'top', maxLines: 2 },\n", " colors: ['#5C3292', '#1A8763', '#871B47', '#999999'],\n", " interpolateNulls: false,\n", " type: :histogram,\n", " height: 400\n", "}\n", "histo_multiple_chart = Daru::View::Plot.new(df_subatomic, histo_multiple_options)\n", "histo_multiple_chart.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 }