Created
May 25, 2016 17:22
-
-
Save cldougl/ad4cf899b5272337c95cb7bf351a14ff to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| { | |
| "cells": [ | |
| { | |
| "cell_type": "code", | |
| "execution_count": 1, | |
| "metadata": { | |
| "collapsed": false | |
| }, | |
| "outputs": [ | |
| { | |
| "data": { | |
| "text/html": [ | |
| "<iframe id=\"igraph\" scrolling=\"no\" style=\"border:none;\" seamless=\"seamless\" src=\"https://plot.ly/~chelsea_lyn/11670.embed\" height=\"525px\" width=\"100%\"></iframe>" | |
| ], | |
| "text/plain": [ | |
| "<plotly.tools.PlotlyDisplay object>" | |
| ] | |
| }, | |
| "execution_count": 1, | |
| "metadata": {}, | |
| "output_type": "execute_result" | |
| } | |
| ], | |
| "source": [ | |
| "import plotly.plotly as py\n", | |
| "import plotly.graph_objs as go\n", | |
| "\n", | |
| "# 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='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='text')\n", | |
| "\n", | |
| "# add trace for x labels on zeroline\n", | |
| "trace_lab = go.Scatter(x=x, y=[0]*len(x),\n", | |
| " text=x, mode='markers+text',\n", | |
| " marker=dict(color='black', symbol=142),\n", | |
| " textposition='bottom',\n", | |
| " hoverinfo='text')\n", | |
| "\n", | |
| "data=[trace_pos, trace_neg, trace_lab]\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", | |
| " xaxis = dict(\n", | |
| " showticklabels=False))\n", | |
| "\n", | |
| "fig = go.Figure(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