Skip to content

Instantly share code, notes, and snippets.

@cldougl
Created May 25, 2016 14:51
Show Gist options
  • Select an option

  • Save cldougl/ed406dc5f927ed44fa71ea9040a3c1f0 to your computer and use it in GitHub Desktop.

Select an option

Save cldougl/ed406dc5f927ed44fa71ea9040a3c1f0 to your computer and use it in GitHub Desktop.
Display the source blob
Display the rendered blob
Raw
{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"import plotly.plotly as py\n",
"import plotly.graph_objs as go"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"text/html": [
"<iframe id=\"igraph\" scrolling=\"no\" style=\"border:none;\" seamless=\"seamless\" src=\"https://plot.ly/~chelsea_lyn/11609.embed\" height=\"525px\" width=\"100%\"></iframe>"
],
"text/plain": [
"<plotly.tools.PlotlyDisplay object>"
]
},
"execution_count": 3,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# data\n",
"x = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]\n",
"y1 = [1000, 500, 250, 5, 100, 500, 600, 75, 10, 200, 100]\n",
"y2 = [500, 250, 5, 100, 500, 600, 75, 10, 200, 100, 1000]\n",
"\n",
"# invert second trace\n",
"y2neg = [-y for y in y2]\n",
"\n",
"# create traces with fill = 'tozeroy' \n",
"trace_pos = go.Scatter(x=x, y=y1, text=y1,\n",
" fill='tozeroy',\n",
" hoverinfo='x+text')\n",
"\n",
"# set y to the negative array and text to the positive array\n",
"# set hoverinfo to 'x+text' to remove negative y values in hover\n",
"trace_neg = go.Scatter(x=x, y=y2neg, text=y2,\n",
" fill='tozeroy',\n",
" hoverinfo='x+text')\n",
"\n",
"data=[trace_pos, trace_neg]\n",
"\n",
"# set the tickvals to the neg - pos vals\n",
"# set the ticktext to all positive values\n",
"layout=dict(\n",
" yaxis = dict(\n",
" tickvals = [-1000, -500, 0, 500, 1000],\n",
" ticktext = [1000, 500, 0, 500, 1000])\n",
" )\n",
"\n",
"\n",
"fig=dict(data=data, layout=layout)\n",
"py.iplot(fig)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 2",
"language": "python",
"name": "python2"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 2
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython2",
"version": "2.7.11"
}
},
"nbformat": 4,
"nbformat_minor": 0
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment