Skip to content

Instantly share code, notes, and snippets.

@chriddyp
Created January 16, 2014 18:21
Show Gist options
  • Save chriddyp/8460341 to your computer and use it in GitHub Desktop.
Save chriddyp/8460341 to your computer and use it in GitHub Desktop.
multiple y axis range
{
"metadata": {
"name": "multiple yaxis range"
},
"nbformat": 3,
"nbformat_minor": 0,
"worksheets": [
{
"cells": [
{
"cell_type": "code",
"collapsed": false,
"input": "import plotly\npp = plotly.plotly('IPython.Demo', '1fw3zw2o13')",
"language": "python",
"metadata": {},
"outputs": [],
"prompt_number": 1
},
{
"cell_type": "code",
"collapsed": false,
"input": "import numpy as np\nimport pandas as pd\n\ndates = pd.date_range(start='11/1/2008', end='7/31/2012', freq='M')\n\nc = ['#fbb4ae',\n'#b3cde3',\n'#ccebc5',\n'#decbe4',] \n\nprograms = ['USCG', 'COPPS', 'NOVA', 'WSC', 'CSA']\n\nband_width = 22\n\nSMA = [{'name': 'USCG',\n 'x': pd.date_range(start='2/1/2009', end='5/1/2009', freq='M'),\n 'y': np.ones(100)*5,\n 'mode':'lines',\n 'line':{'color': c[0], 'width': band_width},\n \"yaxis\": \"yaxis2\"\n},\n{'name': 'USCG',\n 'x': pd.date_range(start='1/1/2010', end='7/1/2010', freq='M'),\n 'y': np.ones(100)*5,\n 'mode':'lines',\n 'line':{'color': c[0], 'width': band_width},\n \"yaxis\": \"yaxis2\"\n},\n{'name': 'USCG',\n 'x': pd.date_range(start='11/1/2010', end='6/1/2011', freq='M'),\n 'y': np.ones(100)*5,\n 'mode':'lines',\n 'line':{'color': c[0], 'width': band_width},\n},\n{'name': 'USCG',\n 'x': pd.date_range(start='1/1/2012', end='3/1/2012', freq='M'),\n 'y': np.ones(100)*5,\n 'mode':'lines',\n 'line':{'color': c[0], 'width': band_width},\n \"yaxis\": \"yaxis2\"\n}\n,{'name': 'COPPS',\n 'x': pd.date_range(start='10/1/2009', end='12/31/2009', freq='M'),\n 'y': np.ones(100)*4,\n 'mode':'lines',\n 'line':{'color': c[1], 'width': band_width},\n \"yaxis\": \"yaxis2\"\n},\n{'name': 'NOVA',\n 'x': pd.date_range(start='11/1/2010', end='8/1/2012', freq='M'),\n 'y': np.ones(100)*3,\n 'mode':'lines',\n 'line':{'color': c[2], 'width': band_width},\n \"yaxis\": \"yaxis2\"\n},\n{'name': 'WSC',\n 'x': pd.date_range(start='12/1/2010', end='8/1/2012', freq='M'),\n 'y': np.ones(100)*2,\n 'mode':'lines',\n 'line':{'color': c[3], 'width': band_width},\n \"yaxis\": \"yaxis2\"\n},\n{'name': 'CSA',\n 'x': pd.date_range(start='2/1/2011', end='8/1/2012', freq='M'),\n 'y': np.ones(100)*1,\n 'mode':'lines',\n 'line':{'color': c[3], 'width': band_width},\n \"yaxis\": \"yaxis2\"\n}]\n\nsma_dates = pd.date_range(start='11/1/2008', end='7/31/2012', freq='12M')\n\nestimates = [{'x': sma_dates, 'y': np.array([0, -0.04, 0.16, -0.67]), 'name': 'Passenger'}]\n#estimates = [{'x': range(4), 'y': [0, -0.04, 0.16, -0.67], 'name': 'Passenger', \n#'marker':{'color':'rgb(111, 168, 220)'},\n#'error_y': {'type': 'data', 'array': [0, 0.08, 0.08, 0.08], 'visible': True, 'color': 'rgb(67, 67, 67)'}}]\n\n# data = [{'x': [1]*2, 'y': [1]*2, \"type\": \"line\"},\n# {'x': [1]*2, 'y': [2]*2, \"type\": \"line\"}]\n\nlayout = {\n \"yaxis2\":{\n 'showgrid': False,\n 'zeroline': False,\n 'ticks': '',\n \"showticklabels\" : False,\n \"overlaying\":\"y\",\n\n }, \n\n \"yaxis\":{\n \"range\": [0, 6], \n \"title\": \"Speed change from initial season\",\n \"titlefont\":{\n \"color\": '#1f77b4'\n },\n \"tickfont\":{\n \"color\": '#1f77b4'\n },\n 'showgrid': False,\n 'zeroline': False\n }, \n \"xaxis\": {'showgrid':False,'zeroline':False, \n 'title': 'Date',\n 'range': [dates[0], dates[-1]]},\n\n \"title\": \"\",\n 'showlegend': False\n}\n\n\npp.iplot(SMA, layout=layout) \n\n",
"language": "python",
"metadata": {},
"outputs": [
{
"html": "<iframe height=\"500\" id=\"igraph\" scrolling=\"no\" seamless=\"seamless\" src=\"https://plot.ly/~IPython.Demo/510/600/450\" width=\"650\"></iframe>",
"metadata": {},
"output_type": "pyout",
"prompt_number": 2,
"text": "<IPython.core.display.HTML at 0x10073c810>"
}
],
"prompt_number": 2
},
{
"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