{ "cells": [ { "cell_type": "code", "execution_count": 1, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/html": [ "\n", " \n", "\n", "\n", "
\n", "\n", "" ], "text/plain": [ "#[\"giraffes\", \"orangutans\", \"monkeys\"], :y=>[20, 14, 23], :type=>:bar}], @layout={}, @config={:linkText=>\"Export to plot.ly\", :showLink=>true}, @embedded=true>" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "# Basic Bar Chart\n", "require 'rbplotly'\n", "\n", "trace = { \n", " x: %w(giraffes orangutans monkeys),\n", " y: [20, 14, 23],\n", " type: :bar\n", "}\n", "\n", "plot = Plotly::Plot.new(data: [trace])\n", "plot.show" ] }, { "cell_type": "code", "execution_count": 2, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/html": [ "\n", " \n", "\n", "\n", "
\n", "\n", "" ], "text/plain": [ "#[\"giraffes\", \"orangutans\", \"monkeys\"], :y=>[20, 14, 23], :type=>:bar, :name=>\"SF Zoo\"}, {:x=>[\"giraffes\", \"orangutans\", \"monkeys\"], :y=>[12, 18, 29], :type=>:bar, :name=>\"LA Zoo\"}], @layout={}, @config={:linkText=>\"Export to plot.ly\", :showLink=>true}, @embedded=true>" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "# Grouped Bar Chart\n", "require 'rbplotly'\n", "\n", "trace1 = {\n", " x: %w(giraffes orangutans monkeys),\n", " y: [20, 14, 23],\n", " type: :bar,\n", " name: 'SF Zoo'\n", "}\n", "trace2 = {\n", " x: %w(giraffes orangutans monkeys),\n", " y: [12, 18, 29],\n", " type: :bar,\n", " name: 'LA Zoo'\n", "}\n", "\n", "plot = Plotly::Plot.new(data: [trace1, trace2])\n", "plot.show" ] }, { "cell_type": "code", "execution_count": 3, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/html": [ "\n", " \n", "\n", "\n", "
\n", "\n", "" ], "text/plain": [ "#[\"giraffes\", \"orangutans\", \"monkeys\"], :y=>[20, 14, 23], :type=>:bar, :name=>\"SF Zoo\"}, {:x=>[\"giraffes\", \"orangutans\", \"monkeys\"], :y=>[12, 18, 29], :type=>:bar, :name=>\"LA Zoo\"}], @layout={:barmode=>:stack}, @config={:linkText=>\"Export to plot.ly\", :showLink=>true}, @embedded=true>" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "# Grouped to Stacked\n", "plot.layout.barmode = :stack\n", "plot.show" ] }, { "cell_type": "code", "execution_count": 4, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/html": [ "\n", " \n", "\n", "\n", "
\n", "\n", "" ], "text/plain": [ "#[\"giraffes\", \"orangutans\", \"monkeys\"], :y=>[20, 14, 23], :type=>:bar, :name=>\"SF Zoo\"}, {:x=>[\"giraffes\", \"orangutans\", \"monkeys\"], :y=>[12, 18, 29], :type=>:bar, :name=>\"LA Zoo\"}], @layout={:barmode=>:stack}, @config={:linkText=>\"Export to plot.ly\", :showLink=>true}, @embedded=true>" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "# Stacked Bar Chart\n", "require 'rbplotly'\n", "\n", "trace1 = {\n", " x: %w(giraffes orangutans monkeys),\n", " y: [20, 14, 23],\n", " type: :bar,\n", " name: 'SF Zoo'\n", "}\n", "trace2 = {\n", " x: %w(giraffes orangutans monkeys),\n", " y: [12, 18, 29],\n", " type: :bar,\n", " name: 'LA Zoo'\n", "}\n", "\n", "plot = Plotly::Plot.new(data: [trace1, trace2], layout: { barmode: :stack } )\n", "plot.show" ] }, { "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": 1 }