def rolling_boxcar_graph_plotly(playerid, startdate, enddate, roll_len): # TODO this seems broken... kwargs = {'player': playerid, 'roll_len': roll_len, 'startdate': startdate, 'enddate': enddate} boxcars = vhelper.get_and_filter_5v5_log(**kwargs) boxcars = pd.concat([boxcars[['Season', 'Game']], rolling_boxcars.calculate_boxcar_rates(boxcars)], axis=1) col_dict = {col[col.index(' ') + 1:col.index('/')]: col for col in boxcars.columns if col[-3:] == '/60'} # Set an index boxcars.loc[:, 'Game Number'] = 1 boxcars.loc[:, 'Game Number'] = boxcars['Game Number'].cumsum() boxcars.set_index('Game Number', inplace=True) goals = go.Scatter(x=boxcars.index, y=boxcars[col_dict['iG']], fill='tozeroy', name='G', mode='none') primaries = go.Scatter(x=boxcars.index, y=boxcars[col_dict['iP1']], fill='tonexty', name='A1', mode='none') secondaries = go.Scatter(x=boxcars.index, y=boxcars[col_dict['iP']], fill='tonexty', name='A2', mode='none', opacity=0.5) gfon = go.Scatter(x=boxcars.index, y=boxcars[col_dict['GFON']], fill='tonexty', name='Other GFON', mode='none', opacity=0.3) title = rolling_boxcars._get_rolling_boxcars_title(**kwargs) fig = go.Figure(data=[goals, primaries, secondaries, gfon], layout=go.Layout(title=title, showlegend=True, legend=go.Legend(x=0, y=1.0), margin=go.Margin(l=40, r=0, t=40, b=30))) return fig
def callback_drug_reports_at_ages_bars(value): series = (data.query('drug_concept_name == @value').groupby( ['age_cat']).apply(lambda x: x.shape[0])) x = series.index.tolist() y = series.values y_norm = np.round((series.values / series.sum()) * 100, 0) drug_trace = go.Bar(x=x, y=y_norm, name='{}'.format(value), text=['{} reports'.format(i) for i in y], marker=go.Marker(color='rgb(55, 83, 109)')) all_trace = go.Bar( x=all_age_cat_counts_x, y=all_age_cat_counts_y_norm, name='All drugs', text=['{} reports'.format(i) for i in all_age_cat_counts_y], marker=go.Marker(color='rgb(180,180,180)')) return { 'data': [all_trace, drug_trace], 'layout': go.Layout(title='Patients taking {} at different age intervals'.format( value), showlegend=True, yaxis=dict(title="Percentage of reports", type='-'), xaxis=dict(title="Age category"), legend=go.Legend(x=0, y=1.0), margin=go.Margin(l=40, r=20, t=40, b=100)) }
def rolling_f_graph_plotly(playerid, startdate, enddate, roll_len, gfcf): kwargs = {'roll_len': roll_len, 'player': playerid, 'startdate': startdate, 'enddate': enddate} # Copy paste this code from rolling_f_graph fa = vhelper.get_and_filter_5v5_log(**kwargs) df = pd.concat([fa[['Season', 'Game']], rolling_cf_gf._calculate_f_rates(fa, gfcf)], axis=1) col_dict = {col[col.index(' ') + 1:]: col for col in df.columns if '%' in col} df.loc[:, 'Game Number'] = 1 df.loc[:, 'Game Number'] = df['Game Number'].cumsum() df.set_index('Game Number', inplace=True) label1 = gfcf + 'F%' label2 = gfcf + 'F% Off' title = rolling_cf_gf._get_rolling_f_title(gfcf, **kwargs) cfon_line = go.Scatter(x=df.index, y=df[col_dict[label1]], mode='lines', name=label1) cfoff_line = go.Scatter(x=df.index, y=df[col_dict[label2]], mode='lines', name=label2, line=dict(dash='dash')) fig = go.Figure(data=[cfon_line, cfoff_line], layout=go.Layout(title=title, showlegend=True, legend=go.Legend(x=0, y=1.0), margin=go.Margin(l=40, r=0, t=40, b=30))) #xaxis='Game', #yaxis=gfcf + 'F%')) return fig
def get_points(my_data, symbol, right, selected_date): has_marker = {'color': f'{has_color}', 'size': 5, 'symbol': 'square'} hasnt_marker = {'color': f'{hasnt_color}', 'size': 5, 'symbol': 'square'} trace = [ go.Candlestick( x=my_data.index, open=my_data.open, high=my_data.high, low=my_data.low, close=my_data.close, name='Daily Bars', ), go.Bar(x=my_data.index, y=my_data.volume, name='Daily Volume') ] return { 'data': trace, 'layout': go.Layout( title= f'Daily bars - {selected_date.strftime("%Y%M%d")} {symbol} {right} ', showlegend=True, legend=go.Legend(x=0, y=1.0), margin=go.Margin(l=100, r=40, t=40, b=30), ) }
def refresh_imports_by_date_graph(clicks, language, packages, start_date, end_date): if packages == None: return None package_data = dal.get_usage_by_import(language, packages, start_date, end_date) colors = gen_colors(len(packages)) def make_trace(df, package, rgb): x_date = df["commit_date"] y_package = df[package] return go.Trace(x=x_date, y=y_package, name=package, marker=go.Marker(color=rgb)) return go.Figure(data=[ make_trace(package_data, package, colors[i]) for i, package in enumerate(packages) ], layout=go.Layout( title="Daily Imports for {} to {}".format( convert_date(start_date), convert_date(end_date)), titlefont=title_font, showlegend=True, legend=go.Legend(x=0, y=1.0, font=annotation_font), margin=go.Margin(l=40, r=40, t=40, b=30)))
def update_graph_live(): webURL = urllib.request.urlopen("http://0.0.0.0:5000") response_data = webURL.read() encoding = webURL.info().get_content_charset('utf-8') data = json.loads(response_data.decode(encoding)) fig = go.Figure(data=[ go.Scatter( x=data['time'], y=data['x'], name='x-velocity', ), go.Scatter( x=data['time'], y=data['y'], name='y-velocity', ), go.Scatter( x=data['time'], y=data['z'], name='z-velocity', ), ], layout=go.Layout(title='', showlegend=True, legend=go.Legend(x=0, y=1.0), margin=go.Margin(l=40, r=0, t=40, b=30))) return fig
def generatePieChart(category): category_df = df[df[buildingCategory].isin([category])].head(10) labels = category_df['Facility'] trace = [ go.Pie(labels=labels, values=category_df[eui], marker=dict(colors=colorPalette, line=dict(color='#000000', width=1))), ] return html.Div([ dcc.Graph(figure={ 'data': trace, 'layout': go.Layout( title='Top 10 EUI for %s' % category, showlegend=True, legend=go.Legend(x=1, y=1, font=dict(size=8)), margin=go.Margin(l=0, r=0, t=60, b=0), ) }, id='pieChart') ], className='six columns')
def generate_spread_dist(val1, val2): print(val1 + " " + val2) CIXS = val1 + "_" + val2 print(CIXS) traces = [] df = generate_CIXS_df(CIXS) traces.append(go.Histogram( y = df.Spread, histnorm = 'probability', opacity = .65, name = CIXS )) return { 'data' : traces, 'layout' : go.Layout( title='Test', showlegend=True, barmode = "overlay", legend=go.Legend(x=0, y=1.0), margin=go.Margin( l=40, r=0, t=40, b=30 )) }
def update_map_view_graph(invitation, workshop1, workshop2, workshop3, spotlights_received, spotlights_placed, paint_received, paint_placed, cover_received, cover_placed): """ Updates the Map View graph. """ filter0 = df_monitoring['invitation'].isin(invitation) filter1 = df_monitoring['workshop1'].isin(workshop1) filter2 = df_monitoring['workshop2'].isin(workshop2) filter3 = df_monitoring['workshop3'].isin(workshop3) filter4 = df_monitoring['spotlights_received'].isin(spotlights_received) filter5 = df_monitoring['spotlights_placed'].isin(spotlights_placed) filter6 = df_monitoring['paint_received'].isin(paint_received) filter7 = df_monitoring['paint_placed'].isin(paint_placed) filter8 = df_monitoring['cover_received'].isin(cover_received) filter9 = df_monitoring['cover_placed'].isin(cover_placed) filter = filter0 & filter1 & filter2 & filter3 & filter4 & filter5 & filter6 & filter7 & filter8 & filter9 df = df_monitoring[filter] traces = [] traces.append( go.Scattermapbox( lat=df['lat'], lon=df['lon'], mode='markers', marker=go.Marker( # color=colors[i], size=8, opacity=0.7), text=df.index, # store ID #name=df.index, # store ID hoverinfo='text')) return { 'data': traces, 'layout': go.Layout(height=370, autosize=True, hovermode='closest', margin=dict(l=0, r=0, t=0, b=0), mapbox=dict(accesstoken=mapbox_access_token, bearing=0, center=dict(lat=19.380434, lon=-99.050932), pitch=0, zoom=11.4), legend=go.Legend(xanchor='right', x=1, bgcolor='white', bordercolor='#DEDEDE', borderwidth=1)) }
def get_layout(title='', ): title = title.replace('_', ' ') layout = graph_objs.Layout(title=title, showlegend=True, autosize=True, legend=graph_objs.Legend(xanchor='left', yanchor='top')) return layout
def func(): x = np.linspace(0, 20, 100) y = np.random.randn(100) # print(x.shape[0]) # print(y.shape[0]) #x test_1(x.shape[0],y.shape[0] app = dash.Dash() # print("hi") app.layout = html.Div( children=[ html.H1(children='Hello Dash'), dcc.Graph( figure=go.Figure( data=[go.Scatter(x=x, y=y, mode='lines', name='lines')], layout=go.Layout( title='Random line plot', showlegend=True, legend=go.Legend(x=0, y=1.0), # margin=go.Margin(l=40, r=0, t=40, b=30) )), style={'height': 300}, id='my-graph1'), dcc.Graph(figure=go.Figure( data=[ go.Pie( labels=[ "friends", "GOT", "HIMYM", "Breking bad", "House of cards", "Suits" ], values=[95, 98, 80, 97, 95, 93], name='Rest of world', ) ], layout=go.Layout(title='Tv series', showlegend=True, legend=go.Legend(x=0, y=1.0), margin=go.Margin(l=40, r=0, t=40, b=30))), style={'height': 300}, id='my-graph2') ]) # app.run_server(debug=True) return x.shape[0], y.shape[0], app
def update_figure(value): x = np.random.randn(value) y = np.random.randn(value) return go.Figure(data=[go.Scatter(x=x, y=y, name='test', mode='markers')], layout=go.Layout(title='Test Chart', showlegend=True, legend=go.Legend(x=0, y=1.0), margin=go.Margin(l=40, r=0, t=40, b=30)))
def select_chem(chem): return { 'data': [go.Bar(x=df['Object'], y=df[chem])], 'layout': [ go.Layout(title='{}'.format(chem), showlegend=True, legend=go.Legend(x=-0.5, y=1.0), margin=go.Margin(l=40, r=0, t=40, b=30)) ] }
def get_points(my_data, symbol, right): has_marker = {'color': f'{has_color}', 'size': 5, 'symbol': 'square'} hasnt_marker = {'color': f'{hasnt_color}', 'size': 5, 'symbol': 'square'} cant_marker = {'color': f'{cant_color}', 'size': 5, 'symbol': 'square'} no_timestamp_marker = { 'color': f'{no_timestamp_color}', 'size': 5, 'symbol': 'square' } has = my_data.query('has_bars == True') hasnt = my_data.query('cantGetDailyBars != True & has_bars != True') cant = my_data.query('cantGetDailyBars == True') no_timestamp = my_data.query('hasTimestamp != True') trace = [ go.Scatter(x=has.strike, y=has.lastTradeDateOrContractMonth, name='Has bars', marker=has_marker, mode='markers'), go.Scatter(x=hasnt.strike, y=hasnt.lastTradeDateOrContractMonth, name='Has no bars', marker=hasnt_marker, mode='markers'), go.Scatter(x=cant.strike, y=cant.lastTradeDateOrContractMonth, name='Can\'t get bars', marker=cant_marker, mode='markers'), go.Scatter(x=no_timestamp.strike, y=no_timestamp.lastTradeDateOrContractMonth, name='No timestamp', marker=no_timestamp_marker, mode='markers'), ] return { 'data': trace, 'layout': go.Layout(title=f'Daily bars by expiry date - {symbol} {right}', showlegend=True, legend=go.Legend(x=0, y=1.0), margin=go.Margin(l=100, r=40, t=40, b=30), yaxis={ "type": 'category', "title": 'Expiry Date', "autorange": True, "showticklabels": True, "automargin": True, "tickformat": "%d-%b-%y" }) }
def update_bars_figure(right, symbol, n_intervals, date, strike): fig = plotly.tools.make_subplots(rows=3, cols=1, specs=[[{ 'rowspan': 2 }], [{}], [{}]], vertical_spacing=0.01, shared_xaxes=True, shared_yaxes=True) layout = fig['layout'] my_data = get_data(right, symbol, date, strike) if isinstance(my_data, pd.DataFrame) and not my_data.empty: my_points = get_points(my_data, symbol, right, dt.strptime(date.split(" ")[0], '%Y-%M-%d'), strike) date_string = dt.strptime(date.split(" ")[0], '%Y-%M-%d').strftime("%Y%M%d") layout[ 'title'] = f'Daily bars - {date_string} {symbol} {strike} {right} ' layout['showlegend'] = True layout['legend'] = go.Legend(x=0, y=1.0) layout['margin'] = go.Margin(l=100, r=40, t=40, b=30) layout['yaxis1']['title'] = 'Price' layout['yaxis1']['autorange'] = True layout['yaxis1']['showticklabels'] = True layout['yaxis1']['automargin'] = True layout['yaxis1']['hoverformat'] = '$,2f' layout['yaxis1']['tickformat'] = '$,2f' layout['yaxis1']['fixedrange'] = True layout['yaxis3']['title'] = 'Volume' layout['yaxis3']['autorange'] = True layout['yaxis3']['showticklabels'] = True fig['layout'] = layout fig.append_trace(my_points['data'][0], 1, 1) fig.append_trace(my_points['data'][1], 3, 1) else: layout['annotations'] = [ dict(xref='paper', x=0.05, y=0, xanchor='middle', yanchor='middle', text='No data found for given parameters', font=dict(family='Arial', size=40), showarrow=False) ] return fig
def display_graphs(selected_values): graphs = [] graphs.append( dcc.Graph( figure=go.Figure( data=[go.Scatter(x=x, y=y, mode='lines', name='lines')], layout=go.Layout( title='Random line plot', showlegend=True, legend=go.Legend(x=0, y=1.0), # margin=go.Margin(l=40, r=0, t=40, b=30) )), style={'height': 300}, id='my-graph1')) graphs.append( dcc.Graph(figure=go.Figure(data=[ go.Pie( labels=[ "friends", "GOT", "HIMYM", "Breking bad", "House of cards", "Suits" ], values=[95, 98, 80, 97, 95, 93], name='Rest of world', ) ], layout=go.Layout( title='Tv series', showlegend=True, legend=go.Legend(x=0, y=1.0), margin=go.Margin(l=40, r=0, t=40, b=30))), style={'height': 300}, id='my-graph2')) if selected_values == "L": return graphs[0] else: return graphs[1]
def get_points(my_data, symbol, right): has_marker = {'color': f'{has_color}', 'size': 5, 'symbol': 'square'} hasnt_marker = {'color': f'{hasnt_color}', 'size': 5, 'symbol': 'square'} cant_marker = {'color': f'{cant_color}', 'size': 5, 'symbol': 'square'} my_data['marker'] = np.select([ my_data.hasTimestamp == True, (my_data.cantGetFirstTimestamp != True) & (my_data.hasTimestamp != True), my_data.cantGetFirstTimestamp == True ], [has_marker, hasnt_marker, cant_marker], np.nan) has = my_data.query('hasTimestamp == True') hasnt = my_data.query( 'cantGetFirstTimestamp != True & hasTimestamp != True') cant = my_data.query('cantGetFirstTimestamp == True') trace = [ go.Scatter(x=has.strike, y=has.lastTradeDateOrContractMonth, name='Has', marker=has_marker, mode='markers'), go.Scatter(x=hasnt.strike, y=hasnt.lastTradeDateOrContractMonth, name='Hasn\'t', marker=hasnt_marker, mode='markers'), go.Scatter(x=cant.strike, y=cant.lastTradeDateOrContractMonth, name='Can\'t', marker=cant_marker, mode='markers'), ] return { 'data': trace, 'layout': go.Layout(title=f'Timestamps by expiry date - {symbol} {right}', showlegend=True, legend=go.Legend(x=0, y=1.0), margin=go.Margin(l=100, r=40, t=40, b=30), yaxis={ "type": 'category', "title": 'Expiry Date', "autorange": True, "showticklabels": True, "automargin": True, "tickformat": "%d-%b-%y" }) }
def update_graph(selected_event_1, selected_node_1, selected_event_2, selected_node_2, rafts_file_1, events_file_1): data = [] max_time, max_flow = np.timedelta64(0, 'm'), 0 if rafts_file_1 is not None: rafts_data = get_from_redis('rafts_data') event_times = get_from_redis('event_times') if events_file_1 is not None: events = get_from_redis('events') if rafts_file_1 and events_file_1: if selected_event_1 and selected_node_1: data, max_time, max_flow = generate_chart_data( selected_event_1, selected_node_1, events, rafts_data, event_times, data, max_time, max_flow) if selected_event_2 and selected_node_2: data, max_time, max_flow = generate_chart_data( selected_event_2, selected_node_2, events, rafts_data, event_times, data, max_time, max_flow) return { 'data': data, 'layout': go.Layout( xaxis=dict( range=[0,max_time/np.timedelta64(1, 'm')], title='Time (minutes)', # domain=[0,1], position=0 ), yaxis=dict( range=[0,max_flow*1.1], title='Discharge (m3/s)', # domain=[0.0,1] ), legend=go.Legend( orientation='h' # x=0.5, y=0.9 ), margin={'l':65, 'b': 40, 't': 10, 'r': 0}, # height=600 ) } else: return {}
def generate_graph(secList): print(secList) return { 'data': go.Scatter(x=table.date, y=table['PX_LAST'], name='ACGB2', line=dict(color='#17BECF'), opacity=.8), 'layout': go.Layout(title='Test', showlegend=True, legend=go.Legend(x=0, y=1.0), margin=go.Margin(l=40, r=0, t=40, b=30)) }
def refresh_joint_graph(viz_joint): std = np.sqrt(J_PRED_VAR) upper_bound_pred = go.Scatter( name="mean + 3std", x=TIME, y=J_PRED_DATA[:, viz_joint] + 3 * std, mode="lines", marker=dict(color="444"), line=dict(width=0), fillcolor="rgba(68, 68, 68, 0.3)", fill="tonexty", ) pred_mean = go.Scatter( name="mean prediction", x=TIME, y=J_PRED_DATA[:, viz_joint], mode="lines", line=dict(color="rgb(31, 119, 180)"), fillcolor="rgba(68, 68, 68, 0.3)", fill="tonexty", ) lower_bound_pred = go.Scatter( name="mean - 3std", x=TIME, y=J_PRED_DATA[:, viz_joint] - 3 * std, marker=dict(color="444"), line=dict(width=0), mode="lines", ) real_state = go.Scatter(x=TIME, y=J_REAL_DATA[viz_joint], mode="lines", name="Real") return go.Figure( data=[upper_bound_pred, pred_mean, lower_bound_pred, real_state], layout=go.Layout( legend=go.Legend(x=0, y=1.0), margin=go.Margin(l=30, r=30, t=50, b=30), xaxis=dict(range=[0, 30]), yaxis=dict(range=[-200, 200]), ), )
def get_heat(my_data, symbol, right): has_marker = {'color': f'{has_color}', 'size': 5, 'symbol': 'square'} hasnt_marker = {'color': f'{hasnt_color}', 'size': 5, 'symbol': 'square'} cant_marker = {'color': f'{cant_color}', 'size': 5, 'symbol': 'square'} my_data['z'] = np.select([ my_data.hasTimestamp == True, (my_data.cantGetFirstTimestamp != True) & (my_data.hasTimestamp != True), my_data.cantGetFirstTimestamp == True ], [0, 0.5, 1], np.nan) has = my_data.query('hasTimestamp == True') hasnt = my_data.query( 'cantGetFirstTimestamp != True & hasTimestamp != True') cant = my_data.query('cantGetFirstTimestamp == True') trace = [ go.Heatmap(x=my_data.strike, y=my_data.lastTradeDateOrContractMonth, z=my_data.z, colorscale=[[0, has_color], [0.5, hasnt_color], [1, cant_color]], zauto=False, zmax=1, zmin=0) ] return { 'data': trace, 'layout': go.Layout( title=f'Timestamps by expiry date - {symbol} {right}', showlegend=True, legend=go.Legend(x=0, y=1.0), margin=go.Margin(l=100, r=40, t=40, b=30), yaxis={ "type": 'category', "title": 'Expiry Date', "autorange": True, "showticklabels": True, "automargin": True, "tickformat": "%d-%b-%y" }, ) }
def get_points(my_data, symbol, right, selected_date): has_marker = {'color': f'{has_color}', 'size': 5, 'symbol': 'square'} hasnt_marker = {'color': f'{hasnt_color}', 'size': 5, 'symbol': 'square'} has = my_data.query('has_bars == True') hasnt = my_data.query('has_bars != True') trace = [ go.Scatter(x=has.date, y=has.strike, name='Has bars', marker=has_marker, mode='markers'), go.Scatter(x=hasnt.date, y=hasnt.strike, name='Has no bars', marker=hasnt_marker, mode='markers'), ] return { 'data': trace, 'layout': go.Layout( title= f'Daily bars - {selected_date.strftime("%Y%M%d")} {symbol} {right} ', showlegend=True, legend=go.Legend(x=0, y=1.0), margin=go.Margin(l=100, r=40, t=40, b=30), xaxis={ "title": 'Date', "autorange": True, "showticklabels": True, "automargin": True, "tickformat": "%d-%b-%y" }, yaxis={ "title": 'Strike', "autorange": True, "showticklabels": True, "automargin": True, }) }
def get_timestamp_bars(my_data, selected_date): trace = [ go.Bar( x=my_data.query('hasTimestamp == True')['symbol'], y=my_data.query('hasTimestamp == True')['count'], name='Has Timestamp', marker=go.Marker(color=has_color), # , line=dict(color='rgb(0, 0, 0)',width=1) ), go.Bar( x=my_data.query( 'cantGetFirstTimestamp != True & hasTimestamp != True') ['symbol'], y=my_data.query( 'cantGetFirstTimestamp != True & hasTimestamp != True') ['count'], name='No Timestamp', marker=go.Marker(color=hasnt_color), ), go.Bar( x=my_data.query('cantGetFirstTimestamp == True')['symbol'], y=my_data.query('cantGetFirstTimestamp == True')['count'], name='Can\'t Get Timestamp', marker=go.Marker(color=cant_color), ), ] return { 'data': trace, 'layout': go.Layout( title= f'Timestamps by symbol - {selected_date.strftime("%d %b %Y")}', showlegend=False, legend=go.Legend(x=0, y=1.0), margin=go.Margin(l=40, r=40, t=40, b=30), barmode='relative', barnorm='percent') }
def get_daily_bar_bars(my_data, selected_date): trace = [ go.Bar( x=my_data.query('no_bars != True')['symbol'], y=my_data.query('no_bars != True')['count'], name='Has Bars', marker=go.Marker(color=has_color), ), go.Bar( x=my_data.query( 'no_bars == True & cantGetDailyBars != True')['symbol'], y=my_data.query('no_bars == True & cantGetDailyBars != True') ['count'], name='No Bars', marker=go.Marker(color=hasnt_color), ), go.Bar( x=my_data.query( 'no_bars == True & cantGetDailyBars == True')['symbol'], y=my_data.query('no_bars == True & cantGetDailyBars == True') ['count'], name='Can\'t Get Bars', marker=go.Marker(color=cant_color), ), ] return { 'data': trace, 'layout': go.Layout( title= f'Daily bars by symbol and date - {selected_date.strftime("%d %b %Y")}', showlegend=False, legend=go.Legend(x=0, y=1.0), margin=go.Margin(l=40, r=40, t=40, b=30), barmode='relative', barnorm='percent') }
def refresh_language_share_pie(clicks, date): language_totals = dal.get_language_totals(date) figure = go.Figure( data=[ go.Pie( type="pie", labels=language_totals["language_name"], values=language_totals["total_daily_usage"], name="Imports by Language", hole=0.5, # domain = {"x": [.3, 1]}, rotation=-135) ], layout=go.Layout(title="Imports by Language for {}".format( convert_date(date)), titlefont=title_font, font=annotation_font, legend=go.Legend(x=0, y=1.0, font={"size": 12}, orientation="v"))) return figure
def get_bars(my_data): trace = [ go.Bar( x=my_data.query('cantGetFirstTimestamp != True & hasTimestamp != True')[ 'expiryDate'], y=my_data.query('cantGetFirstTimestamp != True & hasTimestamp != True')['count'], name='No Timestamp', marker=go.Marker(color=hasnt_color), ), go.Bar( x=my_data.query('hasTimestamp == True')[ 'expiryDate'], y=my_data.query('hasTimestamp == True')['count'], name='Has Timestamp', marker=go.Marker(color=has_color), ), go.Bar( x=my_data.query('cantGetFirstTimestamp == True')['expiryDate'], y=my_data.query('cantGetFirstTimestamp == True')['count'], name='Can\'t Get Timestamp', marker=go.Marker(color=cant_color), ), ] return { 'data': trace, 'layout': go.Layout( title='Count of timestamps by expiry date', showlegend=True, legend=go.Legend( x=0, y=1.0 ), margin=go.Margin(l=40, r=40, t=40, b=30), barmode='group' ) }
def update_all_graph(metric, interval, sheet): try: df = db[sheet] # Split by dwarf dwarfs = df.dwarf.unique() data = [] for dwarf in dwarfs: dwarf_metric = df[df.dwarf == dwarf] data.append( go.Scatter(x=dwarf_metric.tick, y=dwarf_metric[metric], name=dwarf, marker=go.Marker(color='rgb(55, 83, 109)'))) return go.Figure(data=data, layout=go.Layout(title=metric, showlegend=True, legend=go.Legend(x=0, y=1.0), margin=go.Margin(l=40, r=0, t=40, b=30))) except: return None
def generate_yield_dist(val1): traces = [] df = generate_Sec_df(val1) traces.append(go.Histogram( y = df.PX_LAST, histnorm = 'probability', opacity = .65, name = val1 )) return { 'data' : traces, 'layout' : go.Layout( title='Test', showlegend=True, barmode = "overlay", legend=go.Legend(x=0, y=1.0), margin=go.Margin( l=40, r=0, t=40, b=30 )) }
def get_bars(my_data): trace = [ go.Bar( x=my_data.query('no_bars != True')['expiryDate'], y=my_data.query('no_bars != True')['count'], name='Has Bars', marker=go.Marker(color=has_color), ), go.Bar( x=my_data.query( 'no_bars == True & cantGetDailyBars != True')['expiryDate'], y=my_data.query('no_bars == True & cantGetDailyBars != True') ['count'], name='No Bars', marker=go.Marker(color=hasnt_color), ), go.Bar( x=my_data.query( 'no_bars == True & cantGetDailyBars == True')['expiryDate'], y=my_data.query('no_bars == True & cantGetDailyBars == True') ['count'], name='Can\'t Get Bars', marker=go.Marker(color=cant_color), ), ] return { 'data': trace, 'layout': go.Layout(title='Daily bars by expiry date', showlegend=True, legend=go.Legend(x=0, y=1.0), margin=go.Margin(l=40, r=40, t=40, b=30), barmode='group') }
def generate_spread_hist(val1, val2): print(val1 + " " + val2) CIXS = val1 + "_" + val2 print(CIXS) traces = [] df = generate_CIXS_df(CIXS) traces.append(go.Scatter( x = df.date, y = df.Spread, name = CIXS )) return { 'data' : traces, 'layout' : go.Layout( title='Test', showlegend=True, legend=go.Legend(x=0, y=1.0), margin=go.Margin( l=40, r=0, t=40, b=30 )) }