import plotly # You should replace these values with your own registration information reg = plotly.signup("foo12345", "fake_email_address@vanderbilt.edu") reg ply = plotly.plotly(username_or_email=reg['un'], key=reg['api_key']) import numpy as np data = { 'x': np.random.randn(1000), 'y': np.random.randn(1000), "type": "scatter", "name": "Random Numbers", 'mode': 'markers' } ply.iplot(data) import numpy as np ply.iplot([{'y': np.random.randn(10), 'type':'box'} for i in range(20)], layout={'showlegend':False}) data = [ { "x":[1,2,3], "y":[40,50,60], "name":"yaxis data" }, { "x":[2,3,4], "y":[4,5,6], "yaxis":"y2", "name": "yaxis2 data" } ] layout = { "yaxis":{ "title": "yaxis title", }, "yaxis2":{ "title": "yaxis2 title", "titlefont":{ "color":"rgb(148, 103, 189)" }, "tickfont":{ "color":"rgb(148, 103, 189)" }, "overlaying":"y", "side":"right", }, "title": "Double Y Axis Example", } ply.iplot(data, layout=layout) data = [ { "x":[1,2,3], "y":[4,5,6], "name":"yaxis1 data" }, { "x":[2,3,4], "y":[40,50,60], "name":"yaxis2 data", "yaxis":"y2" }, { "x":[3,4,5], "y":[400,500,600], "name":"yaxis3 data", "yaxis":"y3" } ] c = ['#1f77b4', # muted blue '#ff7f0e', # safety orange '#2ca02c'] # cooked asparagus green layout = { "width":800, "xaxis":{ "domain":[0.3,0.7] }, "yaxis":{ "title": "yaxis title", "titlefont":{ "color":c[0] }, "tickfont":{ "color":c[0] }, }, "yaxis2":{ "overlaying":"y", "side":"tight", "anchor":"free", "position":0.15, "title": "yaxis2 title", "titlefont":{ "color":c[1] }, "tickfont":{ "color":c[1] }, }, "yaxis3":{ "overlaying":"y", "side":"left", "anchor":"free", "position":0, "title": "yaxis3 title", "titlefont":{ "color":c[2] }, "tickfont":{ "color":c[2] }, }, "title": "multiple y-axes example" } ply.iplot(data, layout=layout) ''' Created January 14, 2014 by Chris Fonnesbeck Licensed under a Creative Commons Attribution 4.0 International License. ''' import pandas as pd dates = pd.date_range(start='11/1/2008', end='7/31/2012', freq='M') c = ['#fbb4ae', '#b3cde3', '#ccebc5', '#decbe4'] band_width = 15 opacity = 0.8 # Management interventions in seasonal management areas (SMA) SMA = [{'name': 'Intermittant, at-sea radio', 'x': pd.date_range(start='2/1/2009', end='5/1/2009', freq='M'), 'y': ['USCG']*100, 'mode':'lines', 'line':{'color': c[0], 'width': band_width}, "yaxis": "y2", 'showlegend': False, 'opacity': opacity }, {'name': 'Intermittant, at-sea radio', 'x': pd.date_range(start='1/1/2010', end='7/1/2010', freq='M'), 'y': ['USCG']*100, 'mode':'lines', 'line':{'color': c[0], 'width': band_width}, "yaxis": "y2", 'showlegend': False, 'opacity': opacity }, {'name': 'Intermittant, at-sea radio', 'x': pd.date_range(start='11/1/2010', end='6/1/2011', freq='M'), 'y': ['USCG']*100, 'mode':'lines', 'line':{'color': c[0], 'width': band_width}, "yaxis": "y2", 'showlegend': False, 'opacity': opacity }, {'name': 'Intermittant, at-sea radio', 'x': pd.date_range(start='1/1/2012', end='3/1/2012', freq='M'), 'y': ['USCG']*100, 'mode':'lines', 'line':{'color': c[0], 'width': band_width}, "yaxis": "y2", 'showlegend': False, 'opacity': opacity } ,{'name': 'Intermittant, letter', 'x': pd.date_range(start='10/1/2009', end='12/31/2009', freq='M'), 'y': ['COPPS']*100, 'mode':'lines', 'line':{'color': c[1], 'width': band_width}, "yaxis": "y2", 'showlegend': False, 'opacity': opacity }, {'name': 'Certified mail, ongoing litigation', 'x': pd.date_range(start='11/1/2010', end='8/1/2012', freq='M'), 'y': ['NOVA']*100, 'mode':'lines', 'line':{'color': c[2], 'width': band_width}, "yaxis": "y2", 'showlegend': False, 'opacity': opacity }, {'name': 'E-mail, monthly summaries', 'x': pd.date_range(start='12/1/2010', end='8/1/2012', freq='M'), 'y': ['WSC']*100, 'mode':'lines', 'line':{'color': c[3], 'width': band_width}, "yaxis": "y2", 'showlegend': False, 'opacity': opacity }, {'name': 'E-mail, monthly summaries', 'x': pd.date_range(start='2/1/2011', end='8/1/2012', freq='M'), 'y': ['CSA']*100, 'mode':'lines', 'line':{'color': c[3], 'width': band_width}, "yaxis": "y2", 'showlegend': False, 'opacity': opacity, } ][::-1] sma_dates = pd.date_range(start='2/1/2009', end='11/1/2012', freq='12M') sds = 2 line_width = 2 line_color = "rgb(3,78,123)" # Parameter estimates from model estimates = [{'x': sma_dates, 'y': np.array([0, -0.04, 0.16, -0.67]), 'name': 'Passenger', 'showlegend': True, "line":{"color": line_color, "width": line_width, "dash":"dashdot"}, 'error_y': {'type': 'data', 'array': np.array([0, 0.08, 0.08, 0.08]) * sds, 'visible': True, "color": line_color}}, {'x': sma_dates, 'y': np.array([0, -0.26, -0.92, -1.35]), 'name': 'Cargo', 'showlegend': True, "line":{"color": line_color, "width": line_width, "dash":"dot"}, 'error_y': {'type': 'data', 'array': np.array([0, 0.02, 0.02, 0.02]) * sds, 'visible': True, "color": line_color}}, {'x': sma_dates, 'y': np.array([0, -0.02, -0.41, -0.62]), 'name': 'Tanker', 'showlegend': True, "line":{"color": line_color, "width": line_width, "dash":"solid"}, 'error_y': {'type': 'data', 'array': np.array([0, 0.03, 0.03, 0.03]) * sds, 'visible': True, "color": line_color}},] legendstyle = {"x" : 0, "y" : 0, "bgcolor" : "#F0F0F0", "bordercolor" : "#FFFFFF",} layout = { "yaxis2":{'showgrid': False, 'zeroline': True, 'side': 'right', "showticklabels" : True, 'domain': [2./3., 1], 'title': 'Program' }, "yaxis":{"title": "Speed change from 1st season", 'showgrid': False, 'zeroline': True, "zerolinecolor" : "#F0F0F0", "zerolinewidth" : 4, 'mode': 'markers', 'domain': [0, 2./3.] }, "xaxis": {'showgrid':False, 'zeroline':False, 'title': 'Date', 'range': [dates[0], dates[-1]]}, "title": "Vessel speed change in response to notification programs", 'showlegend': True, "legend": legendstyle } ply.iplot(SMA + estimates, layout=layout) titanic = pd.read_csv("http://biostat.mc.vanderbilt.edu/wiki/pub/Main/DataSets/titanic3.csv") titanic.head() age_by_class = [{'y': data.values, 'name': pclass, 'type': 'box', 'boxpoints': 'all', 'jitter': 0.3} for pclass,data in list(titanic.groupby('pclass')['age'])] layout = {'xaxis': {'showgrid':False,'zeroline':False, 'title': 'Passenger class'}, 'yaxis': {'zeroline':False,'gridcolor':'white', 'title': 'Age'}, 'plot_bgcolor': 'rgb(233,233,233)', 'showlegend':False} ply.iplot(age_by_class, layout=layout) %load_ext rmagic %%R -o hist_url library(plotly) py <- plotly('foo12345', key='daia9p1ryi') # Sample data samples <- rnorm(50) # Normal density x_norm <- seq(-5,5,length=100) y_norm <- 1./sqrt(2*pi)*exp(-x_norm**2/2.) # layout l <- list(showlegend = FALSE, xaxis = list(zeroline = FALSE), yaxis = list(zeroline = FALSE)) # Histogram data dataHistogram <- list(y = samples, type = 'histogramy', histnorm = 'probability density') # Curve data dataArea <- list(x = x_norm, y = y_norm, fill = 'tozeroy') # Call plotly response <- py$plotly(list(dataHistogram, dataArea), kwargs = list(layout = l)) # url and filename hist_url <- response$url hist_url from IPython.display import HTML HTML(''.format(hist_url[0])) from pymc.examples import disaster_model from pymc import MCMC, graph M = MCMC(disaster_model) ply.iplot({'y': disaster_model.disasters_array, 'x': range(1851, 1963), "type": "scatter", "mode": "lines", "name": "UK coal mining disasters, 1851-1962"}) nchains = 3 for i in range(nchains): M.sample(5000, progress_bar=False) trace = M.early_mean.trace() data = [{'y': trace}] data.append({'y': trace, 'xaxis': 'x2', 'yaxis': 'y2', 'type': 'histogramy'}) layout = { "xaxis":{ "domain":[0,0.5], "title": "Iteration" }, "yaxis":{ "title": "Value" }, "xaxis2":{ "domain":[0.55,1], "title": "Value" }, "yaxis2":{ "anchor":"x2", "side": "right", "title": "Frequency" }, "showlegend": False, "title": "Posterior samples of early Poisson mean" } ply.iplot(data, layout=layout, width=850,height=400) nparams = len(M.stochastics) mcmc_data = {'chain {0}'.format(i): {s.__name__:s.trace(chain=i)[:100] for s in M.stochastics} for i in range(nchains)} attr = mcmc_data['chain 1'].keys() colors = {'chain 0': 'rgb(31, 119, 180)', 'chain 1': 'rgb(255, 127, 14)', 'chain 2': 'rgb(44, 160, 44)'} data = [] for i in range(nparams): for j in range(nparams): for chain in mcmc_data.keys(): data.append({"name": chain, "x": mcmc_data[chain][attr[i]], "y": mcmc_data[chain][attr[j]], "type":"scatter","mode":"markers", 'marker': {'color': colors[chain], 'opacity':0.2}, "xaxis": "x"+(str(i) if i!=0 else ''), "yaxis": "y"+(str(j) if j!=0 else '')}) padding = 0.04; domains = [[i*padding + i*(1-3*padding)/nparams, i*padding + ((i+1)*(1-3*padding)/nparams)] for i in range(nparams)] layout = { "xaxis":{"domain":domains[0], "title":attr[0], 'zeroline':False,'showline':False,'ticks':'', 'titlefont':{'color': "rgb(67, 67, 67)"},'tickfont':{'color': 'rgb(102,102,102)'}}, "yaxis":{"domain":domains[0], "title":attr[0], 'zeroline':False,'showline':False,'ticks':'', 'titlefont':{'color': "rgb(67, 67, 67)"},'tickfont':{'color': 'rgb(102,102,102)'}}, "xaxis1":{"domain":domains[1], "title":attr[1], 'zeroline':False,'showline':False,'ticks':'', 'titlefont':{'color': "rgb(67, 67, 67)"},'tickfont':{'color': 'rgb(102,102,102)'}}, "yaxis1":{"domain":domains[1], "title":attr[1], 'zeroline':False,'showline':False,'ticks':'', 'titlefont':{'color': "rgb(67, 67, 67)"},'tickfont':{'color': 'rgb(102,102,102)'}}, "xaxis2":{"domain":domains[2], "title":attr[2], 'zeroline':False,'showline':False,'ticks':'', 'titlefont':{'color': "rgb(67, 67, 67)"},'tickfont':{'color': 'rgb(102,102,102)'}}, "yaxis2":{"domain":domains[2], "title":attr[2], 'zeroline':False,'showline':False,'ticks':'', 'titlefont':{'color': "rgb(67, 67, 67)"},'tickfont':{'color': 'rgb(102,102,102)'}}, "showlegend":False, "title":"Posterior samples for coal mining disasters model", "titlefont":{'color':'rgb(67,67,67)', 'size': 20} } ply.iplot(data,layout=layout)