Closed Kully closed 6 years ago
In Python 2.7:
http://plot.ly/path/to/chart/url Reason(s) for failure
corrected code
(if multiple cells are corrected, there will be a ---
separating the cells)
https://plot.ly/python/line-and-scatter/#large-data-sets old: lines; new: scatter points
[X] https://plot.ly/python/line-charts/#filled-lines BROKEN: color not valid type
import plotly.plotly as py
import plotly.graph_objs as go
x = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] x_rev = x[::-1]
y1 = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] y1_upper = [2, 3, 4, 5, 6, 7, 8, 9, 10, 11] y1_lower = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] y1_lower = y1_lower[::-1]
y2 = [5, 2.5, 5, 7.5, 5, 2.5, 7.5, 4.5, 5.5, 5] y2_upper = [5.5, 3, 5.5, 8, 6, 3, 8, 5, 6, 5.5] y2_lower = [4.5, 2, 4.4, 7, 4, 2, 7, 4, 5, 4.75] y2_lower = y2_lower[::-1]
y3 = [10, 8, 6, 4, 2, 0, 2, 4, 2, 0] y3_upper = [11, 9, 7, 5, 3, 1, 3, 5, 3, 1] y3_lower = [9, 7, 5, 3, 1, -.5, 1, 3, 1, -1] y3_lower = y3_lower[::-1]
trace1 = go.Scatter( x=x+x_rev, y=y1_upper+y1_lower, fill='tozerox', fillcolor='rgba(0,100,80,0.2)', line=dict(color='rgba(255,255,255,0)'), showlegend=False, name='Fair', ) trace2 = go.Scatter( x=x+x_rev, y=y2_upper+y2_lower, fill='tozerox', fillcolor='rgba(0,176,246,0.2)', line=dict(color='rgba(255,255,255,0)'), name='Premium', showlegend=False, ) trace3 = go.Scatter( x=x+x_rev, y=y3_upper+y3_lower, fill='tozerox', fillcolor='rgba(231,107,243,0.2)', line=dict(color='rgba(255,255,255,0)'), showlegend=False, name='Fair', ) trace4 = go.Scatter( x=x, y=y1, line=dict(color='rgb(0,100,80)'), mode='lines', name='Fair', ) trace5 = go.Scatter( x=x, y=y2, line=dict(color='rgb(0,176,246)'), mode='lines', name='Premium', ) trace6 = go.Scatter( x=x, y=y3, line=dict(color='rgb(231,107,243)'), mode='lines', name='Ideal', )
data = [trace1, trace2, trace3, trace4, trace5, trace6]
layout = go.Layout( paper_bgcolor='rgb(255,255,255)', plot_bgcolor='rgb(229,229,229)', xaxis=dict( gridcolor='rgb(255,255,255)', range=[1,10], showgrid=True, showline=False, showticklabels=True, tickcolor='rgb(127,127,127)', ticks='outside', zeroline=False ), yaxis=dict( gridcolor='rgb(255,255,255)', showgrid=True, showline=False, showticklabels=True, tickcolor='rgb(127,127,127)', ticks='outside', zeroline=False ), ) fig = go.Figure(data=data, layout=layout) py.iplot(fig, filename= 'shaded_lines')
- [X] https://plot.ly/python/pie-charts/#donut-chart `BROKEN: text must be a list/tuple in data`
import plotly.plotly as py import plotly.graph_objs as go
fig = { "data": [ { "values": [16, 15, 12, 6, 5, 4, 42], "labels": [ "US", "China", "European Union", "Russian Federation", "Brazil", "India", "Rest of World" ], "domain": {"x": [0, .48]}, "name": "GHG Emissions", "hoverinfo":"label+percent+name", "hole": .4, "type": "pie" }, { "values": [27, 11, 25, 8, 1, 3, 25], "labels": [ "US", "China", "European Union", "Russian Federation", "Brazil", "India", "Rest of World" ], "text":["CO2"], "textposition":"inside", "domain": {"x": [.52, 1]}, "name": "CO2 Emissions", "hoverinfo":"label+percent+name", "hole": .4, "type": "pie" }], "layout": { "title":"Global Emissions 1990-2011", "annotations": [ { "font": { "size": 20 }, "showarrow": False, "text": "GHG", "x": 0.20, "y": 0.5 }, { "font": { "size": 20 }, "showarrow": False, "text": "CO2", "x": 0.8, "y": 0.5 } ] } } py.iplot(fig, filename='donut')
- [X] https://plot.ly/python/dot-plots/#styled-categorical-dot-plot `BROKEN: autotick removal`
import plotly.plotly as py import plotly.graph_objs as go
country = ['Switzerland (2011)', 'Chile (2013)', 'Japan (2014)', 'United States (2012)', 'Slovenia (2014)', 'Canada (2011)', 'Poland (2010)', 'Estonia (2015)', 'Luxembourg (2013)', 'Portugal (2011)'] voting_pop = [40, 45.7, 52, 53.6, 54.1, 54.2, 54.5, 54.7, 55.1, 56.6] reg_voters = [49.1, 42, 52.7, 84.3, 51.7, 61.1, 55.3, 64.2, 91.1, 58.9]
trace0 = go.Scatter( x=voting_pop, y=country, mode='markers', name='Percent of estimated voting age population', marker=dict( color='rgba(156, 165, 196, 0.95)', line=dict( color='rgba(156, 165, 196, 1.0)', width=1, ), symbol='circle', size=16, ) ) trace1 = go.Scatter( x=reg_voters, y=country, mode='markers', name='Percent of estimated registered voters', marker=dict( color='rgba(204, 204, 204, 0.95)', line=dict( color='rgba(217, 217, 217, 1.0)', width=1, ), symbol='circle', size=16, ) )
data = [trace0, trace1] layout = go.Layout( title="Votes cast for ten lowest voting age population in OECD countries", xaxis=dict( showgrid=False, showline=True, linecolor='rgb(102, 102, 102)', titlefont=dict( color='rgb(204, 204, 204)' ), tickfont=dict( color='rgb(102, 102, 102)', ), showticklabels=True, dtick=10, ticks='outside', tickcolor='rgb(102, 102, 102)', ), margin=dict( l=140, r=40, b=50, t=80 ), legend=dict( font=dict( size=10, ), yanchor='middle', xanchor='right', ), width=800, height=600, paper_bgcolor='rgb(254, 247, 234)', plot_bgcolor='rgb(254, 247, 234)', hovermode='closest', ) fig = go.Figure(data=data, layout=layout) py.iplot(fig, filename='lowest-oecd-votes-cast')
- [X] https://plot.ly/python/horizontal-bar-charts/#color-palette-for-bar-chart `BROKEN: x cannot be int - must be a list`
import plotly.plotly as py import plotly.graph_objs as go
top_labels = ['Strongly
agree', 'Agree', 'Neutral', 'Disagree',
'Strongly
disagree']
colors = ['rgba(38, 24, 74, 0.8)', 'rgba(71, 58, 131, 0.8)', 'rgba(122, 120, 168, 0.8)', 'rgba(164, 163, 204, 0.85)', 'rgba(190, 192, 213, 1)']
x_data = [[21, 30, 21, 16, 12], [24, 31, 19, 15, 11], [27, 26, 23, 11, 13], [29, 24, 15, 18, 14]]
y_data = ['The course was effectively
organized',
'The course developed my
abilities and skills ' +
'for
the subject', 'The course developed ' +
'my
ability to think critically about
the subject',
'I would recommend this
course to a friend']
traces = []
for i in range(0, len(x_data[0])): for xd, yd in zip(x_data, y_data): traces.append(go.Bar( x=[xd[i]], y=[yd], orientation='h', marker=dict( color=colors[i], line=dict( color='rgb(248, 248, 249)', width=1) ) ))
layout = go.Layout( xaxis=dict( showgrid=False, showline=False, showticklabels=False, zeroline=False, domain=[0.15, 1] ), yaxis=dict( showgrid=False, showline=False, showticklabels=False, zeroline=False, ), barmode='stack', paper_bgcolor='rgb(248, 248, 255)', plot_bgcolor='rgb(248, 248, 255)', margin=dict( l=120, r=10, t=140, b=80 ), showlegend=False, )
annotations = []
for yd, xd in zip(y_data, x_data):
annotations.append(dict(xref='paper', yref='y',
x=0.14, y=yd,
xanchor='right',
text=str(yd),
font=dict(family='Arial', size=14,
color='rgb(67, 67, 67)'),
showarrow=False, align='right'))
# labeling the first percentage of each bar (x_axis)
annotations.append(dict(xref='x', yref='y',
x=xd[0] / 2, y=yd,
text=str(xd[0]) + '%',
font=dict(family='Arial', size=14,
color='rgb(248, 248, 255)'),
showarrow=False))
# labeling the first Likert scale (on the top)
if yd == y_data[-1]:
annotations.append(dict(xref='x', yref='paper',
x=xd[0] / 2, y=1.1,
text=top_labels[0],
font=dict(family='Arial', size=14,
color='rgb(67, 67, 67)'),
showarrow=False))
space = xd[0]
for i in range(1, len(xd)):
# labeling the rest of percentages for each bar (x_axis)
annotations.append(dict(xref='x', yref='y',
x=space + (xd[i]/2), y=yd,
text=str(xd[i]) + '%',
font=dict(family='Arial', size=14,
color='rgb(248, 248, 255)'),
showarrow=False))
# labeling the Likert scale
if yd == y_data[-1]:
annotations.append(dict(xref='x', yref='paper',
x=space + (xd[i]/2), y=1.1,
text=top_labels[i],
font=dict(family='Arial', size=14,
color='rgb(67, 67, 67)'),
showarrow=False))
space += xd[i]
layout['annotations'] = annotations
fig = go.Figure(data=traces, layout=layout) py.iplot(fig, filename='bar-colorscale')
- [X] https://plot.ly/python/horizontal-bar-charts/#bar-chart-with-line-plot `BROKEN: xaxis1 -> xaxis and yaxis1 -> yaxis`
import plotly.plotly as py import plotly.graph_objs as go from plotly import tools
import numpy as np
y_saving = [1.3586, 2.2623000000000002, 4.9821999999999997, 6.5096999999999996, 7.4812000000000003, 7.5133000000000001, 15.2148, 17.520499999999998 ] y_net_worth = [93453.919999999998, 81666.570000000007, 69889.619999999995, 78381.529999999999, 141395.29999999999, 92969.020000000004, 66090.179999999993, 122379.3] x_saving = ['Japan', 'United Kingdom', 'Canada', 'Netherlands', 'United States', 'Belgium', 'Sweden', 'Switzerland'] x_net_worth = ['Japan', 'United Kingdom', 'Canada', 'Netherlands', 'United States', 'Belgium', 'Sweden', 'Switzerland' ] trace0 = go.Bar( x=y_saving, y=x_saving, marker=dict( color='rgba(50, 171, 96, 0.6)', line=dict( color='rgba(50, 171, 96, 1.0)', width=1), ), name='Household savings, percentage of household disposable income', orientation='h', ) trace1 = go.Scatter( x=y_net_worth, y=x_net_worth, mode='lines+markers', line=dict( color='rgb(128, 0, 128)'), name='Household net worth, Million USD/capita', ) layout = dict( title='Household savings & net worth for eight OECD countries', yaxis=dict( showgrid=False, showline=False, showticklabels=True, domain=[0, 0.85], ), yaxis2=dict( showgrid=False, showline=True, showticklabels=False, linecolor='rgba(102, 102, 102, 0.8)', linewidth=2, domain=[0, 0.85], ), xaxis=dict( zeroline=False, showline=False, showticklabels=True, showgrid=True, domain=[0, 0.42], ), xaxis2=dict( zeroline=False, showline=False, showticklabels=True, showgrid=True, domain=[0.47, 1], side='top', dtick=25000, ), legend=dict( x=0.029, y=1.038, font=dict( size=10, ), ), margin=dict( l=100, r=20, t=70, b=70, ), paper_bgcolor='rgb(248, 248, 255)', plot_bgcolor='rgb(248, 248, 255)', )
annotations = []
y_s = np.round(y_saving, decimals=2) y_nw = np.rint(y_net_worth)
for ydn, yd, xd in zip(y_nw, y_s, x_saving):
annotations.append(dict(xref='x2', yref='y2',
y=xd, x=ydn - 20000,
text='{:,}'.format(ydn) + 'M',
font=dict(family='Arial', size=12,
color='rgb(128, 0, 128)'),
showarrow=False))
# labeling the bar net worth
annotations.append(dict(xref='x1', yref='y1',
y=xd, x=yd + 3,
text=str(yd) + '%',
font=dict(family='Arial', size=12,
color='rgb(50, 171, 96)'),
showarrow=False))
annotations.append(dict(xref='paper', yref='paper', x=-0.2, y=-0.109, text='OECD "' + '(2015), Household savings (indicator), ' + 'Household net worth (indicator). doi: ' + '10.1787/cfc6f499-en (Accessed on 05 June 2015)', font=dict(family='Arial', size=10, color='rgb(150,150,150)'), showarrow=False))
layout['annotations'] = annotations
fig = tools.make_subplots(rows=1, cols=2, specs=[[{}, {}]], shared_xaxes=True, shared_yaxes=False, vertical_spacing=0.001)
fig.append_trace(trace0, 1, 1) fig.append_trace(trace1, 1, 2)
fig['layout'].update(layout) py.iplot(fig, filename='oecd-networth-saving-bar-line')
- [X] https://plot.ly/python/table/#use-a-pandas-dataframe `BROKEN: values must be a list, not pd.Index`
import plotly.plotly as py import plotly.graph_objs as go
import pandas as pd
df = pd.read_csv('https://raw.githubusercontent.com/plotly/datasets/master/2014_usa_states.csv')
trace = go.Table( header=dict(values=list(df.columns), fill = dict(color='#C2D4FF'), align = ['left'] 5), cells=dict(values=[df.Rank, df.State, df.Postal, df.Population], fill = dict(color='#F5F8FF'), align = ['left'] 5))
data = [trace] py.iplot(data, filename = 'pandas_table')
- [X] https://plot.ly/python/table/#changing-row-and-column-size `BROKEN: type not a valid param`
import plotly.plotly as py import plotly.graph_objs as go
values = [[['Salaries', 'Office', 'Merchandise', 'Legal', 'TOTAL
EXPENSES']],
[["Lorem ipsum dolor sit amet, tollit discere inermis pri ut. Eos ea iusto timeam, an prima laboramus vim. Id usu aeterno adversarium, summo mollis timeam vel ad",
"Lorem ipsum dolor sit amet, tollit discere inermis pri ut. Eos ea iusto timeam, an prima laboramus vim. Id usu aeterno adversarium, summo mollis timeam vel ad",
"Lorem ipsum dolor sit amet, tollit discere inermis pri ut. Eos ea iusto timeam, an prima laboramus vim. Id usu aeterno adversarium, summo mollis timeam vel ad",
"Lorem ipsum dolor sit amet, tollit discere inermis pri ut. Eos ea iusto timeam, an prima laboramus vim. Id usu aeterno adversarium, summo mollis timeam vel ad",
"Lorem ipsum dolor sit amet, tollit discere inermis pri ut. Eos ea iusto timeam, an prima laboramus vim. Id usu aeterno adversarium, summo mollis timeam vel ad"]]]
trace0 = go.Table(
columnorder = [1,2],
columnwidth = [80,400],
header = dict(
values = [['EXPENSES
as of July 2017'],
['DESCRIPTION']],
line = dict(color = '#506784'),
fill = dict(color = '#119DFF'),
align = ['left','center'],
font = dict(color = 'white', size = 12),
height = 40
),
cells = dict(
values = values,
line = dict(color = '#506784'),
fill = dict(color = ['#25FEFD', 'white']),
align = ['left', 'center'],
font = dict(color = '#506784', size = 12),
height = 30
))
data = [trace0]
py.iplot(data, filename = "Row and Column Size")
- [X] https://plot.ly/python/table/#alternating-row-colors `BROKEN: type not allowed in go.Table`
import plotly.plotly as py import plotly.graph_objs as go
headerColor = 'grey' rowEvenColor = 'lightgrey' rowOddColor = 'white'
trace0 = go.Table( header = dict( values = [['EXPENSES'], ['Q1'], ['Q2'], ['Q3'], ['Q4']], line = dict(color = '#506784'), fill = dict(color = headerColor), align = ['left','center'], font = dict(color = 'white', size = 12) ), cells = dict( values = [ [['Salaries', 'Office', 'Merchandise', 'Legal', 'TOTAL']], [[1200000, 20000, 80000, 2000, 12120000]], [[1300000, 20000, 70000, 2000, 130902000]], [[1300000, 20000, 120000, 2000, 131222000]], [[1400000, 20000, 90000, 2000, 14102000]]], line = dict(color = '#506784'), fill = dict(color = [rowOddColor,rowEvenColor,rowOddColor, rowEvenColor,rowOddColor]), align = ['left', 'center'], font = dict(color = '#506784', size = 11) ))
data = [trace0]
py.iplot(data, filename = "alternating row colors")
- [X] https://plot.ly/python/table/#row-color-based-on-variable `BROKEN: multple colors for fill not supported`
- [X] https://plot.ly/python/table/#cell-color-based-on-variable `same as ^^^`
- [X] https://plot.ly/python/gauge-charts/ `BROKEN: remove autotick in layout`
- [X] https://plot.ly/python/linear-gauge-chart/#add-rating-data `BROKEN: y=[int] not y=int; mode=marker->markers`
ratings = [4.5, 5, 1, 2.75]
for i in range(len(ratings)): traces.append(go.Scatter( x=[0.5], y=[ratings[i]], xaxis='x'+str(i+1), yaxis='y'+str(i+1), mode='markers', marker={'size': 16, 'color': '#29ABD6'}, text=ratings[i], hoverinfo='text', showlegend=False ))
fig = dict(data=traces, layout=layout) py.iplot(fig, filename='linear-gauge')
# Statistical
- [X] https://plot.ly/python/error-bars/#colored-and-styled-error-bars `BROKEN: opacity not a valid keyword`
import plotly.plotly as py import plotly.graph_objs as go
import numpy as np
x_theo = np.linspace(-4, 4, 100) sincx = np.sinc(x_theo) x = [-3.8, -3.03, -1.91, -1.46, -0.89, -0.24, -0.0, 0.41, 0.89, 1.01, 1.91, 2.28, 2.79, 3.56] y = [-0.02, 0.04, -0.01, -0.27, 0.36, 0.75, 1.03, 0.65, 0.28, 0.02, -0.11, 0.16, 0.04, -0.15]
trace1 = go.Scatter( x=x_theo, y=sincx, name='sinc(x)' ) trace2 = go.Scatter( x=x, y=y, mode='markers', name='measured', error_y=dict( type='constant', value=0.1, color='#85144B', thickness=1.5, width=3, ), error_x=dict( type='constant', value=0.2, color='#85144B', thickness=1.5, width=3, ), marker=dict( color='#85144B', size=8 ) ) data = [trace1, trace2] py.iplot(data, filename='error-bar-style')
- [X] https://plot.ly/python/continuous-error-bars/#basic-continuous-error-bars `BROKEN: transparent is not a color`
import plotly.plotly as py import plotly.graph_objs as go
x = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] x_rev = x[::-1]
y1 = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] y1_upper = [2, 3, 4, 5, 6, 7, 8, 9, 10, 11] y1_lower = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] y1_lower = y1_lower[::-1]
y2 = [5, 2.5, 5, 7.5, 5, 2.5, 7.5, 4.5, 5.5, 5] y2_upper = [5.5, 3, 5.5, 8, 6, 3, 8, 5, 6, 5.5] y2_lower = [4.5, 2, 4.4, 7, 4, 2, 7, 4, 5, 4.75] y2_lower = y2_lower[::-1]
y3 = [10, 8, 6, 4, 2, 0, 2, 4, 2, 0] y3_upper = [11, 9, 7, 5, 3, 1, 3, 5, 3, 1] y3_lower = [9, 7, 5, 3, 1, -.5, 1, 3, 1, -1] y3_lower = y3_lower[::-1]
trace1 = go.Scatter( x=x+x_rev, y=y1_upper+y1_lower, fill='tozerox', fillcolor='rgba(0,100,80,0.2)', line=dict(color='rgba(255,255,255,0)'), showlegend=False, name='Fair', ) trace2 = go.Scatter( x=x+x_rev, y=y2_upper+y2_lower, fill='tozerox', fillcolor='rgba(0,176,246,0.2)', line=dict(color='rgba(255,255,255,0)'), name='Premium', showlegend=False, ) trace3 = go.Scatter( x=x+x_rev, y=y3_upper+y3_lower, fill='tozerox', fillcolor='rgba(231,107,243,0.2)', line=dict(color='rgba(255,255,255,0)'), showlegend=False, name='Fair', ) trace4 = go.Scatter( x=x, y=y1, line=dict(color='rgb(0,100,80)'), mode='lines', name='Fair', ) trace5 = go.Scatter( x=x, y=y2, line=dict(color='rgb(0,176,246)'), mode='lines', name='Premium', ) trace6 = go.Scatter( x=x, y=y3, line=dict(color='rgb(231,107,243)'), mode='lines', name='Ideal', )
data = [trace1, trace2, trace3, trace4, trace5, trace6]
layout = go.Layout( paper_bgcolor='rgb(255,255,255)', plot_bgcolor='rgb(229,229,229)', xaxis=dict( gridcolor='rgb(255,255,255)', range=[1,10], showgrid=True, showline=False, showticklabels=True, tickcolor='rgb(127,127,127)', ticks='outside', zeroline=False ), yaxis=dict( gridcolor='rgb(255,255,255)', showgrid=True, showline=False, showticklabels=True, tickcolor='rgb(127,127,127)', ticks='outside', zeroline=False ), ) fig = go.Figure(data=data, layout=layout) py.iplot(fig, filename= 'shaded_lines')
- [X] https://plot.ly/python/continuous-error-bars/#asymmetric-error-bars-with-a-constant-offset `BROKEN: '444' -> '#444' for color`
import plotly.plotly as py import plotly.graph_objs as go
import pandas as pd
df = pd.read_csv('https://raw.githubusercontent.com/plotly/datasets/master/wind_speed_laurel_nebraska.csv')
upper_bound = go.Scatter( name='Upper Bound', x=df['Time'], y=df['10 Min Sampled Avg']+df['10 Min Std Dev'], mode='lines', marker=dict(color="#444"), line=dict(width=0), fillcolor='rgba(68, 68, 68, 0.3)', fill='tonexty')
trace = go.Scatter( name='Measurement', x=df['Time'], y=df['10 Min Sampled Avg'], mode='lines', line=dict(color='rgb(31, 119, 180)'), fillcolor='rgba(68, 68, 68, 0.3)', fill='tonexty')
lower_bound = go.Scatter( name='Lower Bound', x=df['Time'], y=df['10 Min Sampled Avg']-df['10 Min Std Dev'], marker=dict(color="#444"), line=dict(width=0), mode='lines')
data = [lower_bound, trace, upper_bound]
layout = go.Layout(
yaxis=dict(title='Wind speed (m/s)'),
title='Continuous, variable value error bars.
Notice the hover text!',
showlegend = False)
fig = go.Figure(data=data, layout=layout) py.iplot(fig, filename='pandas-continuous-error-bars')
- [X] https://plot.ly/python/histograms/#styled-histogram `BROKEN: histnorm cannot be count; not identical to original chart`
import plotly.plotly as py import plotly.graph_objs as go
import numpy as np x0 = np.random.randn(500) x1 = np.random.randn(500)+1
trace1 = go.Histogram( x=x0, histnorm='percent', name='control', xbins=dict( start=-4.0, end=3.0, size=0.5 ), marker=dict( color='#FFD7E9', ), opacity=0.75 ) trace2 = go.Histogram( x=x1, name='experimental', xbins=dict( start=-3.0, end=4, size=0.5 ), marker=dict( color='#EB89B5' ), opacity=0.75 ) data = [trace1, trace2]
layout = go.Layout( title='Sampled Results', xaxis=dict( title='Value' ), yaxis=dict( title='Count' ), bargap=0.2, bargroupgap=0.1 ) fig = go.Figure(data=data, layout=layout) py.iplot(fig, filename='styled histogram')
- [X] https://plot.ly/python/2D-Histogram/#2d-histogram-overlaid-with-a-scatter-chart `BROKEN: colorscale should be YlGnBu not YlGnBu (L not I)`
import plotly.plotly as py import plotly.graph_objs as go
import numpy as np
x0 = np.random.randn(100)/5. + 0.5 # 5. enforces float division y0 = np.random.randn(100)/5. + 0.5 x1 = np.random.rand(50) y1 = np.random.rand(50) + 1.0
x = np.concatenate([x0, x1]) y = np.concatenate([y0, y1])
trace1 = go.Scatter( x=x0, y=y0, mode='markers', showlegend=False, marker=dict( symbol='x', opacity=0.7, color='white', size=8, line=dict(width=1), ) ) trace2 = go.Scatter( x=x1, y=y1, mode='markers', showlegend=False, marker=dict( symbol='circle', opacity=0.7, color='white', size=8, line=dict(width=1), ) ) trace3 = go.Histogram2d( x=x, y=y, colorscale='YlGnBu', zmax=10, nbinsx=14, nbinsy=14, zauto=False, )
layout = go.Layout( xaxis=dict( ticks='', showgrid=False, zeroline=False, nticks=20 ), yaxis=dict( ticks='', showgrid=False, zeroline=False, nticks=20 ), autosize=False, height=550, width=550, hovermode='closest',
) data = [trace1, trace2, trace3] fig = go.Figure(data=data, layout=layout)
py.iplot(fig)
- https://plot.ly/python/bullet-charts/#custom-kwargs `BROKEN: some of the values in figure are unicode. Solution for Python 2 is str(unicode_string) but Python 3 classifies unicode and str as unicode`
- [X] https://plot.ly/python/splom/ `BROKEN: change all grid_colors: #ffff -> #fff`
- https://plot.ly/python/tree-plots/ `BROKEN: broken before ipyplotly integration` (make its own issue if not already)
# Scientific
- https://plot.ly/python/annotated_heatmap/#annotated-heatmap-with-numpy `BROKEN: z cannot be a multidimensional array`
- https://plot.ly/python/quiver-plots/#quiver-plot-with-points `BROKEN: cannot append to data; must use .add_scatter`
import plotly.plotly as py import plotly.figure_factory as ff import plotly.graph_objs as go
import numpy as np
x,y = np.meshgrid(np.arange(-2, 2, .2), np.arange(-2, 2, .25)) z = x*np.exp(-x2 - y2) v, u = np.gradient(z, .2, .2)
fig = ff.create_quiver(x, y, u, v, scale=.25, arrow_scale=.4, name='quiver', line=dict(width=1))
fig.add_scatter(x=[-.7, .75], y=[0,0], mode='markers', marker=dict(size=12), name='points')
py.iplot(fig, filename='Quiver with Points')
- https://plot.ly/python/streamline-plots/#streamline-and-source-point-plot `BROKEN: same issue as above`
import plotly.plotly as py import plotly.figure_factory as ff import plotly.graph_objs as go
import numpy as np
N = 50 x_start, x_end = -2.0, 2.0 y_start, y_end = -1.0, 1.0 x = np.linspace(x_start, x_end, N) y = np.linspace(y_start, y_end, N) X, Y = np.meshgrid(x, y) source_strength = 5.0 x_source, y_source = -1.0, 0.0
u = (source_strength/(2np.pi) (X-x_source)/((X-x_source)2 + (Y-y_source)2)) v = (source_strength/(2np.pi) (Y-y_source)/((X-x_source)2 + (Y-y_source)2))
fig = ff.create_streamline(x, y, u, v, name='streamline')
fig.add_scatter(x=[x_source], y=[y_source], mode='markers', marker=go.Marker(size=14), name='source point')
py.iplot(fig, filename='streamline_source')
- https://plot.ly/python/network-graphs/ `BROKEN: multiple ways: colorscale name incorrect//cannot append to tuples`
import plotly.plotly as py import plotly.graph_objs as go
import networkx as nx
G=nx.random_geometric_graph(200,0.125) pos=nx.get_node_attributes(G,'pos')
dmin=1 ncenter=0 for n in pos: x,y=pos[n] d=(x-0.5)2+(y-0.5)2 if d<dmin: ncenter=n dmin=d
p=nx.single_source_shortest_path_length(G,ncenter)
edge_trace = go.Scatter( x=[], y=[], line=dict(width=0.5,color='#888'), hoverinfo='none', mode='lines')
for edge in G.edges(): x0, y0 = G.node[edge[0]]['pos'] x1, y1 = G.node[edge[1]]['pos'] edge_trace['x'] += (x0, x1, None) edge_trace['y'] += (y0, y1, None)
node_trace_x = [] node_trace_y = [] for node in G.nodes(): x, y = G.node[node]['pos'] node_trace_x.append(x) node_trace_y.append(y)
node_trace = go.Scatter( x=node_trace_x, y=node_trace_y, text=[], mode='markers', hoverinfo='text', marker=dict( showscale=True,
# 'Greys' | 'Greens' | 'Bluered' | 'Hot' | 'Picnic' | 'Portland' |
# Jet' | 'RdBu' | 'Blackbody' | 'Earth' | 'Electric' | 'YIOrRd' | 'YIGnBu'
colorscale='YlGnBu',
reversescale=True,
color=[],
size=10,
colorbar=dict(
thickness=15,
title='Node Connections',
xanchor='left',
titleside='right'
),
line=dict(width=2)))
node_trace_color = [] node_trace_text = [] for node, adjacencies in enumerate(G.adjacency_list()): node_trace_color.append(len(adjacencies)) node_info = '# of connections: '+str(len(adjacencies)) node_trace_text.append(node_info)
node_trace['marker']['color'] = node_trace_color node_trace['text'] = node_trace_text
fig = go.Figure(data=[edge_trace, node_trace],
layout=go.Layout(
title='
Network graph made with Python',
titlefont=dict(size=16),
showlegend=False,
hovermode='closest',
margin=dict(b=20,l=5,r=5,t=40),
annotations=[ dict(
text="Python code: https://plot.ly/ipython-notebooks/network-graphs/",
showarrow=False,
xref="paper", yref="paper",
x=0.005, y=-0.002 ) ],
xaxis=dict(showgrid=False, zeroline=False, showticklabels=False),
yaxis=dict(showgrid=False, zeroline=False, showticklabels=False)))
py.iplot(fig, filename='networkx')
- https://plot.ly/python/alpha-shapes/ `BROKEN: missing data-file.txt`
- https://plot.ly/python/filled-chord-diagram/ `BROKEN: multiple reasons, one of which is changing offline to online so chart shows in Jupyter - only last 2 cells of doc changed`
ribbon_info=[] shapes = [] for k in range(L):
sigma=idx_sort[k]
sigma_inv=invPerm(sigma)
for j in range(k, L):
if matrix[k][j]==0 and matrix[j][k]==0: continue
eta=idx_sort[j]
eta_inv=invPerm(eta)
l=ribbon_ends[k][sigma_inv[j]]
if j==k:
shapes.append(make_self_rel(l, 'rgb(175,175,175)' ,
ideo_colors[k], radius=radii_sribb[k]))
z=0.9*np.exp(1j*(l[0]+l[1])/2)
#the text below will be displayed when hovering the mouse over the ribbon
text=labels[k]+' commented on '+ '{:d}'.format(matrix[k][k])+' of '+ 'herself Fb posts',
ribbon_info.append(go.Scatter(x=[z.real],
y=[z.imag],
mode='markers',
marker=dict(size=0.5, color=ideo_colors[k]),
text=text,
hoverinfo='text'
)
)
else:
r=ribbon_ends[j][eta_inv[k]]
zi=0.9*np.exp(1j*(l[0]+l[1])/2)
zf=0.9*np.exp(1j*(r[0]+r[1])/2)
#texti and textf are the strings that will be displayed when hovering the mouse
#over the two ribbon ends
texti=labels[k]+' commented on '+ '{:d}'.format(matrix[k][j])+' of '+\
labels[j]+ ' Fb posts',
textf=labels[j]+' commented on '+ '{:d}'.format(matrix[j][k])+' of '+\
labels[k]+ ' Fb posts',
ribbon_info.append(go.Scatter(x=[zi.real],
y=[zi.imag],
mode='markers',
marker=dict(size=0.5, color=ribbon_color[k][j]),
text=texti,
hoverinfo='text'
)
),
ribbon_info.append(go.Scatter(x=[zf.real],
y=[zf.imag],
mode='markers',
marker=dict(size=0.5, color=ribbon_color[k][j]),
text=textf,
hoverinfo='text'
)
)
r=(r[1], r[0])#IMPORTANT!!! Reverse these arc ends because otherwise you get
# a twisted ribbon
#append the ribbon shape
shapes.append(make_ribbon(l, r, 'rgb(175,175,175)' , ribbon_color[k][j]))
ideograms=[]
for k in range(len(ideo_ends)):
z= make_ideogram_arc(1.1, ideo_ends[k])
zi=make_ideogram_arc(1.0, ideo_ends[k])
m=len(z)
n=len(zi)
ideograms.append(go.Scatter(x=z.real,
y=z.imag,
mode='lines',
line=dict(color=ideo_colors[k], shape='spline', width=0.25),
text=labels[k]+'
'+'{:d}'.format(row_sum[k]),
hoverinfo='text'
)
)
path='M '
for s in range(m):
path+=str(z.real[s])+', '+str(z.imag[s])+' L '
Zi=np.array(zi.tolist()[::-1])
for s in range(m):
path+=str(Zi.real[s])+', '+str(Zi.imag[s])+' L '
path+=str(z.real[0])+' ,'+str(z.imag[0])
shapes.append(make_ideo_shape(path,'rgb(150,150,150)' , ideo_colors[k]))
layout['shapes'] = shapes
data = go.Data(ideograms+ribbon_info)
fig = go.Figure(data=data, layout=layout)
py.iplot(fig, filename='chord-diagram-Fb')
- [X] https://plot.ly/python/carpet-contour/#add-multiple-traces `BROKEN: remove type = "carpet" from the Carpet graph object`
import plotly.graph_objs as go import plotly.plotly as py
import urllib, json
url = "https://raw.githubusercontent.com/bcdunbar/datasets/master/airfoil_data.json" response = urllib.urlopen(url) data = json.loads(response.read())
trace1 = go.Carpet( a = data[0]['a'], b = data[0]['b'], x = data[0]['x'], y = data[0]['y'], baxis = dict( startline = False, endline = False, showticklabels = "none", smoothing = 0, showgrid = False ), aaxis = dict( startlinewidth = 2, startline = True, showticklabels = "none", endline = True, showgrid = False, endlinewidth = 2, smoothing = 0 ) )
trace2 = go.Contourcarpet( z = data[1]['z'], autocolorscale = False, zmax = 1, name = "Pressure", colorscale = "Viridis", zmin = -8, colorbar = dict( y = 0, yanchor = "bottom", titleside = "right", len = 0.75, title = "Pressure coefficient, cp" ), contours = dict( start = -1, size = 0.025, end = 1.000, showlines = False ), line = dict( smoothing = 0 ), autocontour = False, zauto = False )
trace3 = go.Contourcarpet( z = data[2]['z'], opacity = 0.300, showlegend = True, name = "Streamlines", autocontour = True, ncontours = 50, contours = dict( coloring = "none" ), line = dict( color = "white", width = 1 ) )
trace4 = go.Contourcarpet(
z = data[3]['z'],
showlegend = True,
name = "Pressure
contours",
autocontour = False,
line = dict(
color = "rgba(0, 0, 0, 0.5)",
smoothing = 1
),
contours = dict(
size = 0.250,
start = -4,
coloring = "none",
end = 1.000,
showlines = True
)
)
trace5 = go.Scatter(
x = data[4]['x'],
y = data[4]['y'],
legendgroup = "g1",
name = "Surface
pressure",
mode = "lines",
hoverinfo = "skip",
line = dict(
color = "rgba(255, 0, 0, 0.5)",
width = 1,
shape = "spline",
smoothing = 1
),
fill = "toself",
fillcolor = "rgba(255, 0, 0, 0.2)"
)
trace6 = go.Scatter( x = data[5]['x'], y = data[5]['y'], showlegend = False, legendgroup = "g1", mode = "lines", hoverinfo = "skip", line = dict( color = "rgba(255, 0, 0, 0.3)", width = 1 ) )
trace7 = go.Scatter( x = data[6]['x'], y = data[6]['y'], showlegend = False, legendgroup = "g1", name = "cp", text = data[6]['text'], hoverinfo = "text", mode = "lines", line = dict( color = "rgba(255, 0, 0, 0.2)", width = 0 ) )
data = [trace1,trace2,trace3,trace4,trace5,trace6,trace7]
layout = go.Layout( yaxis = dict( zeroline = False, range = [-1.800,1.800], showgrid = False ), dragmode = "pan", height = 700, xaxis = dict( zeroline = False, scaleratio = 1, scaleanchor = 'y', range = [-3.800,3.800], showgrid = False ), title = "Flow over a Karman-Trefftz airfoil", hovermode = "closest", margin = dict( r = 60, b = 40, l = 40, t = 80 ), width = 900 )
fig = go.Figure(data=data,layout=layout) py.iplot(fig, filename = "contourcarpet/airfoil")
- https://plot.ly/python/polar-chart/ `BROKEN: polar2, polar3, etc are not allowed in layout`
# Financial
- no errors
# Maps
- see https://github.com/plotly/documentation/issues/945#issuecomment-396836952
- no errors
# 3D Charts
- [X] https://plot.ly/python/3d-line-plots/#3d-line-plot-of-brownian-motion
BROKEN: dates -> list(dates) and remove validate in iplot thing
- [X] https://plot.ly/python/3d-mesh/#mesh-tetrahedron `BROKEN: colorscale cannot have string numbers`
data = go.Data([ go.Mesh3d( x = [0, 1, 2, 0], y = [0, 0, 1, 2], z = [0, 2, 0, 1], colorbar = go.ColorBar( title='z' ), colorscale = [[0, 'rgb(255, 0, 0)'], [0.5, 'rgb(0, 255, 0)'], [1, 'rgb(0, 0, 255)']], intensity = [0, 0.33, 0.66, 1], i = [0, 0, 0, 1], j = [1, 2, 3, 2], k = [2, 3, 1, 3], name = 'y', showscale = True ) ]) layout = go.Layout( xaxis=go.XAxis( title='x' ), yaxis=go.YAxis( title='y' ) ) fig = go.Figure(data=data, layout=layout) py.iplot(fig, filename='3d-mesh-tetrahedron-python')
- [X] https://plot.ly/python/3d-mesh/#mesh-cube `same as above`
data = go.Data([ go.Mesh3d( x = [0, 0, 1, 1, 0, 0, 1, 1], y = [0, 1, 1, 0, 0, 1, 1, 0], z = [0, 0, 0, 0, 1, 1, 1, 1], colorbar = go.ColorBar( title='z' ), colorscale = [[0, 'rgb(255, 0, 255)'], [0.5, 'rgb(0, 255, 0)'], [1, 'rgb(0, 0, 255)']], intensity = [0, 0.142857142857143, 0.285714285714286, 0.428571428571429, 0.571428571428571, 0.714285714285714, 0.857142857142857, 1], i = [7, 0, 0, 0, 4, 4, 6, 6, 4, 0, 3, 2], j = [3, 4, 1, 2, 5, 6, 5, 2, 0, 1, 6, 3], k = [0, 7, 2, 3, 6, 7, 1, 1, 5, 5, 7, 6], name='y', showscale=True ) ]) layout = go.Layout( xaxis=go.XAxis( title='x' ), yaxis=go.YAxis( title='y' ) ) fig = go.Figure(data=data, layout=layout) py.iplot(fig, filename='3d-mesh-cube-python')
- [X] https://plot.ly/python/isosurfaces-with-marching-cubes/
/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/plotly/tools.py:1506: UserWarning:
plotly.tools.FigureFactory.create_trisurf is deprecated. Use plotly.figure_factory.create_trisurf
# Multiple Axes
- [X] https://plot.ly/python/subplots/#simple-subplot-with-annotations `BROKEN: 'bottom' is in valid. changed to 'bottom center'`
from plotly import tools import plotly.plotly as py import plotly.graph_objs as go
trace1 = go.Scatter( x=[1, 2, 3], y=[4, 5, 6], mode='markers+text', text=['Text A', 'Text B', 'Text C'], textposition='bottom center' ) trace2 = go.Scatter( x=[20, 30, 40], y=[50, 60, 70], mode='markers+text', text=['Text D', 'Text E', 'Text F'], textposition='bottom center' )
fig = tools.make_subplots(rows=1, cols=2)
fig.append_trace(trace1, 1, 1) fig.append_trace(trace2, 1, 2)
fig['layout'].update(height=600, width=800, title='i <3 annotations and subplots') py.iplot(fig, filename='simple-subplot-with-annotations')
- [X] https://plot.ly/python/3d-subplots/#3d-surface-subplots `BROKEN: correct incorrect spelling of colorscales`
import plotly.plotly as py import plotly.graph_objs as go from plotly import tools
import numpy as np
x = np.linspace(-5, 80, 10) y = np.linspace(-5, 60, 10) xGrid, yGrid = np.meshgrid(y, x) z = xGrid 3 + yGrid 3
scene = dict( xaxis=dict( gridcolor='rgb(255, 255, 255)', zerolinecolor='rgb(255, 255, 255)', showbackground=True, backgroundcolor='rgb(230, 230,230)' ), yaxis=dict( gridcolor='rgb(255, 255, 255)', zerolinecolor='rgb(255, 255, 255)', showbackground=True, backgroundcolor='rgb(230, 230,230)' ), zaxis=dict( gridcolor='rgb(255, 255, 255)', zerolinecolor='rgb(255, 255, 255)', showbackground=True, backgroundcolor='rgb(230, 230,230)' ) )
fig = tools.make_subplots(rows=2, cols=2, specs=[[{'is_3d': True}, {'is_3d': True}], [{'is_3d': True}, {'is_3d': True}]])
fig.append_trace(dict(type='surface', x=x, y=y, z=z, colorscale='Viridis', scene='scene1', showscale=False), 1, 1) fig.append_trace(dict(type='surface', x=x, y=y, z=z, colorscale='RdBu', scene='scene2', showscale=False), 1, 2) fig.append_trace(dict(type='surface', x=x, y=y, z=z, colorscale='YlOrRd', scene='scene3', showscale=False), 2, 1) fig.append_trace(dict(type='surface', x=x, y=y, z=z, colorscale='YlGnBu', scene='scene4', showscale=False), 2, 2)
fig['layout'].update(title='subplots with different colorscales', height=800, width=800) fig['layout']['scene1'].update(scene) fig['layout']['scene2'].update(scene) fig['layout']['scene3'].update(scene) fig['layout']['scene4'].update(scene)
py.iplot(fig, file_name='multiple_plots')
- https://plot.ly/python/figure-factory-subplots/ `BROKEN: all examples - AttributeError: 'tuple' object has no attribute 'extend'`
- https://plot.ly/python/table-subplots/#table-and-right-aligned-plots `BROKEN: UnicodeEncodeError: 'ascii' codec can't encode character u'\u20bf' in position 0: ordinal not in range(128)`
- https://plot.ly/python/table-subplots/#vertical-table-and-graph-subplot `BROKEN: same as above`
# transforms
- no errors
# add custom controls
- https://plot.ly/python/custom-buttons/#restyle-button `BROKEN: AttributeError: 'Layout' object has no attribute 'get' - check plotly.py at line 155`
- [X] https://plot.ly/python/custom-buttons/#update-button `BROKEN: make DateTimeIndex arrays into lists`
import plotly.plotly as py import plotly.graph_objs as go
from datetime import datetime import pandas_datareader.data as web
df = web.DataReader("aapl", 'yahoo', datetime(2015, 1, 1), datetime(2016, 7, 1))
trace_high = go.Scatter(x=list(df.index), y=list(df.High), name='High', line=dict(color='#33CFA5'))
trace_high_avg = go.Scatter(x=list(df.index), y=[df.High.mean()]*len(df.index), name='High Average', visible=False, line=dict(color='#33CFA5', dash='dash'))
trace_low = go.Scatter(x=list(df.index), y=list(df.Low), name='Low', line=dict(color='#F06A6A'))
trace_low_avg = go.Scatter(x=list(df.index), y=[df.Low.mean()]*len(df.index), name='Low Average', visible=False, line=dict(color='#F06A6A', dash='dash'))
data = [trace_high, trace_high_avg, trace_low, trace_low_avg]
high_annotations=[dict(x='2016-03-01',
y=df.High.mean(),
xref='x', yref='y',
text='High Average:
'+str(df.High.mean()),
ax=0, ay=-40),
dict(x=df.High.idxmax(),
y=df.High.max(),
xref='x', yref='y',
text='High Max:
'+str(df.High.max()),
ax=0, ay=-40)]
low_annotations=[dict(x='2015-05-01',
y=df.Low.mean(),
xref='x', yref='y',
text='Low Average:
'+str(df.Low.mean()),
ax=0, ay=40),
dict(x=df.High.idxmin(),
y=df.Low.min(),
xref='x', yref='y',
text='Low Min:
'+str(df.Low.min()),
ax=0, ay=40)]
updatemenus = list([
dict(type="buttons",
active=-1,
buttons=list([
dict(label = 'High',
method = 'update',
args = [{'visible': [True, True, False, False]},
{'title': 'Yahoo High',
'annotations': high_annotations}]),
dict(label = 'Low',
method = 'update',
args = [{'visible': [False, False, True, True]},
{'title': 'Yahoo Low',
'annotations': low_annotations}]),
dict(label = 'Both',
method = 'update',
args = [{'visible': [True, True, True, True]},
{'title': 'Yahoo',
'annotations': high_annotations+low_annotations}]),
dict(label = 'Reset',
method = 'update',
args = [{'visible': [True, False, True, False]},
{'title': 'Yahoo',
'annotations': []}])
]),
)
])
layout = dict(title='Yahoo', showlegend=False, updatemenus=updatemenus)
fig = dict(data=data, layout=layout) py.iplot(fig, filename='update_button')
- https://plot.ly/python/custom-buttons/#style-buttons `BROKEN: various small errors`
df_wind = pd.read_csv('https://plot.ly/~datasets/2805.csv')
df_known_capacity = df_wind[ df_wind['total_cpcy'] != -99999.000 ] df_sum = df_known_capacity.groupby('manufac')['total_cpcy'].sum().sort_values(ascending=False).to_frame()
df_farms = pd.read_csv('https://plot.ly/~jackp/17256.csv') df_farms.set_index('Wind Farm', inplace=True)
wind_farms=list([ dict( args=[ { 'mapbox.center.lat':38, 'mapbox.center.lon':-94, 'mapbox.zoom':3, 'annotations[0].text':'All US wind turbines (scroll to zoom)' } ], label='USA', method='relayout' ) ])
for farm, row in df_farms.iterrows():
desc = []
for col in df_farms.columns:
if col not in ['DegMinSec','Latitude','Longitude']:
if str(row[col]) not in ['None','nan','']:
desc.append( col + ': ' + str(row[col]).strip("'") )
desc.insert(0, farm)
wind_farms.append(
dict(
args=[ {
'mapbox.center.lat':row['Latitude'],
'mapbox.center.lon':float(str(row['Longitude']).strip("'")),
'mapbox.zoom':9,
'annotations[0].text': '
'.join(desc)
} ],
label=' '.join(farm.split(' ')[0:2]),
method='relayout'
)
)
data = [] for mfr in list(df_sum.index): if mfr != 'unknown': trace = dict( lat = df_wind[ df_wind['manufac'] == mfr ]['lat_DD'], lon = df_wind[ df_wind['manufac'] == mfr ]['long_DD'], name = mfr, marker = dict(size = 4), type = 'scattermapbox' ) data.append(trace)
mapbox_access_token = 'pk.eyJ1IjoiY2hlbHNlYXBsb3RseSIsImEiOiJjaXFqeXVzdDkwMHFrZnRtOGtlMGtwcGs4In0.SLidkdBMEap9POJGIe1eGw'
layout = dict( height = 800, margin = dict( t=0, b=0, l=0, r=0 ), font = dict( color='#FFFFFF', size=11 ), paper_bgcolor = '#000000', mapbox=dict( accesstoken=mapbox_access_token, bearing=0, center=dict( lat=38, lon=-94 ), pitch=0, zoom=3, style='dark' ), )
updatemenus=list([
dict(
buttons = wind_farms[0:6],
direction = 'left',
pad = {'r': 0, 't': 10},
type = 'buttons',
x = 0.1,
xanchor = 'left',
y = 1.0,
yanchor = 'top',
bgcolor = '#AAAAAA',
active = 99,
bordercolor = '#FFFFFF',
font = dict(size=11, color='#000000')
),
dict(
buttons = wind_farms[6:10],
direction = 'left',
pad = {'r': 0, 't': 10},
type = 'buttons',
x = 0.1,
xanchor = 'left',
y = 0.95,
yanchor = 'top',
bgcolor = '#AAAAAA',
active = 99,
bordercolor = '#FFFFFF',
font = dict(size=11, color='#000000')
),
dict(
buttons=list([
dict(
args=['mapbox.style', 'dark'],
label='Dark',
method='relayout'
),
dict(
args=['mapbox.style', 'light'],
label='Light',
method='relayout'
),
dict(
args=['mapbox.style', 'satellite'],
label='Satellite',
method='relayout'
),
dict(
args=['mapbox.style', 'satellite-streets'],
label='Satellite with Streets',
method='relayout'
)
]),
direction = 'up',
x = 0.75,
xanchor = 'left',
y = 0.05,
yanchor = 'bottom',
bgcolor = '#000000',
bordercolor = '#FFFFFF',
font = dict(size=11)
),
])
annotations = list([
dict(text='All US wind turbines (scroll to zoom)', font=dict(color='magenta',size=14), borderpad=10,
x=0.05, y=0.05, xref='paper', yref='paper', align='left', showarrow=False, bgcolor='black'),
dict(text='Wind
Farms', x=0.01, y=0.99, yref='paper', align='left', showarrow=False,font=dict(size=14))
])
layout['updatemenus'] = updatemenus layout['annotations'] = annotations
figure = dict(data=data, layout=layout) py.iplot(figure, filename='wind-turbine-territory')
- [X] https://plot.ly/python/sliders/#simple-slider-control `BROKEN: color='00CED1' -> color='#00CED1'`
import plotly.plotly as py import numpy as np
data = [dict( visible = False, line=dict(color='#00CED1', width=6), name = 'π = '+str(step), x = np.arange(0,10,0.01), y = np.sin(step*np.arange(0,10,0.01))) for step in np.arange(0,5,0.1)] data[10]['visible'] = True
py.iplot(data, filename='Single Sine Wave')
- https://plot.ly/python/dropdowns/#restyle-dropdown `BROKEN: AttributeError: 'Layout' object has no attribute 'get'`
- [X] https://plot.ly/python/dropdowns/#update-dropdown `BROKEN: made DateTimeIndex arrays into lists`
import plotly.plotly as py import plotly.graph_objs as go
from datetime import datetime import pandas_datareader as web
df = web.DataReader("aapl", 'yahoo', datetime(2015, 1, 1), datetime(2016, 7, 1))
trace_high = go.Scatter(x=list(df.index), y=list(df.High), name='High', line=dict(color='#33CFA5'))
trace_high_avg = go.Scatter(x=list(df.index), y=[df.High.mean()]*len(df.index), name='High Average', visible=False, line=dict(color='#33CFA5', dash='dash'))
trace_low = go.Scatter(x=list(df.index), y=list(df.Low), name='Low', line=dict(color='#F06A6A'))
trace_low_avg = go.Scatter(x=list(df.index), y=[df.Low.mean()]*len(df.index), name='Low Average', visible=False, line=dict(color='#F06A6A', dash='dash'))
data = [trace_high, trace_high_avg, trace_low, trace_low_avg]
high_annotations=[dict(x='2016-03-01',
y=df.High.mean(),
xref='x', yref='y',
text='High Average:
'+str(df.High.mean()),
ax=0, ay=-40),
dict(x=df.High.idxmax(),
y=df.High.max(),
xref='x', yref='y',
text='High Max:
'+str(df.High.max()),
ax=0, ay=-40)]
low_annotations=[dict(x='2015-05-01',
y=df.Low.mean(),
xref='x', yref='y',
text='Low Average:
'+str(df.Low.mean()),
ax=0, ay=40),
dict(x=df.High.idxmin(),
y=df.Low.min(),
xref='x', yref='y',
text='Low Min:
'+str(df.Low.min()),
ax=0, ay=40)]
updatemenus = list([
dict(active=-1,
buttons=list([
dict(label = 'High',
method = 'update',
args = [{'visible': [True, True, False, False]},
{'title': 'Yahoo High',
'annotations': high_annotations}]),
dict(label = 'Low',
method = 'update',
args = [{'visible': [False, False, True, True]},
{'title': 'Yahoo Low',
'annotations': low_annotations}]),
dict(label = 'Both',
method = 'update',
args = [{'visible': [True, True, True, True]},
{'title': 'Yahoo',
'annotations': high_annotations+low_annotations}]),
dict(label = 'Reset',
method = 'update',
args = [{'visible': [True, False, True, False]},
{'title': 'Yahoo',
'annotations': []}])
]),
)
])
layout = dict(title='Yahoo', showlegend=False, updatemenus=updatemenus)
fig = dict(data=data, layout=layout) py.iplot(fig, filename='update_dropdown')
- [X] https://plot.ly/python/dropdowns/#style-dropdown `BROKEN: similar issues as parallel example in style buttons sections`
df_wind = pd.read_csv('https://plot.ly/~datasets/2805.csv')
df_known_capacity = df_wind[ df_wind['total_cpcy'] != -99999.000 ] df_sum = df_known_capacity.groupby('manufac')['total_cpcy'].sum().sort_values(ascending=False).to_frame()
df_farms = pd.read_csv('https://plot.ly/~jackp/17256.csv') df_farms.set_index('Wind Farm', inplace=True)
wind_farms=list([ dict( args=[ { 'mapbox.center.lat':38, 'mapbox.center.lon':-94, 'mapbox.zoom':3, 'annotations[0].text':'All US wind turbines (scroll to zoom)' } ], label='USA', method='relayout' ) ])
for farm, row in df_farms.iterrows():
desc = []
for col in df_farms.columns:
if col not in ['DegMinSec','Latitude','Longitude']:
if str(row[col]) not in ['None','nan','']:
desc.append( col + ': ' + str(row[col]).strip("'") )
desc.insert(0, farm)
wind_farms.append(
dict(
args=[ {
'mapbox.center.lat':row['Latitude'],
'mapbox.center.lon':float(str(row['Longitude']).strip("'")),
'mapbox.zoom':9,
'annotations[0].text': '
'.join(desc)
} ],
label=' '.join(farm.split(' ')[0:2]),
method='relayout'
)
)
data = [] for mfr in list(df_sum.index): if mfr != 'unknown': trace = dict( lat = df_wind[ df_wind['manufac'] == mfr ]['lat_DD'], lon = df_wind[ df_wind['manufac'] == mfr ]['long_DD'], name = mfr, marker = dict(size = 4), type = 'scattermapbox' ) data.append(trace)
layout = dict( height = 800, margin = dict( t=0, b=0, l=0, r=0 ), font = dict( color='#FFFFFF', size=11 ), paper_bgcolor = '#000000', mapbox=dict( accesstoken=mapbox_access_token, bearing=0, center=dict( lat=38, lon=-94 ), pitch=0, zoom=3, style='dark' ), )
updatemenus=list([
dict(
buttons = wind_farms[0:10],
pad = {'r': 0, 't': 10},
x = 0.1,
xanchor = 'left',
y = 1.0,
yanchor = 'top',
bgcolor = '#AAAAAA',
active = 99,
bordercolor = '#FFFFFF',
font = dict(size=11, color='#000000')
),
dict(
buttons=list([
dict(
args=['mapbox.style', 'dark'],
label='Dark',
method='relayout'
),
dict(
args=['mapbox.style', 'light'],
label='Light',
method='relayout'
),
dict(
args=['mapbox.style', 'satellite'],
label='Satellite',
method='relayout'
),
dict(
args=['mapbox.style', 'satellite-streets'],
label='Satellite with Streets',
method='relayout'
)
]),
direction = 'up',
x = 0.75,
xanchor = 'left',
y = 0.05,
yanchor = 'bottom',
bgcolor = '#000000',
bordercolor = '#FFFFFF',
font = dict(size=11)
),
])
annotations = list([
dict(text='All US wind turbines (scroll to zoom)', font=dict(color='magenta',size=14), borderpad=10,
x=0.05, y=0.05, xref='paper', yref='paper', align='left', showarrow=False, bgcolor='black'),
dict(text='Wind
Farms', x=0.01, y=0.99, yref='paper', align='left', showarrow=False,font=dict(size=14))
])
layout['updatemenus'] = updatemenus layout['annotations'] = annotations
figure = dict(data=data, layout=layout) py.iplot(figure, filename='wind-turbine-territory-dropdown')
- [X] https://plot.ly/python/range-slider/#basic-range-slider-and-range-selectors `BROKEN: make DateTimeIndex arrays into lists`
import plotly.plotly as py import plotly.graph_objs as go
from datetime import datetime import pandas_datareader.data as web
df = web.DataReader("aapl", 'yahoo', datetime(2007, 10, 1), datetime(2009, 4, 1))
trace = go.Scatter(x=list(df.index), y=list(df.High))
data = [trace] layout = dict( title='Time series with range slider and selectors', xaxis=dict( rangeselector=dict( buttons=list([ dict(count=1, label='1m', step='month', stepmode='backward'), dict(count=6, label='6m', step='month', stepmode='backward'), dict(count=1, label='YTD', step='year', stepmode='todate'), dict(count=1, label='1y', step='year', stepmode='backward'), dict(step='all') ]) ), rangeslider=dict(), type='date' ) )
fig = dict(data=data, layout=layout) py.iplot(fig)
- https://plot.ly/python/range-slider/#range-slider-with-vertically-stacked-subplots `BROKEN: ValueError: The 'type' property of scatter is read-only`
# animations
- see https://github.com/plotly/documentation/issues/945#issuecomment-397066915
# style options
- [X] https://plot.ly/python/shapes/#highlighting-time-series-regions-with-rectangle-shapes `BROKEN: line should be lines for mode param`
import plotly.plotly as py import plotly.graph_objs as go
trace0 = go.Scatter( x=['2015-02-01', '2015-02-02', '2015-02-03', '2015-02-04', '2015-02-05', '2015-02-06', '2015-02-07', '2015-02-08', '2015-02-09', '2015-02-10', '2015-02-11', '2015-02-12', '2015-02-13', '2015-02-14', '2015-02-15', '2015-02-16', '2015-02-17', '2015-02-18', '2015-02-19', '2015-02-20', '2015-02-21', '2015-02-22', '2015-02-23', '2015-02-24', '2015-02-25', '2015-02-26', '2015-02-27', '2015-02-28'], y=[-14, -17, -8, -4, -7, -10, -12, -14, -12, -7, -11, -7, -18, -14, -14, -16, -13, -7, -8, -14, -8, -3, -9, -9, -4, -13, -9, -6], mode='lines', name='temperature' ) data = [trace0] layout = {
'shapes': [
# 1st highlight during Feb 4 - Feb 6
{
'type': 'rect',
# x-reference is assigned to the x-values
'xref': 'x',
# y-reference is assigned to the plot paper [0,1]
'yref': 'paper',
'x0': '2015-02-04',
'y0': 0,
'x1': '2015-02-06',
'y1': 1,
'fillcolor': '#d3d3d3',
'opacity': 0.2,
'line': {
'width': 0,
}
},
# 2nd highlight during Feb 20 - Feb 23
{
'type': 'rect',
'xref': 'x',
'yref': 'paper',
'x0': '2015-02-20',
'y0': 0,
'x1': '2015-02-22',
'y1': 1,
'fillcolor': '#d3d3d3',
'opacity': 0.2,
'line': {
'width': 0,
}
}
]
} py.iplot({'data': data, 'layout': layout}, filename='timestamp-highlight')
- [X] https://plot.ly/python/shapes/#venn-diagram-with-circle-shapes `BROKEN: removing autotick param as invalid`
import plotly.plotly as py import plotly.graph_objs as go
trace0 = go.Scatter( x=[1, 1.75, 2.5], y=[1, 1, 1], text=['$A$', '$A+B$', '$B$'], mode='text', textfont=dict( color='black', size=18, family='Arail', ) )
data = [trace0]
layout = { 'xaxis': { 'showticklabels': False, 'showgrid': False, 'zeroline': False, }, 'yaxis': { 'showticklabels': False, 'showgrid': False, 'zeroline': False, }, 'shapes': [ { 'opacity': 0.3, 'xref': 'x', 'yref': 'y', 'fillcolor': 'blue', 'x0': 0, 'y0': 0, 'x1': 2, 'y1': 2, 'type': 'circle', 'line': { 'color': 'blue', }, }, { 'opacity': 0.3, 'xref': 'x', 'yref': 'y', 'fillcolor': 'gray', 'x0': 1.5, 'y0': 0, 'x1': 3.5, 'y1': 2, 'type': 'circle', 'line': { 'color': 'gray', }, } ], 'margin': { 'l': 20, 'r': 20, 'b': 100 }, 'height': 600, 'width': 800, } fig = { 'data': data, 'layout': layout, } py.iplot(fig, filename='venn-diagram')
- [X] https://plot.ly/python/shapes/#svg-paths `BROKEN: typo -: changing 'color': 'rgb(93, 164, 214,)' to 'color': 'rgb(93, 164, 214)'`
import plotly.plotly as py import plotly.graph_objs as go
trace0 = go.Scatter( x=[2, 1, 8, 8], y=[0.25, 9, 2, 6], text=['Filled Triangle', 'Filled Polygon', 'Quadratic Bezier Curves', 'Cubic Bezier Curves'], mode='text', ) data = [trace0] layout = {
'xaxis': {
'range': [0, 9],
'zeroline': False,
},
'yaxis': {
'range': [0, 11],
'showgrid': False,
},
'shapes': [
# Quadratic Bezier Curves
{
'type': 'path',
'path': 'M 4,4 Q 6,0 8,4',
'line': {
'color': 'rgb(93, 164, 214)',
},
},
# Cubic Bezier Curves
{
'type': 'path',
'path': 'M 1,4 C 2,8 6,4 8,8',
'line': {
'color': 'rgb(207, 114, 255)',
},
},
# filled Triangle
{
'type': 'path',
'path': ' M 1 1 L 1 3 L 4 1 Z',
'fillcolor': 'rgba(44, 160, 101, 0.5)',
'line': {
'color': 'rgb(44, 160, 101)',
},
},
# filled Polygon
{
'type': 'path',
'path': ' M 3,7 L2,8 L2,9 L3,10, L4,10 L5,9 L5,8 L4,7 Z',
'fillcolor': 'rgba(255, 140, 184, 0.5)',
'line': {
'color': 'rgb(255, 140, 184)',
},
},
]
} fig = { 'data': data, 'layout': layout, } py.iplot(fig, filename='shapes-path')
- [X] https://plot.ly/python/text-and-annotations/#adding-text-to-data-in-line-and-scatter-plots `BROKEN: textposition values invalid: must be 'top center' not 'top'`
import plotly.plotly as py import plotly.graph_objs as go
trace1 = go.Scatter( x=[0, 1, 2], y=[1, 1, 1], mode='lines+markers+text', name='Lines, Markers and Text', text=['Text A', 'Text B', 'Text C'], textposition='top center' )
trace2 = go.Scatter( x=[0, 1, 2], y=[2, 2, 2], mode='markers+text', name='Markers and Text', text=['Text D', 'Text E', 'Text F'], textposition='bottom center' )
trace3 = go.Scatter( x=[0, 1, 2], y=[3, 3, 3], mode='lines+text', name='Lines and Text', text=['Text G', 'Text H', 'Text I'], textposition='bottom center' )
data = [trace1, trace2, trace3]
layout = go.Layout( showlegend=False )
fig = go.Figure(data=data, layout=layout) py.iplot(fig, filename='text-chart-basic')
- [X] https://plot.ly/python/text-and-annotations/#3d-annotations `BROKEN: type not allowed for go.Scatter3d`
import plotly.plotly as py import plotly.graph_objs as go
data = [go.Scatter3d( x = ["2017-01-01", "2017-02-10", "2017-03-20"], y = ["A", "B", "C"], z = [1, 1000, 100000], name = "z", )]
layout = go.Layout( scene = dict( aspectratio = dict( x = 1, y = 1, z = 1 ), camera = dict( center = dict( x = 0, y = 0, z = 0 ), eye = dict( x = 1.96903462608, y = -1.09022831971, z = 0.405345349304 ), up = dict( x = 0, y = 0, z = 1 ) ), dragmode = "turntable", xaxis = dict( title = "", type = "date" ), yaxis = dict( title = "", type = "category" ), zaxis = dict( title = "", type = "log" ), annotations = [dict( showarrow = False, x = "2017-01-01", y = "A", z = 0, text = "Point 1", xanchor = "left", xshift = 10, opacity = 0.7 ), dict( x = "2017-02-10", y = "B", z = 4, text = "Point 2", textangle = 0, ax = 0, ay = -75, font = dict( color = "black", size = 12 ), arrowcolor = "black", arrowsize = 3, arrowwidth = 1, arrowhead = 1 ), dict( x = "2017-03-20", y = "C", z = 5, ax = 50, ay = 0, text = "Point 3", arrowhead = 1, xanchor = "left", yanchor = "bottom" )] ), xaxis = dict(title = "x"), yaxis = dict(title = "y") )
fig = go.Figure(data=data, layout=layout) py.iplot(fig, filename = "3d annotations")
- [X] https://plot.ly/python/text-and-annotations/#custom-text-color-and-styling `BROKEN: bottom must be bottom center for textposition`
import plotly.plotly as py import plotly.graph_objs as go
trace1 = go.Scatter( x=[0, 1, 2], y=[1, 1, 1], mode='lines+markers+text', name='Lines, Markers and Text', text=['Text A', 'Text B', 'Text C'], textposition='top right', textfont=dict( family='sans serif', size=18, color='#1f77b4' ) )
trace2 = go.Scatter( x=[0, 1, 2], y=[2, 2, 2], mode='lines+markers+text', name='Lines and Text', text=['Text G', 'Text H', 'Text I'], textposition='bottom center', textfont=dict( family='sans serif', size=18, color='#ff7f0e' ) )
data = [trace1, trace2]
layout = go.Layout( showlegend=False )
fig = go.Figure(data=data, layout=layout) py.iplot(fig, filename='text-chart-styling')
- https://plot.ly/python/3d-surface-coloring/ `BROKEN: scene does not work`
See https://github.com/plotly/documentation/issues/958
- [X] https://plot.ly/python/logos/#formatting-and-positioning-images-as-logos
`1st Example` `BROKEN: removing go.Data() and autotick`
import plotly.plotly as py import plotly.graph_objs as go
data = [ go.Bar( x=['-35.3', '-15.9', '-15.8', '-15.6', '-11.1', '-9.6', '-9.2', '-3.5', '-1.9', '-0.9', '1.0', '1.4', '1.7', '2.0', '2.8', '6.2', '8.1', '8.5', '8.5', '8.6', '11.4', '12.5', '13.3', '13.7', '14.4', '17.5', '17.7', '18.9', '25.1', '28.9', '41.4'], y=['Designers, musicians, artists, etc.', 'Secretaries and administrative assistants', 'Waiters and servers', 'Archivists, curators, and librarians', 'Sales and related', 'Childcare workers, home car workers, etc.', 'Food preparation occupations', 'Janitors, maids, etc.', 'Healthcare technicians, assistants. and aides', 'Counselors, social and religious workers', 'Physical, life and social scientists', 'Construction', 'Factory assembly workers', 'Machinists, repairmen, etc.', 'Media and communications workers', 'Teachers', 'Mechanics, repairmen, etc.', 'Financial analysts and advisers', 'Farming, fishing and forestry workers', 'Truck drivers, heavy equipment operator, etc.','Accountants and auditors', 'Human resources, management analysts, etc.', 'Managers', 'Lawyers and judges', 'Engineers, architects and surveyors', 'Nurses', 'Legal support workers', 'Computer programmers and system admin.', 'Police officers and firefighters', 'Chief executives', 'Doctors, dentists and surgeons'], marker=dict( color='rgb(253, 240, 54)', line=dict(color='rgb(0, 0, 0)', width=2) ), orientation='h', ) ]
layout = go.Layout(
images=[dict(
source="https://raw.githubusercontent.com/cldougl/plot_images/add_r_img/vox.png",
xref="paper", yref="paper",
x=1, y=1.05,
sizex=0.2, sizey=0.2,
xanchor="right", yanchor="bottom"
)],
autosize=False, height=800, width=700,
bargap=0.15, bargroupgap=0.1,
barmode='stack', hovermode='x',
margin=dict(r=20, l=300,
b=75, t=125),
title='Moving Up, Moving Down
Percentile change in income between childhood and adulthood',
xaxis=dict(
dtick=10, nticks=0,
gridcolor='rgba(102, 102, 102, 0.4)',
linecolor='#000', linewidth=1,
mirror=True,
showticklabels=True, tick0=0, tickwidth=1,
title='Change in percentile',
),
yaxis=dict(
anchor='x',
gridcolor='rgba(102, 102, 102, 0.4)', gridwidth=1,
linecolor='#000', linewidth=1,
mirror=True, showgrid=False,
showline=True, zeroline=False,
showticklabels=True, tick0=0,
type='category',
)
)
fig = go.Figure(data=data, layout=layout)
py.iplot(fig)
- [X] `Example 2` `BROKEN: getting figure results in error since it contains invalid value to tickangle. Fixing by rewriting the raw grabbed figure. Long term solution needed.`
import plotly.plotly as py import plotly.graph_objs as go
fig = py.get_figure('https://plot.ly/~Dreamshot/8152/', raw=True) fig['layout']['yaxis']['tickangle'] = 0 fig = go.Figure(fig)
fig.layout.images = [dict( source="https://raw.githubusercontent.com/cldougl/plot_images/add_r_img/accuweather.jpeg", xref="paper", yref="paper", x=0.1, y=1.05, sizex=0.4, sizey=0.4, xanchor="center", yanchor="bottom" )]
py.iplot(fig, fileopt='overwrite', filename='Logos/Florida_Rainfall_AccuWeather')
- [X] `Example 3` `BROKEN: removing autobinx and autobiny as they are not allowed in go.Bar`
import plotly.plotly as py
import plotly.plotly as py import plotly.graph_objs as go
fig = py.get_figure('https://plot.ly/~Dreamshot/8160/', raw=True) for j in range(len(fig['data'])): del fig['data'][j]['autobinx'] del fig['data'][j]['autobiny'] fig = go.Figure(fig)
fig.layout.images = [dict( source="https://raw.githubusercontent.com/cldougl/plot_images/add_r_img/bleacherreport.png", xref="paper", yref="paper", x=0.5, y=-0.35, sizex=0.3, sizey=0.3, xanchor="center", yanchor="top" )]
py.iplot(fig, fileopt='overwrite', filename='Logos/Top_Earners_BleacherReport')
- [X] https://plot.ly/python/images/#add-a-logo `BROKEN: removing autotick param`
import plotly.plotly as py import plotly.graph_objs as go
data = [ go.Bar( x=['-35.3', '-15.9', '-15.8', '-15.6', '-11.1', '-9.6', '-9.2', '-3.5', '-1.9', '-0.9', '1.0', '1.4', '1.7', '2.0', '2.8', '6.2', '8.1', '8.5', '8.5', '8.6', '11.4', '12.5', '13.3', '13.7', '14.4', '17.5', '17.7', '18.9', '25.1', '28.9', '41.4'], y=['Designers, musicians, artists, etc.', 'Secretaries and administrative assistants', 'Waiters and servers', 'Archivists, curators, and librarians', 'Sales and related', 'Childcare workers, home car workers, etc.', 'Food preparation occupations', 'Janitors, maids, etc.', 'Healthcare technicians, assistants. and aides', 'Counselors, social and religious workers', 'Physical, life and social scientists', 'Construction', 'Factory assembly workers', 'Machinists, repairmen, etc.', 'Media and communications workers', 'Teachers', 'Mechanics, repairmen, etc.', 'Financial analysts and advisers', 'Farming, fishing and forestry workers', 'Truck drivers, heavy equipment operator, etc.','Accountants and auditors', 'Human resources, management analysts, etc.', 'Managers', 'Lawyers and judges', 'Engineers, architects and surveyors', 'Nurses', 'Legal support workers', 'Computer programmers and system admin.', 'Police officers and firefighters', 'Chief executives', 'Doctors, dentists and surgeons'], marker=dict( color='rgb(253, 240, 54)', line=dict(color='rgb(0, 0, 0)', width=2) ), orientation='h', ) ]
layout = go.Layout(
images=[dict(
source="https://raw.githubusercontent.com/cldougl/plot_images/add_r_img/vox.png",
xref="paper", yref="paper",
x=1, y=1.05,
sizex=0.2, sizey=0.2,
xanchor="right", yanchor="bottom"
)],
autosize=False, height=800, width=700,
bargap=0.15, bargroupgap=0.1,
barmode='stack', hovermode='x',
margin=dict(r=20, l=300,
b=75, t=125),
title='Moving Up, Moving Down
Percentile change in income between childhood and adulthood',
xaxis=dict(
dtick=10, nticks=0,
gridcolor='rgba(102, 102, 102, 0.4)',
linecolor='#000', linewidth=1,
mirror=True,
showticklabels=True, tick0=0, tickwidth=1,
title='Change in percentile',
),
yaxis=dict(
anchor='x',
gridcolor='rgba(102, 102, 102, 0.4)', gridwidth=1,
linecolor='#000', linewidth=1,
mirror=True, showgrid=False,
showline=True, zeroline=False,
showticklabels=True, tick0=0,
type='category',
)
)
fig = go.Figure(data=data, layout=layout)
py.iplot(fig)
# layout options
- [X] https://plot.ly/python/axes/#toggling-axes-lines-ticks-labels-and-autorange `BROKEN: autotick removal`
import plotly.plotly as py import plotly.graph_objs as go
trace1 = go.Scatter( x=[0, 1, 2, 3, 4, 5, 6, 7, 8], y=[8, 7, 6, 5, 4, 3, 2, 1, 0] ) trace2 = go.Scatter( x=[0, 1, 2, 3, 4, 5, 6, 7, 8], y=[0, 1, 2, 3, 4, 5, 6, 7, 8] ) data = [trace1, trace2] layout = go.Layout( xaxis=dict( autorange=True, showgrid=False, zeroline=False, showline=False, ticks='', showticklabels=False ), yaxis=dict( autorange=True, showgrid=False, zeroline=False, showline=False, ticks='', showticklabels=False ) ) fig = go.Figure(data=data, layout=layout) py.iplot(fig, filename='axes-booleans')
- [X] https://plot.ly/python/axes/#set-and-style-axes-title-labels-and-ticks `Invalid value of type '__builtin__.str' received for the 'showexponent'`
import plotly.plotly as py import plotly.graph_objs as go
trace1 = go.Scatter( x=[0, 1, 2, 3, 4, 5, 6, 7, 8], y=[8, 7, 6, 5, 4, 3, 2, 1, 0] ) trace2 = go.Scatter( x=[0, 1, 2, 3, 4, 5, 6, 7, 8], y=[0, 1, 2, 3, 4, 5, 6, 7, 8] ) data = [trace1, trace2] layout = go.Layout( xaxis=dict( title='AXIS TITLE', titlefont=dict( family='Arial, sans-serif', size=18, color='lightgrey' ), showticklabels=True, tickangle=45, tickfont=dict( family='Old Standard TT, serif', size=14, color='black' ), exponentformat='e', showexponent='all' ), yaxis=dict( title='AXIS TITLE', titlefont=dict( family='Arial, sans-serif', size=18, color='lightgrey' ), showticklabels=True, tickangle=45, tickfont=dict( family='Old Standard TT, serif', size=14, color='black' ), exponentformat='e', showexponent='all' ) ) fig = go.Figure(data=data, layout=layout) py.iplot(fig, filename='axes-labels')
- [X] https://plot.ly/python/axes/#subcategory-axes `Invalid property specified for object of type plotly.graph_objs.Box: 'type'`
import plotly.plotly as py import plotly.graph_objs as go
trace1 = go.Box( x = [2, 3, 1, 5], y = ["A", "A", "A", "A"], line = dict(color = 'gray'), name = "A", orientation = "h" )
trace2 = go.Box( x = [8, 3, 6, 5], y = ["B", "B", "B", "B"], line = dict(color = 'gray'), name = "B", orientation = "h" )
trace3 = go.Box( x = [2, 3, 2, 5], y = ["C", "C", "C", "C"], line = dict(color = 'gray'), name = "C", orientation = "h" )
trace4 = go.Box( x = [7.5, 3, 6, 4], y = ["D", "D", "D", "D"], line = dict(color = 'gray'), name = "D", orientation = "h" )
data = [trace1, trace2, trace3, trace4]
layout = go.Layout( annotations = [ dict( x = -0.0951769406393, y = 1.06972670892, showarrow = False, text = "Subgroup", xref = "paper", yref = "paper" ), dict( x = -0.235516552511, y = 1.07060587474, showarrow = False, text = "Group", xref = "paper", yref = "paper" ), dict( x = -0.235516552511, y = 0.922906017856, showarrow = False, text = "One", xref = "paper", yref = "paper" ), dict( x = -0.235516552511, y = 0.375, showarrow = False, text = "Two", xref = "paper", yref = "paper" ) ], height = 400, hovermode = "closest", legend = dict( x = 0.986145833333, y = 0.936263886049 ), margin = dict( r = 10, t = 25, b = 40, l = 110 ), shapes = [ dict( line = dict( color = "rgba(68, 68, 68, 0.5)", width = 1 ), type = "line", x0 = -0.3, x1 = 1.2, xref = "paper", y0 = 0.5, y1 = 0.5, yref = "paper" ), dict( line = dict( color = "rgba(68, 68, 68, 0.63)", width = 1 ), type = "line", x0 = -0.3, x1 = 1.2, xref = "paper", y0 = 1, y1 = 1, yref = "paper" ) ], showlegend = True, title = "", width = 600, xaxis = dict( domain = [0, 1] ), yaxis = dict( autorange = True, categoryorder = "category descending", domain = [0, 1], range = [-0.5, 3.5], showline = True, title = "", type = "category" ) )
fig = go.Figure(data=data, layout=layout) py.iplot(fig, filename = 'subcategory-axes')
# connecting to databases
# report generation
# add custom controls with JavaScript
- [X] https://plot.ly/python/slider-widget/ `BROKEN: invalid figure from retrieved fig using 'get_figure'`
Replace
graph = GraphWidget("https://plot.ly/~chriddyp/674") fig = py.get_figure("https://plot.ly/~chriddyp/674")
with
graph = GraphWidget("https://plot.ly/~jordanpeterson/889") fig = py.get_figure("https://plot.ly/~jordanpeterson/889")
- https://plot.ly/python/zoom-events/#binding-to-zoom-events `BROKEN: the chart at 'cufflinks/simple-bubble-chart' has an invalid attribute`
Invalid value of type 'builtin.str' received for the 'symbol' property of scatter.marker Received value: 'dot'`
- https://plot.ly/python/hover-events/ `BROKEN: Marker is not defined`
import plotly.plotly as py import plotly.graph_objs as go
data = [ go.Bar( x=['Bob Dylan', 'The Beatles', 'David Bowie', 'Randy Newman', 'The Rolling Stones', 'Madonna', 'Frank Sinatra', 'The Beach Boys', 'Marvin Gaye', 'Prince', 'The Kinks', 'Elvis Presley', 'Tom Waits', 'U2', 'The Clash', 'Johnny Cash', 'Kate Bush', 'The Supremes', 'The Smiths', 'Al Green', 'Pulp', 'Chuck Berry', 'Elvis Costello and the Attractions', 'Neil Young', 'Stevie Wonder', 'Ray Charles', 'The Pogues', 'Grace Jones', 'Bill Withers', 'The Who', 'Paul Simon', 'Roy Orbison', 'Arctic Monkeys', 'Bruce Springsteen', 'The Police', 'Rod Stewart', 'Steve Earle'], y=[24, 19, 9, 8, 8, 6, 6, 6, 6, 6, 6, 6, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4], name='Number of songs per artist', marker=go.bar.Marker( color='#2ca02c' ) ) ]
layout = go.Layout(
title="Number of songs listed in the Guardian's
Top 1,000 Songs to Hear Before You Die per artist with 4 or more songs",
font=dict(
family='Georgia, serif',
color='#635F5D'
),
plot_bgcolor='#EFECEA'
)
fig = go.Figure(data=data, layout=layout)
plot_url = py.plot(fig)
- https://plot.ly/python/click-events/ `BROKEN`: see https://github.com/plotly/documentation/issues/960
# Mathematics
- [X] https://plot.ly/python/numerical-differentiation/ `BROKEN: line must be lines`
x = np.linspace(0, 2*np.pi, 100) y = np.sin(x)
dy = np.zeros(y.shape,np.float) dy[0:-1] = np.diff(y)/np.diff(x) dy[-1] = (y[-1] - y[-2])/(x[-1] - x[-2])
trace1 = go.Scatter( x=x, y=y, mode='lines', name='sin(x)' )
trace2 = go.Scatter( x=x, y=dy, mode='lines', name='numerical derivative of sin(x)' )
trace_data = [trace1, trace2] py.iplot(trace_data, filename='numerical-differentiation')
# Statistics
# Peak Analysis
- [X] https://plot.ly/python/peak-integration/#area-under-one-peak `BROKEN: symbol=open-circle should be circle-open`
baseline_values = peakutils.baseline(time_series)
x = [j for j in range(len(time_series))] time_series = time_series.tolist() baseline_values = baseline_values.tolist()
rev_baseline_values = baseline_values[:11] rev_baseline_values.reverse() area_x = [0,1,2,3,4,5,6,7,8,9,10,11,10,9,8,7,6,5,4,3,2,1] area_y = time_series[:11] + rev_baseline_values
trace = go.Scatter( x=x, y=time_series, mode='lines', marker=dict( color='#B292EA', ), name='Original Plot' )
trace2 = go.Scatter( x=x, y=baseline_values, mode='markers', marker=dict( size=3, color='#EB55BF', symbol='circle-open' ), name='Bassline' )
trace3 = go.Scatter( x=area_x, y=area_y, mode='lines+markers', marker=dict( size=4, color='rgb(255,0,0)', ), name='1st Peak Outline' )
first_peak_x = [j for j in range(11)] area_under_first_peak = np.trapz(time_series[:11], first_peak_x) - np.trapz(baseline_values[:11], first_peak_x) area_under_first_peak
annotation = go.Annotation( x=80, y=1000, text='The peak integration for the first peak is approximately %s' % (area_under_first_peak), showarrow=False )
layout = go.Layout( annotations=[annotation] )
trace_data = [trace, trace2, trace3] fig = go.Figure(data=trace_data, layout=layout) py.iplot(fig, filename='milk-production-peak-integration')
- [X] https://plot.ly/python/baseline-subtraction/#baseline-subtraction `BROKEN: same as above`
baseline_values = peakutils.baseline(time_series)
trace = go.Scatter( x=[j for j in range(len(time_series))], y=time_series, mode='lines', marker=dict( color='#547C66', ), name='Original Plot' )
trace2 = go.Scatter( x=[j for j in range(len(time_series))], y=baseline_values, mode='markers', marker=dict( size=3, color='#EB55BF', symbol='circle-open' ), name='Baseline' )
data = [trace, trace2] py.iplot(data, filename='milk-production-plot-with-baseline')
- [X] https://plot.ly/python/baseline-detection/#plot-with-baseline `BROKEN: same as above`
baseline_values = peakutils.baseline(time_series)
trace = go.Scatter( x=[j for j in range(len(time_series))], y=time_series, mode='lines', marker=dict( color='#B292EA', ), name='Original Plot' )
trace2 = go.Scatter( x=[j for j in range(len(time_series))], y=baseline_values, mode='markers', marker=dict( size=3, color='#EB55BF', symbol='circle-open' ), name='Baseline' )
data = [trace, trace2] py.iplot(data, filename='milk-production-plot-with-baseline')
# Signal Analysis
The heatmap z
coordinate as multi-dimensional array should be fixed in https://github.com/plotly/plotly.py/pull/942/commits/ea6cb8544d4fa127468a73ae8340cc4de5568040
@kully I've removed the size/int issue from your list and updated the doc :) That's more of a typo in the example as that size attribute should only be a int (not a string): https://plot.ly/python/reference/#scatter-marker-size
@Kully I think it would be more helpful to fix the doc or create a new issue when it is broken due to general python 3 incompatibility or other sorts of typos and keep this log focused around issues due to the plotly.py3 release as noted in your first comment:
This is more of a to-do list//discussion for tackling the documentation that will need to be changed in the plotly.py docs for Jon's Ipyplotly PR plotly/plotly.py#942
I think it might get a little confusing having that general "broken" list above. I've also created an issue here for general Python 3 breaks: https://github.com/plotly/documentation/issues/948
Note: I only ran these with 3.0.0rc3
. Will rerun with 3.0.0rc5
then update above comment.
~Both have ValueError: Invalid value of type 'pandas.core.series.Series'
~
~AttributeError: 'NoneType' object has no attribute 'inf'
~
~AttributeError: 'Layout' object has no attribute 'get'
~
EDIT: errors resolved rc7+. https://github.com/plotly/documentation/issues/945#issuecomment-395769229 updated to reflect this. Also, go.FigureWidget(fig)
worked as expected.
Thanks for the reports @bcdunbar, I think all of these should be fixed when we push out an rc5 later this morning.
@Kully I haven't been able to exactly reproduce the DateTimeIndex
errors mentioned above because I get an error from pandas_datareader when I run web.DataReader
with the yahoo
data_source. If the index is a simple DateTImeIndex
(and not a MultiIndex
) then I think should also be working in rc5.
When you guys go back through with ~rc5~ rc6, could you also check that the plots render alright as FigureWidget
s?
Basically, whenever there is an iplot(fig)
command, could you display go.FigureWidget(fig)
and make sure it looks the same. I don't think we're ready to leave these in the documentation, but it would be helpful to flag any errors that crop up this way.
My expectation is that the figure as rendered by go.FigureWidget
should look identical to iplot
with the exception that the height may not be the same (which is fine). I also expect an informative error to be raised when a figure with frames
is passed to the go.FigureWidget
constructor.
Thanks!
I haven't been able to exactly reproduce the DateTimeIndex errors mentioned above because I get an error from pandas_datareader when I run web.DataReader with the yahoo data_source
Try changing the source to something else other than 'yahoo'. I believe that is broken as I came across that error a few months ago
animation with slider issue: this example: https://plot.ly/python/animations/#using-a-slider-and-buttons is not with version 3.0.0.rc9
I think it might get a little confusing having that general "broken" list above
ask discussed via our slack convo, and for further clarity for others, I will keep the issues in here that need to be changed before the release. So typo errors such as using open-circle
(wrong) instead of circle-open
(true) for example should be fixed before this release.
@cldougl Animation with slider issue should be fixed on the ipyplotly_integration
branch now (and in 3.0.0rc10).
Is there anything else you've found here that I should dig into?
@jmmease nothing else from me π
Shall we close this issue as Plotly 3 is released now?
This is more of a to-do list//discussion for tackling the documentation that will need to be changed in the plotly.py docs for Jon's Ipyplotly PR https://github.com/plotly/plotly.py/pull/942 Please comment with your suggestions/ideas:
I will be going through all the python docs and seeing if the code examples work or not (and taking note). Then for the failed examples we will:
What do y'all think of this? It would be awesome to have this finished before the end of next week for the presentation.
cc @jackparmer @chriddyp @jmmease @cldougl @bcdunbar
π΄ == tested with branch, not with
3.0.0rcX
Docs Reviewed:Additional Processes to Tested
py.sign_in()
Additional Environments Checked