Skip to content

Instantly share code, notes, and snippets.

@jackparmer
Created February 2, 2014 09:25
Show Gist options
  • Save jackparmer/8765246 to your computer and use it in GitHub Desktop.
Save jackparmer/8765246 to your computer and use it in GitHub Desktop.
Stacked, Horizontal Bar Chart Time Series in Plotly
Display the source blob
Display the rendered blob
Raw
{
"metadata": {
"name": "Stacked, Horizontal Bar Chart"
},
"nbformat": 3,
"nbformat_minor": 0,
"worksheets": [
{
"cells": [
{
"cell_type": "heading",
"level": 1,
"metadata": {},
"source": "Stacked, Horizontal Bar Chart Time Series in Plotly"
},
{
"cell_type": "heading",
"level": 3,
"metadata": {},
"source": "Inspired by http://mattbango.com/notebook/code/pure-css-timeline/<br>Questions? jack[at]plot[dot]ly"
},
{
"cell_type": "code",
"collapsed": false,
"input": "import plotly\npy = plotly.plotly('IPython.Demo', '1fw3zw2o13')",
"language": "python",
"metadata": {},
"outputs": [],
"prompt_number": 4
},
{
"cell_type": "code",
"collapsed": false,
"input": "categories = ['Design & Typography', 'Photography', 'Web Dev & Programming', \\\n '3D Modeling & Rendering', 'Drawing & Illustration'];\n\nfirst_white_stack = {'name': '',\n\t'x': categories,\n\t'y': [2006, 2005, 2003, 2002, 2002],\n 'marker':{'color': 'white'},\n\t'type': 'bar',\n 'bardir':'h'}\n\nmiddle_grey_stack = {'name': '',\n\t'x': categories,\n\t'y': [3, 4, 6, 3, 7],\n 'marker':{'color': 'lightgrey','line': {'color': 'violet','width': 2}},\n\t'type': 'bar',\n 'bardir':'h'}\n\nlast_white_stack = {'name': '',\n\t'x': categories,\n\t'y': [0, 0, 0, 4, 0],\n 'marker':{'color': 'white'},\n\t'type': 'bar',\n 'bardir':'h'}\n\ntext = [\n {'text':'Drawing & Illustration',\n 'xref':'x','yref':'y',\n 'showarrow': False,\n 'font':{'color':'#444'},\n 'x':2005.5,'y':4},\n {'text':'3D Modeling & Rendering',\n 'xref':'x','yref':'y',\n 'showarrow': False,\n 'font':{'color':'#444'},\n 'x':2003.5,'y':3},\n {'text':'Web Dev & Programming',\n 'xref':'x','yref':'y',\n 'showarrow': False,\n 'font':{'color':'#444'},\n 'x':2006,'y':2},\n {'text':'Photography',\n 'xref':'x','yref':'y',\n 'showarrow': False,\n 'font':{'color':'#444'},\n 'x':2007,'y':1}, \n {'text':'Design & Typography',\n 'xref':'x','yref':'y',\n 'showarrow': False,\n 'font':{'color':'#444'},\n 'x':2007.5,'y':0}, \n]\n\nlayout = {\n 'height' : 300,\n 'autosize': False,\n 'showlegend': False,\n 'annotations': text,\n 'xaxis': {'range' : [2002,2009], 'dtick':1, 'tickcolor':'grey', 'autotick':False, \\\n 'showgrid': False, 'showline': False},\n 'yaxis': {'showgrid': False, 'showline': False, 'ticks': '', 'showticklabels': False},\n 'barmode': 'stack',\n 'margin': {'l': 160},\n 'categories': categories}\n\npy.iplot([first_white_stack, middle_grey_stack, last_white_stack], layout=layout, height=300)",
"language": "python",
"metadata": {},
"outputs": [
{
"output_type": "stream",
"stream": "stdout",
"text": "\n\n\n"
},
{
"html": "<iframe height=\"350\" id=\"igraph\" scrolling=\"no\" seamless=\"seamless\" src=\"https://plot.ly/~IPython.Demo/1045/600/300\" width=\"650\"></iframe>",
"metadata": {},
"output_type": "pyout",
"prompt_number": 61,
"text": "<IPython.core.display.HTML at 0x1044377d0>"
}
],
"prompt_number": 61
},
{
"cell_type": "code",
"collapsed": false,
"input": "",
"language": "python",
"metadata": {},
"outputs": []
}
],
"metadata": {}
}
]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment