y4ashida/rbplotly

View on GitHub
examples/Box Plots.ipynb

Summary

Maintainability
Test Coverage
{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "\n",
       "  <script>\n",
       "  requirejs.config({paths: { 'plotly': ['https://cdn.plot.ly/plotly-latest.min'] }})\n",
       "  </script>\n",
       "\n",
       "\n",
       "<div id=\"7d6323ad-491d-42c9-bbdb-8aa3764a5d41\" style=\"height: 100%; width: 100%;\"></div>\n",
       "\n",
       "<script>\n",
       " require(['plotly'], function(Plotly) { \n",
       "Plotly.newPlot(\n",
       "  '7d6323ad-491d-42c9-bbdb-8aa3764a5d41',\n",
       "  [{\"y\":[-0.818778464572787,-0.28535348942750705,-0.5243724179604262,-0.9692243397740018,-0.5203572832904212,-0.5490325187248112,-0.9344961332190633,-0.08640876919554541,-0.31423962270212946,-0.7321161664287822,-0.05956054510696107,-0.6336988688680469,-0.038964886680868616,-0.038127105229104674,-0.26087617855235334,-0.39078567379558893,-0.707565103354636,-0.3285166008571415,-0.8388805425338606,-0.41725789130449065,-0.5837232814760575,-0.924828477847427,-0.9908320890160224,-0.3967410547804715,-0.3961175610070107,-0.46225895075446544,-0.9499326458262588,-0.8652449349088409,-0.2091148737819235,-0.9893414039938501,-0.6001874782695088,-0.8780882345225167,-0.2708801195536389,-0.31209585166881415,-0.40566545370220053,-0.5756645639856102,-0.3762055223000168,-0.9340022551235174,-0.5722871875277331,-0.9567320690957005,-0.15515867527005,-0.5596311742118937,-0.814979542317942,-0.4794655336063228,-0.9407539236188923,-0.19885221253999297,-0.24842403416394954,-0.19957489719937072,-0.30714071350721683,-0.10702030811067842],\"type\":\"box\"},{\"y\":[0.9584268599923178,0.08904236109117303,0.1014512040883142,0.6105230091395797,0.16329774002936526,0.2265709459862466,0.8681321128582443,0.8061619207197374,0.09008585407745606,0.2967692908047632,0.5386431449788928,0.8481088079807734,0.32532310953673216,0.6031350396143287,0.34908863321845296,0.34179157548806804,0.6580909521014432,0.9930884472859675,0.7813692890043071,0.9029453263556432,0.9722702191958671,0.8886425699036719,0.05903307134075708,0.9187893224644376,0.4135910719799538,0.07640636298695691,0.1170396377130678,0.4785813455509742,0.7047636318854636,0.5404610656790951,0.6011237744993523,0.987142126894797,0.5824990524517196,0.023341436634658486,0.9991338327256978,0.6967081488614129,0.35246713592252954,0.3320566086731954,0.8609324541667795,0.737110413620862,0.7737865361896256,0.20240794469547774,0.4384923478967351,0.19234243897191183,0.7150737164744262,0.7982845876652145,0.7868763241100386,0.27575083672063194,0.26977270115295726,0.22858752027492812],\"type\":\"box\"}],\n",
       "  {},\n",
       "  {\"linkText\":\"Export to plot.ly\",\"showLink\":true}\n",
       ")\n",
       "\n",
       "window.addEventListener('resize', function() {\n",
       "  Plotly.Plots.resize(document.getElementById('7d6323ad-491d-42c9-bbdb-8aa3764a5d41'))\n",
       "})\n",
       " }) \n",
       "</script>"
      ],
      "text/plain": [
       "#<Plotly::Offline::HTML:0x00005577e1f31b38 @id=\"7d6323ad-491d-42c9-bbdb-8aa3764a5d41\", @data=[{:y=>[-0.818778464572787, -0.28535348942750705, -0.5243724179604262, -0.9692243397740018, -0.5203572832904212, -0.5490325187248112, -0.9344961332190633, -0.08640876919554541, -0.31423962270212946, -0.7321161664287822, -0.05956054510696107, -0.6336988688680469, -0.038964886680868616, -0.038127105229104674, -0.26087617855235334, -0.39078567379558893, -0.707565103354636, -0.3285166008571415, -0.8388805425338606, -0.41725789130449065, -0.5837232814760575, -0.924828477847427, -0.9908320890160224, -0.3967410547804715, -0.3961175610070107, -0.46225895075446544, -0.9499326458262588, -0.8652449349088409, -0.2091148737819235, -0.9893414039938501, -0.6001874782695088, -0.8780882345225167, -0.2708801195536389, -0.31209585166881415, -0.40566545370220053, -0.5756645639856102, -0.3762055223000168, -0.9340022551235174, -0.5722871875277331, -0.9567320690957005, -0.15515867527005, -0.5596311742118937, -0.814979542317942, -0.4794655336063228, -0.9407539236188923, -0.19885221253999297, -0.24842403416394954, -0.19957489719937072, -0.30714071350721683, -0.10702030811067842], :type=>:box}, {:y=>[0.9584268599923178, 0.08904236109117303, 0.1014512040883142, 0.6105230091395797, 0.16329774002936526, 0.2265709459862466, 0.8681321128582443, 0.8061619207197374, 0.09008585407745606, 0.2967692908047632, 0.5386431449788928, 0.8481088079807734, 0.32532310953673216, 0.6031350396143287, 0.34908863321845296, 0.34179157548806804, 0.6580909521014432, 0.9930884472859675, 0.7813692890043071, 0.9029453263556432, 0.9722702191958671, 0.8886425699036719, 0.05903307134075708, 0.9187893224644376, 0.4135910719799538, 0.07640636298695691, 0.1170396377130678, 0.4785813455509742, 0.7047636318854636, 0.5404610656790951, 0.6011237744993523, 0.987142126894797, 0.5824990524517196, 0.023341436634658486, 0.9991338327256978, 0.6967081488614129, 0.35246713592252954, 0.3320566086731954, 0.8609324541667795, 0.737110413620862, 0.7737865361896256, 0.20240794469547774, 0.4384923478967351, 0.19234243897191183, 0.7150737164744262, 0.7982845876652145, 0.7868763241100386, 0.27575083672063194, 0.26977270115295726, 0.22858752027492812], :type=>:box}], @layout={}, @config={:linkText=>\"Export to plot.ly\", :showLink=>true}, @embedded=true>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/plain": [
       "#<CZTop::Socket::PUB:0x5577e1be72a0 last_endpoint=\"tcp://127.0.0.1:60209\">"
      ]
     },
     "execution_count": 1,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# Basic Box Plot\n",
    "require 'rbplotly'\n",
    "\n",
    "n = 50\n",
    "y0 = n.times.map { rand(-1.0..0.0) }\n",
    "y1 = n.times.map { rand(0.0..1.0) }\n",
    "\n",
    "trace0 = {\n",
    "  y: y0,\n",
    "  type: :box\n",
    "}\n",
    "\n",
    "trace1 = {\n",
    "  y: y1,\n",
    "  type: :box\n",
    "}\n",
    "\n",
    "data = [trace0, trace1]\n",
    "\n",
    "plot = Plotly::Plot.new(data: data)\n",
    "plot.show"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "\n",
       "  <script>\n",
       "  requirejs.config({paths: { 'plotly': ['https://cdn.plot.ly/plotly-latest.min'] }})\n",
       "  </script>\n",
       "\n",
       "\n",
       "<div id=\"79505dc0-b5f6-4b05-89f3-399761a94c7e\" style=\"height: 100%; width: 100%;\"></div>\n",
       "\n",
       "<script>\n",
       " require(['plotly'], function(Plotly) { \n",
       "Plotly.newPlot(\n",
       "  '79505dc0-b5f6-4b05-89f3-399761a94c7e',\n",
       "  [{\"type\":\"box\",\"x\":[-0.7208981685892687,-0.36637448307818987,-0.07195142764789242,-0.8947440288828019,-0.19080934706756958,-0.09097425254082359,-0.9687312815041146,-0.4137327245763237,-0.6831073157678831,-0.25016224258170183,-0.834318461838564,-0.004198818252545422,-0.18305621943139339,-0.8308699358646298,-0.38609038190220235,-0.40671759388249296,-0.2624461844158511,-0.11010368480022648,-0.869215024428811,-0.8347996657611646,-0.4348802950090185,-0.3817689615877813,-0.04821457281291608,-0.027660300609340438,-0.1272813639820054,-0.1686908837463188,-0.02522071739202203,-0.2162802970013047,-0.7484047101669224,-0.6519352674024296,-0.9338837847612163,-0.5195189086369425,-0.17656225261528458,-0.39280152725314144,-0.5374489138410379,-0.6629845103231281,-0.5465974938914689,-0.7761244981731541,-0.005972460424478965,-0.37450462526307615,-0.07057691730388016,-0.9468337959057181,-0.3960032099094357,-0.6705013776551891,-0.1283233478608382,-0.7165489198156656,-0.8149518074551625,-0.4577603530503095,-0.6818368227776116,-0.5020182860576637]},{\"type\":\"box\",\"x\":[0.2596415102895009,0.0449485223836783,0.6687942428664903,0.40141308712361623,0.7147158474648745,0.21547499656471414,0.2955560373170386,0.8760461126426486,0.8208998299895568,0.9218966083333362,0.9047438500672093,0.8379823426545258,0.9651428594278217,0.9847433111569038,0.6051426451597384,0.9588237970261188,0.08680950576227586,0.4020993694913989,0.48912825850288877,0.32570390807550076,0.447465169374085,0.4495066828504488,0.5455382569701841,0.10761556169593711,0.40992042588029665,0.8702729810191612,0.7213314075448368,0.6276100688466614,0.3162056255268424,0.03583276642988997,0.5620828917919326,0.17007570607725975,0.036205437424550735,0.6911080554540988,0.46825288805600984,0.7425079479632225,0.3866579709314413,0.47480591371422887,0.5818504294911337,0.06168767121963681,0.4933454800124978,0.8868434198211811,0.7541547228076296,0.5036884275009763,0.4786836330071037,0.062146596221696604,0.46761633878354636,0.5426697790732398,0.35255192091554766,0.42013153046960927]}],\n",
       "  {},\n",
       "  {\"linkText\":\"Export to plot.ly\",\"showLink\":true}\n",
       ")\n",
       "\n",
       "window.addEventListener('resize', function() {\n",
       "  Plotly.Plots.resize(document.getElementById('79505dc0-b5f6-4b05-89f3-399761a94c7e'))\n",
       "})\n",
       " }) \n",
       "</script>"
      ],
      "text/plain": [
       "#<Plotly::Offline::HTML:0x00005577e1df6e08 @id=\"79505dc0-b5f6-4b05-89f3-399761a94c7e\", @data=[{:type=>:box, :x=>[-0.7208981685892687, -0.36637448307818987, -0.07195142764789242, -0.8947440288828019, -0.19080934706756958, -0.09097425254082359, -0.9687312815041146, -0.4137327245763237, -0.6831073157678831, -0.25016224258170183, -0.834318461838564, -0.004198818252545422, -0.18305621943139339, -0.8308699358646298, -0.38609038190220235, -0.40671759388249296, -0.2624461844158511, -0.11010368480022648, -0.869215024428811, -0.8347996657611646, -0.4348802950090185, -0.3817689615877813, -0.04821457281291608, -0.027660300609340438, -0.1272813639820054, -0.1686908837463188, -0.02522071739202203, -0.2162802970013047, -0.7484047101669224, -0.6519352674024296, -0.9338837847612163, -0.5195189086369425, -0.17656225261528458, -0.39280152725314144, -0.5374489138410379, -0.6629845103231281, -0.5465974938914689, -0.7761244981731541, -0.005972460424478965, -0.37450462526307615, -0.07057691730388016, -0.9468337959057181, -0.3960032099094357, -0.6705013776551891, -0.1283233478608382, -0.7165489198156656, -0.8149518074551625, -0.4577603530503095, -0.6818368227776116, -0.5020182860576637]}, {:type=>:box, :x=>[0.2596415102895009, 0.0449485223836783, 0.6687942428664903, 0.40141308712361623, 0.7147158474648745, 0.21547499656471414, 0.2955560373170386, 0.8760461126426486, 0.8208998299895568, 0.9218966083333362, 0.9047438500672093, 0.8379823426545258, 0.9651428594278217, 0.9847433111569038, 0.6051426451597384, 0.9588237970261188, 0.08680950576227586, 0.4020993694913989, 0.48912825850288877, 0.32570390807550076, 0.447465169374085, 0.4495066828504488, 0.5455382569701841, 0.10761556169593711, 0.40992042588029665, 0.8702729810191612, 0.7213314075448368, 0.6276100688466614, 0.3162056255268424, 0.03583276642988997, 0.5620828917919326, 0.17007570607725975, 0.036205437424550735, 0.6911080554540988, 0.46825288805600984, 0.7425079479632225, 0.3866579709314413, 0.47480591371422887, 0.5818504294911337, 0.06168767121963681, 0.4933454800124978, 0.8868434198211811, 0.7541547228076296, 0.5036884275009763, 0.4786836330071037, 0.062146596221696604, 0.46761633878354636, 0.5426697790732398, 0.35255192091554766, 0.42013153046960927]}], @layout={}, @config={:linkText=>\"Export to plot.ly\", :showLink=>true}, @embedded=true>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/plain": [
       "#<CZTop::Socket::PUB:0x5577e1be72a0 last_endpoint=\"tcp://127.0.0.1:60209\">"
      ]
     },
     "execution_count": 2,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# Basic Horizontal Box Plot\n",
    "n = 50\n",
    "x0 = n.times.map { rand(-1.0..0.0) }\n",
    "x1 = n.times.map { rand(0.0..1.0) }\n",
    "\n",
    "trace0 = {\n",
    "  x: x0,\n",
    "  type: :box\n",
    "}\n",
    "\n",
    "trace1 = {\n",
    "  x: x1,\n",
    "  type: :box\n",
    "}\n",
    "\n",
    "data = [trace0, trace1]\n",
    "\n",
    "plot = Plotly::Plot.new(data: data)\n",
    "plot.show"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "\n",
       "  <script>\n",
       "  requirejs.config({paths: { 'plotly': ['https://cdn.plot.ly/plotly-latest.min'] }})\n",
       "  </script>\n",
       "\n",
       "\n",
       "<div id=\"686f254a-068d-4203-814c-075343be458c\" style=\"height: 100%; width: 100%;\"></div>\n",
       "\n",
       "<script>\n",
       " require(['plotly'], function(Plotly) { \n",
       "Plotly.newPlot(\n",
       "  '686f254a-068d-4203-814c-075343be458c',\n",
       "  [{\"y\":[0,1,1,2,3,5,8,13,21],\"type\":\"box\",\"boxpoints\":\"all\",\"jitter\":0.3,\"pointpos\":-1.8}],\n",
       "  {},\n",
       "  {\"linkText\":\"Export to plot.ly\",\"showLink\":true}\n",
       ")\n",
       "\n",
       "window.addEventListener('resize', function() {\n",
       "  Plotly.Plots.resize(document.getElementById('686f254a-068d-4203-814c-075343be458c'))\n",
       "})\n",
       " }) \n",
       "</script>"
      ],
      "text/plain": [
       "#<Plotly::Offline::HTML:0x00005577e1e32a20 @id=\"686f254a-068d-4203-814c-075343be458c\", @data=[{:y=>[0, 1, 1, 2, 3, 5, 8, 13, 21], :type=>:box, :boxpoints=>:all, :jitter=>0.3, :pointpos=>-1.8}], @layout={}, @config={:linkText=>\"Export to plot.ly\", :showLink=>true}, @embedded=true>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/plain": [
       "#<CZTop::Socket::PUB:0x5577e1be72a0 last_endpoint=\"tcp://127.0.0.1:60209\">"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# Box Plot That Displays the Underlying Data\n",
    "trace = {\n",
    "    y: [0, 1, 1, 2, 3, 5, 8, 13, 21],\n",
    "    boxpoints: :all,\n",
    "    jitter: 0.3,\n",
    "    pointpos: -1.8,\n",
    "    type: :box\n",
    "  }\n",
    "\n",
    "plot = Plotly::Plot.new(data: [trace])\n",
    "plot.show"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Ruby 2.5.1",
   "language": "ruby",
   "name": "ruby"
  },
  "language_info": {
   "file_extension": ".rb",
   "mimetype": "application/x-ruby",
   "name": "ruby",
   "version": "2.5.1"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}