def devuelve_figura_con_kpis(confirmados, fallecidos, recuperados): figura_aux = go.Figure() figura_aux.add_trace(go.Indicator( mode = "number", value = confirmados, number={"font":{"size":50, "color":'orange'}}, domain = {'row': 1, 'column': 0}, title = {"text": "Confirmados", "font":{"size":TAMANIO_LETRA_KPIS}})) figura_aux.add_trace(go.Indicator( mode = "number", value = fallecidos, number={"font":{"size":50, "color":'red'}}, domain = {'row': 1, 'column': 1}, title = {"text": "Fallecidos", "font":{"size":TAMANIO_LETRA_KPIS}})) figura_aux.add_trace(go.Indicator( mode = "number", value = recuperados, number={"font":{"size":50, "color":'green'}}, domain = {'row': 1, 'column': 2}, title = {"text": "Recuperados", "font":{"size":TAMANIO_LETRA_KPIS}})) figura_aux.add_trace(go.Indicator( mode = "number", value = recuperados/(recuperados+fallecidos), number={"font":{"size":50, "color":'black'}}, domain = {'row': 1, 'column': 3}, title = {"text": "Tasa de recuperación", "font":{"size":TAMANIO_LETRA_KPIS}})) figura_aux.update_layout( grid = {'rows': 1, 'columns': 4, 'pattern': "independent"}, height=100) return figura_aux
def display_master_data(input_data): master_data = {} dff = covid_data.groupby("ObservationDate").agg( {"Confirmed": "sum", "Deaths": "sum", "Recovered": "sum"}).reset_index() master_data["Confirmed"] = dff.iloc[-1, 1].astype(int) master_data["Deaths"] = dff.iloc[-1, 2].astype(int) master_data["Recovered"] = dff.iloc[-1, 3].astype(int) fig = go.Figure() fig.add_trace(go.Indicator( mode="number+delta", value=master_data["Confirmed"], title={ "text": "Confirmed"}, domain={'x': [0, 0.2], 'y': [0, 1]}, delta={'reference': int(dff.iloc[-2, 1]), 'relative': True, })) fig.add_trace(go.Indicator( mode="number+delta", value=master_data["Deaths"], title={ "text": "Deaths"}, delta={'reference': int(dff.iloc[-2, 2]), 'relative': True}, domain={'x': [0.4, 0.6], 'y': [0, 1]})) fig.add_trace(go.Indicator( mode="number+delta", value=master_data["Recovered"], title={ "text": "Recovered"}, delta={'reference': int(dff.iloc[-2, 3]), 'relative': True}, domain={'x': [0.8, 1], 'y': [0, 1]})) return fig
def create_gauge(row): """ Function to create the 8 Gauge chart subplots Arguments: row: Selected row Returns: Figure object """ fig = make_subplots(rows=2,cols=4, specs=[[{"type": "indicator"}, {"type": "indicator"},{"type": "indicator"}, {"type": "indicator"}], [{"type": "indicator"}, {"type": "indicator"},{"type": "indicator"}, {"type": "indicator"}]], subplot_titles=[axes[0]+"-record",axes[1]+"-record",axes[2]+"-record",axes[3]+"-record", axes[0]+"-class",axes[1]+"-class",axes[2]+"-class",axes[3]+"-class"] ) sample_df1 = df.iloc[row:row+1] sample_df2 = df_norm.iloc[row:row+1] target_class = sample_df1['target'].values[0] filtered_df = df[df['target']==target_class] filtered_df2 = df_norm[df_norm['target']==target_class] category_avg = filtered_df.mean(axis=0).tolist() category_avg = [ round(elem, 2) for elem in category_avg ] c = [1,2,3,4] colors = ["#E4FF87", '#70DDFF', '#709BFF', '#FFAA70'] for i,axis in zip(c,axes): [fig.add_trace(go.Indicator( mode = "gauge+number+delta", value = float(sample_df1[axis]) , domain = {'x': [0,1], 'y': [0,1]}, delta = {'reference': float(category_avg[i-1]), 'increasing': {'color': "RebeccaPurple"}}, gauge = {'bar':{'color':colors[i-1]}, 'axis': {'range': [-4, 4]}} # 'steps': [ # {'range': [-4, 0], 'color': 'white'}, # {'range': [0.1, 4], 'color': 'red'}]} #title = {'text': axis}) ),row=1,col=i)] for i,axis in zip(c,axes): [fig.add_trace(go.Indicator( mode = "gauge+number", value = float(category_avg[i-1]) , domain = {'x': [0,1], 'y': [0,1]}, gauge = {'bar':{'color':colors[i-1]}, 'axis': {'range': [-4, 4]}}, delta = {'reference': 0, 'increasing': {'color': "RebeccaPurple"}}, #title = {'text': axis}) ),row=2,col=i)] fig.update_layout(paper_bgcolor='rgba(233,233,233,0)', plot_bgcolor='rgba(255,233,0,0)') for i in range(0,8): fig.layout.annotations[i]["font"] = {'size': 12} return fig
def get_widget_graph(self): return dbc.Row() data_arr = self.config['graph']['data'] figs = [ go.Figure(data=go.Indicator(mode="gauge+number", value=data['value'], domain=dict(x=[0, 1], y=[0, 1]), number=dict(suffix=' %'), gauge=dict( axis=dict(range=[0, 200], visible=False), bar=dict(color='#00FF00', thickness=1), bordercolor='rgba(0,0,0,0)', )), layout=self.get_graph_layout( dict(margin=dict(l=15, t=15, r=15, b=15), height=100))) for data in data_arr ] return [ dbc.Row([ dbc.Col([ dcc.Graph(figure=fig, className='w-100'), html.P(data_arr[index]['label'], className='text-center') ], className='col-6 col-lg-3') for index, fig in enumerate(figs) ], className='mx-auto') ]
def update_fish_graph(fish_value): fish_sum = fish_aggregate[fish_aggregate['fish_type'] == fish_value].copy() fish_sum.sort_values(by='year', inplace=True) pop_2009 = fish_sum[fish_sum['year'] == 2009]['fish_total'].values[0] pop_2018 = fish_sum[fish_sum['year'] == 2018]['fish_total'].values[0] return { 'data': [ go.Indicator( mode="delta", value=pop_2018, delta={ 'reference': pop_2009, 'relative': True, 'font.size': 28 }, ), go.Scatter(x=fish_sum.year, y=fish_sum['fish_total']) ], 'layout': go.Layout( title= f"{fish_value.replace('_', ' ').title()} <br> Population Evolution", margin=dict(l=40, r=0, b=100, t=50, pad=0), ) }
def update_output(client_num): default_proba = 0 if (client_num == MSG_ERROR) | (client_num == ''): pass else: default_proba = df.loc[df['client'] == client_num, 'default_proba'].array[0] gauge_score = [ go.Indicator( mode = 'gauge+number', value= default_proba, number={'suffix': "%"}, gauge={ 'axis': {'range':[0, 100]}, 'threshold':{ 'value': 91.7936, 'thickness': 0.9, 'line': {'color': 'red', 'width': 3} }, }, ) ] gauge_layout = { 'autosize': False, 'height': 250, 'width': 300, 'title': 'Probabilité de défaut<br>de paiement<br>', } return { 'data': gauge_score, 'layout': gauge_layout, }
def update_output(value): # creo un dizionario con le esposizioni per ciascun anno exp_per_years = { year: value for year, value in df.loc["total_exp"].items() } # dato che l'indicatore mostra la variazione rispetto all'anno precedente, creo anche un anno fittizio minore del # primo anno monitorato, con valore identico a questo. exp_per_years[df.columns.values.min() - 1] = df.loc["total_exp", df.columns.values.min()] total_exp_graph = go.Indicator(mode="number+delta", value=exp_per_years[int(value)], delta={ "reference": exp_per_years[int(value) - 1], "increasing": { "color": "#FF0000" }, "decreasing": { "color": "#008000" } }, title={"text": "Total Exposures"}) total_exp_layout = go.Layout(paper_bgcolor=colors["background"], plot_bgcolor=colors["background"], font=dict(color=colors["text"])) total_exp_figure = dict(data=[total_exp_graph], layout=total_exp_layout) return total_exp_figure
def get_gauge(pred): pred = round(pred * 100) if pred >= 50: color = "red" else: color = "orange" fig = go.Figure() fig.add_trace( go.Indicator(mode="gauge+number", value=pred, gauge={ "axis": { "range": [0, 100], "dtick": 25, "showticklabels": True, "tickcolor": "red" }, "bar": { "color": color, "thickness": 0.85 } }, number={"suffix": "%"})) fig.update_layout(height=550, width=750) return fig
def gauge_orders(): # orders['orderdate'] = pd.to_datetime(orders['orderdate']).dt.date # # today = np.datetime64('2016-09-19') # # yesterday = np.datetime64('2016-09-18') # # today_orders = orders[orders['orderdate'] == today]['orderid'].count() + 3 # # yesterday_orders = orders[orders['orderdate'] == yesterday]['orderid'].count() today_orders = 25 yesterday_orders = 22 fig = go.Figure( go.Indicator(title={"text": "No. orders placed today"}, mode="number+delta", value=today_orders, number={'suffix': " orders"}, delta={ 'position': "top", 'reference': yesterday_orders }, domain={ 'x': [0, 1], 'y': [0, 1] })) fig.update_layout(margin=dict(l=30, r=30, t=30, b=10)) return fig
def gauge_revenue(): # orders['orderdate'] = pd.to_datetime(orders['orderdate']).dt.date # # today = np.datetime64('2016-09-19') # # yesterday = np.datetime64('2016-09-18') # # today_revenue = orders[orders['orderdate'] == today]['totalprice'].sum() # # yesterday_revenue = orders[orders['orderdate'] == yesterday]['totalprice'].sum() today_revenue = 1023.71 yesterday_revenue = 1050.26 fig = go.Figure( go.Indicator(title={"text": "Total revenue today"}, mode="number+delta", value=today_revenue, number={'prefix': "$"}, delta={ 'position': "top", 'reference': yesterday_revenue }, domain={ 'x': [0, 1], 'y': [0, 1] })) fig.update_layout(margin=dict(l=30, r=30, t=30, b=10)) return fig
def update_graph_live(n): df = get_df() # rating fig = go.Figure() #1 fig.add_trace(go.Scatter(x=df.index+1, y=df['review'], marker_color = 'crimson', hoverinfo='y', mode='lines+markers')) # indicator of change prev_review_rate_mean = round(df.iloc[:-2:,7].mean(), 2) new_review_rate_mean = round(df.iloc[:,7].mean(), 2) #2 fig.add_trace(go.Indicator(mode = 'number+delta', value = new_review_rate_mean, hoverinfo='skip', delta = {"reference": prev_review_rate_mean, "valueformat": ".2f"}, title = {"text": "Review rate"}, domain = {'y': [0, 1], 'x': [0.0, 1.0]})) # mean_line #3 fig.add_trace(go.Scatter(x=list(df.index+1), y=([df['review'].mean()] * len(df.index)), line=dict(color="#6b648f", dash="dash"), name = 'mean', mode="lines")) # config layout fig.update_layout(plot_bgcolor=colors['background'], paper_bgcolor = colors['background'], font=dict(color=colors['text']), xaxis=dict(gridcolor=colors['grid'], showgrid=False), autosize=True, title="Оценки пользователей / текущий средний рейтинг", yaxis=dict(gridcolor=colors['grid'], range=[0,10]), showlegend=False, ) return fig
def gauge_units(): # orders['orderdate'] = pd.to_datetime(orders['orderdate']).dt.date # # today = np.datetime64('2016-09-19') # # yesterday = np.datetime64('2016-09-18') # # today_numunits = orders[orders['orderdate'] == today]['numunits'].sum() # # yesterday_numunits = orders[orders['orderdate'] == yesterday]['numunits'].sum() today_numunits = 48 yesterday_numunits = 24 fig = go.Figure( go.Indicator(title={"text": "No. units sold today"}, mode="number+delta", value=today_numunits, number={'suffix': " units"}, delta={ 'position': "top", 'reference': yesterday_numunits }, domain={ 'x': [0, 1], 'y': [0, 1] })) fig.update_layout(margin=dict(l=30, r=30, t=30, b=10)) return fig
def update_graph6(country_name): country_df = df[df['location'] == country_name] fig = px.bar(country_df.tail(30), x='date', y='new_deaths') fig.update_traces(marker_color=bar_color) fig.update_layout(title={ 'text': 'New deaths last 30 days', **title_style_middle }, xaxis=bar_chart_style, yaxis=bar_chart_style, margin=dict(l=0, r=0, t=0, b=0), **plotPaperBgColor) fig.add_trace( go.Indicator(mode='number+delta', value=country_df.tail(30).iloc[29]['new_deaths'], delta={ 'reference': country_df.tail(30).iloc[1]['new_deaths'], 'relative': True, 'increasing': { 'color': 'red' }, 'decreasing': { 'color': 'green' } }, number={'font': { 'color': '#1f302e' }})) return fig
def indicator(lastMonth, previousMonth, titulo): return { 'data': [ go.Indicator(mode="gauge+number+delta", value=lastMonth, domain={ 'x': [0, 1], 'y': [0, 1] }, title={'text': titulo}, delta={'reference': previousMonth}, gauge={ 'axis': { 'range': [None, 30] }, 'steps': [{ 'range': [0, 15], 'color': "lightgray" }, { 'range': [15, 25], 'color': "gray" }], 'threshold': { 'line': { 'color': "red", 'width': 4 }, 'thickness': 0.75, 'value': 29 } }) ] }
def update_graph_live(n): pr_rate_per_day = create_rating_df() df = create_df() # логика для рэйтинга pr_day_rate = pr_rate_per_day.iloc[-2,1] last_day_rate = pr_rate_per_day.iloc[-1,1] #------------------------------------- data=[go.Indicator(mode = 'number+delta', value = last_day_rate, delta = {"reference": pr_day_rate, "valueformat": ".0f"}, title = {"text": "Praktikum rate"}, domain = {'y': [0, 1], 'x': [0.25, 0.75]} ), go.Scatter( x = df['timestamp'], y = df['pr_rate'], line=dict(color="crimson"),name = 'rate' ), go.Scatter( x=list(df.timestamp), y=([df['pr_rate'].mean()] * len(df.timestamp)), line=dict(color="#6b648f", dash="dash"),name = 'mean')] layout = go.Layout(plot_bgcolor=colors['background'], paper_bgcolor = colors['background'], font=dict(color=colors['text']), xaxis=dict(gridcolor=colors['grid'], showgrid=False), yaxis=dict(gridcolor=colors['grid']), xaxis_rangeslider_visible=True ) fig = go.Figure(data=data, layout=layout) #fig.add_shape(go.layout.Shape(type="line", x0=df.loc[14,'timestamp'], y0=0, x1=df.loc[14,'timestamp'], y1=650, line=dict(color='green'))) return fig
def update_graph_live(n): pr_rate_per_day = create_rating_df() # логика для рэйтинга pr_day_rate = pr_rate_per_day.iloc[-2, 1] last_day_rate = pr_rate_per_day.iloc[-1, 1] #------------------------------------- data = [ go.Indicator(mode='number+delta', value=last_day_rate, delta={ "reference": pr_day_rate, "valueformat": ".0f" }, title={"text": "Praktikum rate"}, domain={ 'y': [0, 1], 'x': [0.25, 0.75] }), go.Scatter(x=pr_rate_per_day['day'], y=pr_rate_per_day['pr_rate'], marker_color='crimson') ] layout = go.Layout(plot_bgcolor=colors['background'], paper_bgcolor=colors['background'], font=dict(color=colors['text']), xaxis=dict(gridcolor=colors['grid'], showgrid=False), yaxis=dict(gridcolor=colors['grid'])) fig = go.Figure(data=data, layout=layout) #fig.add_shape(go.layout.Shape(type="line", x0=df.loc[14,'timestamp'], y0=0, x1=df.loc[14,'timestamp'], y1=650, line=dict(color='green'))) return fig
def __init__(self, api_key, secret_key): client = pybybit.API(key=api_key, secret=secret_key, testnet=False) self.store = pybybit.DataStore() client.ws.add_callback(self.store.onmessage) client.ws.run_forever_inverse(topics=['order']) self.fig = go.Figure() self.fig.add_trace( go.Indicator( mode="number", value=0, title={ "text": "<span style='font-size:0.8em;color:gray'>Active Buy Orders</span>" }, domain={ 'x': [0, 0.5], 'y': [0, 0] })) self.fig.add_trace( go.Indicator( mode="number", value=0, title={ "text": "<span style='font-size:0.8em;color:gray'>Active Sell Orders</span>" }, domain={ 'x': [0.6, 1], 'y': [0, 0] })) self.app = dash.Dash() self.app.layout = html.Div([ dcc.Graph(id='live-indicator', animate=False, figure=self.fig), dcc.Interval( id='indicator-update', interval=1000, # updating every 1 second n_intervals=0) ]) self.app.callback(Output('live-indicator', 'figure'), [Input('indicator-update', 'n_intervals')], [State('live-indicator', 'figure')])( self.update_graph)
def update_confirmed(w_countries): '''input argument is w_countries (id of dropdown list) to get a dynamic value Since call-back will call the function right below it, name of the function is not important''' covid_data_2 = covid_data.groupby(['date', 'Country/Region'])[[ 'confirmed', 'death', 'recovered', 'active' ]].sum().reset_index() # Today value_confirmed = covid_data_2[ covid_data_2['Country/Region'] == w_countries]['confirmed'].iloc[ -1] - covid_data_2[covid_data_2['Country/Region'] == w_countries]['confirmed'].iloc[-2] # Yesterday value_confirmed_yesterday = covid_data_2[ covid_data_2['Country/Region'] == w_countries]['confirmed'].iloc[ -2] - covid_data_2[covid_data_2['Country/Region'] == w_countries]['confirmed'].iloc[-3] # print(f'value_confirmed = {value_confirmed}, value_confirmed_yesterday = {value_confirmed_yesterday}') return { 'data': [ go.Indicator( mode='number+delta', value=value_confirmed, delta={ 'reference': value_confirmed_yesterday, 'position': 'right', 'valueformat': ',g', 'relative': False, 'font': { 'size': 15 } }, number={ 'valueformat': ',', 'font': { 'size': 20 } }, domain={ 'y': [0, 1], 'x': [0, 1] } # it is alignment of the two values ) ], 'layout': go.Layout( title={ 'text': 'New Confirmed', 'y': 1, 'x': 0.5, 'xanchor': 'center', 'yanchor': 'top' }, font=dict(color='orange'), paper_bgcolor='#1f2c56', plot_bgcolor='#1f2c56', height=50, ) }
def update_active(state): dt=statewise[statewise['Status']=='Deceased'][state].iloc[-1] rt=statewise[statewise['Status']=='Recovered'][state].iloc[-1] ct=statewise[statewise['Status']=='Confirmed'][state].iloc[-1] dy=statewise[statewise['Status']=='Deceased'][state].iloc[-2] ry=statewise[statewise['Status']=='Recovered'][state].iloc[-2] cy=statewise[statewise['Status']=='Confirmed'][state].iloc[-2] # Build the figure fig = { "data": [ go.Indicator( mode = "number+delta", value = ct-dt-rt, delta = { "reference": cy-ry-dy, "position": "right", "valueformat": ",g", "relative": False, "font": { "size": 15 } }, number = { "valueformat": ",", "font": { "size": 20 } }, domain = { "y": [0, 1], "x": [0, 1] } ) ], "layout": go.Layout( title = { "text": "Active Cases", "y": 1, "x": 0.5, "xanchor": "center", "yanchor": "top" }, font = { "color": "#e55467" }, paper_bgcolor = "white", plot_bgcolor = "white", height = 50 ) } # Return the figure return fig
def update_recovered(w_countries): covid_data_2 = covid_data.groupby(['date', 'Country/Region'])[[ 'confirmed', 'death', 'recovered', 'active' ]].sum().reset_index() value_recovered = covid_data_2[ covid_data_2['Country/Region'] == w_countries]['recovered'].iloc[ -1] - covid_data_2[covid_data_2['Country/Region'] == w_countries]['recovered'].iloc[-2] value_recovered_yesterday = covid_data_2[ covid_data_2['Country/Region'] == w_countries]['recovered'].iloc[ -2] - covid_data_2[covid_data_2['Country/Region'] == w_countries]['recovered'].iloc[-3] # print(f'value_recovered = {value_recovered}, value_recovered_yesterday={value_recovered_yesterday}') return { 'data': [ go.Indicator(mode='number+delta', value=value_recovered, delta={ 'reference': value_recovered_yesterday, 'position': 'right', 'valueformat': ',g', 'relative': False, 'font': { 'size': 15 } }, number={ 'valueformat': ',', 'font': { 'size': 20 } }, domain={ 'y': [0, 1], 'x': [0, 1] }) ], 'layout': go.Layout( title={ 'text': 'New Recovered', 'y': 1, 'x': 0.5, 'xanchor': 'center', 'yanchor': 'top' }, font=dict(color='green'), paper_bgcolor='#1f2c56', plot_bgcolor='#1f2c56', height=50, ) }
def output_value(n_intervals): index1 = 0 n_intervals = n_intervals % length if (n_intervals >= 0 and n_intervals <= length - 1): index1 = n_intervals fig1 = go.Figure( go.Indicator(mode="gauge+number+delta", value=y[index1], domain={ 'x': [0, 1], 'y': [0, 1] }, title={'text': "Stride Frequency"})) fig2 = go.Figure( go.Indicator(mode="gauge+number+delta", value=z[index1], domain={ 'x': [0, 1], 'y': [0, 1] }, title={'text': "Stride Duration"})) return (fig1, fig2)
def biden_total_number( time_slider: List[int], profanity_dropdown: List[str], candidate_dropdown: List[str], ) -> go.Figure: filtered_frame = process_profanity(time_slider, profanity_dropdown, candidate_dropdown) biden_count = filtered_frame.query("subject=='Biden'")["count"].sum() indicator = go.Figure() indicator.add_trace(go.Indicator(value=biden_count, mode="number")) indicator.update_layout(margin={"l": 0, "r": 0, "b": 0, "t": 0, "pad": 1}) return indicator
def update_confirmed(w_countries): covid_data_2 = covid_data.groupby(['date', 'Country/Region'])[[ 'confirmed', 'death', 'recovered', 'active' ]].sum().reset_index() value_active = covid_data_2[covid_data_2['Country/Region'] == w_countries][ 'active'].iloc[-1] - covid_data_2[covid_data_2['Country/Region'] == w_countries]['active'].iloc[-2] delta_active = covid_data_2[covid_data_2['Country/Region'] == w_countries][ 'active'].iloc[-2] - covid_data_2[covid_data_2['Country/Region'] == w_countries]['active'].iloc[-3] return { 'data': [ go.Indicator(mode='number+delta', value=value_active, delta={ 'reference': delta_active, 'position': 'right', 'valueformat': ',g', 'relative': False, 'font': { 'size': 15 } }, number={ 'valueformat': ',', 'font': { 'size': 20 }, }, domain={ 'y': [0, 1], 'x': [0, 1] }) ], 'layout': go.Layout(title={ 'text': 'New Active', 'y': 1, 'x': 0.5, 'xanchor': 'center', 'yanchor': 'top' }, font=dict(color='#e55467'), paper_bgcolor='#102c44', plot_bgcolor='#102c44', height=50), }
def update_graph(company, value): dff = find_all_cells_with_index(make_combined_df(company), 'Index', value) colors = ['#176BEF', '#3B5998', '#1C9DEB', '#d3d030'] c = colors[0] if company == 'GOOGL' else colors[ 1] if company == 'FB' else colors[2] if company == 'TWTR' else colors[3] fig = tools.make_subplots( rows=1, shared_xaxes=True, shared_yaxes=True, cols=1, print_grid=False, vertical_spacing=0.12, ) # Add main trace (style) to figure fig.append_trace( go.Scatter(x=dff['Year_Peoriode'].values, y=['${:0,.0f}'.format(stock) for stock in dff["Stock"]], mode='lines', name='Stock', line=dict(color=c, width=3)), 1, 1) fig.add_trace( go.Indicator(mode="number+delta", value=np.flipud(dff["Stock"])[0], delta={ "reference": np.flipud(dff['Stock'])[3:12].mean(), "valueformat": ".0f" }, title={"text": company + " Stock Prices"}, domain={ 'y': [0, 1], 'x': [.25, .75] })) fig["layout"]["margin"] = {"t": 10, "l": 10, "b": 80, "r": 40} fig["layout"]["autosize"] = True fig["layout"]["height"] = 400 fig["layout"]["xaxis"]["rangeslider"]["visible"] = False fig["layout"]["xaxis"]["showgrid"] = False fig["layout"]["xaxis"]["title"] = "Year-Quarter" fig["layout"]["yaxis"]["tickformat"] = "$," fig["layout"]["yaxis"]["showgrid"] = False fig["layout"]["yaxis"]["gridcolor"] = "#c4d1ed" fig["layout"]["yaxis"]["gridwidth"] = 1 fig["layout"].update(paper_bgcolor="#E5ECF6", plot_bgcolor="#E5ECF6") return fig
def live_machine(data): """ Generates components for the 'bottom-bar' """ measurements = list(influx.get_measurements()) # for now use all available measurements, instead data.keys? children = [] layout = dict( paper_bgcolor="rgba(0,0,0,0)", plot_bgcolor="rgba(0,0,0,0)", margin=dict(l=0, r=0, b=0, t=0, pad=5), showlegend=False, font={"color": "white"}, ) for msmt in measurements: fig = go.Figure( go.Indicator( mode="gauge+number", value=data[msmt]["y"][-1], domain={ "x": [0.2, 0.8], "y": [0, 0.8] }, title=f"{msmt.upper()}", gauge={ "axis": { "tickwidth": 1, "tickcolor": "darkblue", }, "bar": { "color": "darkblue" }, "bgcolor": "white", "borderwidth": 2, "bordercolor": "gray", }, )) fig.update_layout(layout) children.append( dcc.Graph(figure=fig, config={"displayModeBar": False}, className="gauge")) return children
def update_recovered(state): # Build the figure fig = { "data": [ go.Indicator( mode = "number+delta", value = statewise[statewise['Status']=='Recovered'][state].iloc[-1], delta = { "reference": statewise[statewise['Status']=='Recovered'][state].iloc[-2], "position": "right", "valueformat": ",g", "relative": False, "font": { "size": 15 } }, number = { "valueformat": ",", "font": { "size": 20 } }, domain = { "y": [0, 1], "x": [0, 1] } ) ], "layout": go.Layout( title = { "text": "Recoveries", "y": 1, "x": 0.5, "xanchor": "center", "yanchor": "top" }, font = { "color": "green" }, paper_bgcolor = "white", plot_bgcolor = "white", height = 50 ) } # Return the figure return fig
def update_active_cases(province): value_confirmed = df_categories['Kasus Aktif'][province].iloc[ -1] - df_categories['Kasus Aktif'][province].iloc[-2] delta_confirmed = df_categories['Kasus Aktif'][province].iloc[ -2] - df_categories['Kasus Aktif'][province].iloc[-3] result = { "data": [ go.Indicator(mode='number+delta', value=value_confirmed, delta={ 'reference': delta_confirmed, 'position': 'right', 'valueformat': ',g', 'relative': False, 'font': { 'size': 15 } }, number={ "valueformat": ',', 'font': { 'size': 20 } }, domain={ 'y': [0, 1], 'x': [0, 1] }) ], 'layout': go.Layout(title={ 'text': 'Kasus Aktif', 'y': 1, 'x': 0.5, 'xanchor': 'center', 'yanchor': 'top' }, font=dict(color='white'), paper_bgcolor='#1f2c56', plot_bgcolor='#1f2c56', height=50) } return result
def get_custom_indicator(value, delta=None): figure = go.Indicator( mode="number+delta", value=value, number={ 'valueformat': "000,000,000", "font": { 'size': 40 } }, delta={ "reference": delta, "valueformat": "000,000,000", }, ) return figure
def trump_total_number( time_slider: List[int], profanity_dropdown: List[str], candidate_dropdown: List[str], ) -> go.Figure: filtered_frame = (process_profanity(time_slider, profanity_dropdown, candidate_dropdown).groupby( ["time_central", "subject"]).agg({ "count": "sum" }).reset_index()) trump_count = filtered_frame.query("subject=='Trump'")["count"].sum() indicator = go.Figure() indicator.add_trace(go.Indicator(value=trump_count, mode="number")) indicator.update_layout(margin={"l": 0, "r": 0, "b": 0, "t": 0, "pad": 1}) return indicator
def gerar_grafico1(mensagem): if mensagem == 'Arquivo carregado com sucesso!': n_recomendacoes = df_sim.shape[0] data = [ go.Indicator( mode="number", value=n_recomendacoes, title={ "text": "<span style='color:white'>Nº Total de Recomendações</span>" }, domain={ 'x': [0, 0], 'y': [0, 0] }) ] layout = go.Layout(paper_bgcolor='#262B3D', plot_bgcolor='#262B3D') fig = go.Figure(data=data, layout=layout) return fig else: pass