examples/Pie Charts.ipynb
{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"metadata": {
"collapsed": false
},
"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=\"de199c69-f935-4778-8724-3628dd873a18\" style=\"height: 100%; width: 100%;\"></div>\n",
"\n",
"<script>\n",
" require(['plotly'], function(Plotly) { \n",
"Plotly.newPlot(\n",
" 'de199c69-f935-4778-8724-3628dd873a18',\n",
" [{\"labels\":[\"Residential\",\"Non-Residential\",\"Utility\"],\"values\":[19,26,55],\"type\":\"pie\"}],\n",
" {\"title\":\"Forcasted 2014 U.S. PV Installations by Market Segment\"},\n",
" {\"linkText\":\"Export to plot.ly\",\"showLink\":true}\n",
")\n",
"\n",
"window.addEventListener('resize', function() {\n",
" Plotly.Plots.resize(document.getElementById('de199c69-f935-4778-8724-3628dd873a18'))\n",
"})\n",
" }) \n",
"</script>"
],
"text/plain": [
"#<Plotly::Offline::HTML:0x007fb37a9e7660 @id=\"de199c69-f935-4778-8724-3628dd873a18\", @data=[{:labels=>[\"Residential\", \"Non-Residential\", \"Utility\"], :values=>[19, 26, 55], :type=>:pie}], @layout={:title=>\"Forcasted 2014 U.S. PV Installations by Market Segment\"}, @config={:linkText=>\"Export to plot.ly\", :showLink=>true}, @embedded=true>"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"# Basic Pie Chart\n",
"require 'rbplotly'\n",
"\n",
"data = [{\n",
" labels: %w(Residential Non-Residential Utility),\n",
" values: [19, 26, 55],\n",
" type: :pie\n",
"}]\n",
"\n",
"layout = { title: 'Forcasted 2014 U.S. PV Installations by Market Segment' }\n",
"\n",
"plot = Plotly::Plot.new(data: data, layout: layout )\n",
"plot.show"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {
"collapsed": false
},
"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=\"f2ed54f8-f9fa-4386-b222-917ab5f9ef9e\" style=\"height: 100%; width: 100%;\"></div>\n",
"\n",
"<script>\n",
" require(['plotly'], function(Plotly) { \n",
"Plotly.newPlot(\n",
" 'f2ed54f8-f9fa-4386-b222-917ab5f9ef9e',\n",
" [{\"labels\":[\"US\",\"China\",\"European\",\"Union\",\"Russian\",\"Federation\",\"Brazil\",\"India\",\"Rest of World\"],\"values\":[16,15,12,6,5,4,42],\"type\":\"pie\",\"name\":\"GHG Emissions\",\"domain\":{\"x\":[0,0.5]},\"hoverinfo\":\"label+percent+name\",\"hole\":0.4},{\"labels\":[\"US\",\"China\",\"European\",\"Union\",\"Russian\",\"Federation\",\"Brazil\",\"India\",\"Rest of World\"],\"values\":[27,11,25,8,1,3,25],\"type\":\"pie\",\"name\":\"CO2 Emissions\",\"domain\":{\"x\":[0.5,1]},\"hoverinfo\":\"label+percent+name\",\"hole\":0.4}],\n",
" {},\n",
" {\"linkText\":\"Export to plot.ly\",\"showLink\":true}\n",
")\n",
"\n",
"window.addEventListener('resize', function() {\n",
" Plotly.Plots.resize(document.getElementById('f2ed54f8-f9fa-4386-b222-917ab5f9ef9e'))\n",
"})\n",
" }) \n",
"</script>"
],
"text/plain": [
"#<Plotly::Offline::HTML:0x007fb37a94cde0 @id=\"f2ed54f8-f9fa-4386-b222-917ab5f9ef9e\", @data=[{:labels=>[\"US\", \"China\", \"European\", \"Union\", \"Russian\", \"Federation\", \"Brazil\", \"India\", \"Rest of World\"], :values=>[16, 15, 12, 6, 5, 4, 42], :type=>:pie, :name=>\"GHG Emissions\", :domain=>{:x=>[0, 0.5]}, :hoverinfo=>:\"label+percent+name\", :hole=>0.4}, {:labels=>[\"US\", \"China\", \"European\", \"Union\", \"Russian\", \"Federation\", \"Brazil\", \"India\", \"Rest of World\"], :values=>[27, 11, 25, 8, 1, 3, 25], :type=>:pie, :name=>\"CO2 Emissions\", :domain=>{:x=>[0.5, 1]}, :hoverinfo=>:\"label+percent+name\", :hole=>0.4}], @layout={}, @config={:linkText=>\"Export to plot.ly\", :showLink=>true}, @embedded=true>"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"# Donut Chart\n",
"require 'rbplotly'\n",
"\n",
"trace1 = {\n",
" name: 'GHG Emissions',\n",
" values: [16, 15, 12, 6, 5, 4, 42],\n",
" domain: { x: [0, 0.5] },\n",
" \n",
" labels: %w(US China European Union Russian Federation Brazil India Rest\\ of\\ World),\n",
" hoverinfo: :'label+percent+name',\n",
" hole: 0.4,\n",
" type: :pie,\n",
"}\n",
"\n",
"trace2 = trace1.merge({\n",
" name: 'CO2 Emissions',\n",
" values: [27, 11, 25, 8, 1, 3, 25],\n",
" domain: { x: [0.5, 1] }\n",
"})\n",
"\n",
"plot = Plotly::Plot.new(data: [trace1, trace2])\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
}