Ejemplo n.º 1
0
def _update_div1(df):

    df_ = pd.read_json(df, orient='split')

    fig = px.bar(hastag_counts(df_)[:20], y='#Tags', x='#Num', orientation='h')
    fig.update_yaxes(categoryorder='total ascending', title='')
    fig.update_layout(margin=dict(t=30, r=0, b=0, pad=1), title_x=.5)
    return fig
Ejemplo n.º 2
0
def top_goalscorer(df):
    df['player_rating'] = df['player_name'] + ' - ' + df['rating'].astype(
        'str')
    fig = px.bar(df.sort_values('goals', ascending=False).head(25),
                 x='player_rating',
                 y='goals',
                 title='Top 25 Goalscorers')
    st.plotly_chart(fig)
Ejemplo n.º 3
0
def draw_interactive_bar_plot_for_simulations(df):
    return px.bar(
        df, 
        x='ctp_bin_labels', 
        y='ctp_bin_counts', 
        animation_frame='sim_index', 
        range_y=[0,1300]
    )
Ejemplo n.º 4
0
def create_df(selected_provider):
    df1 = psi_data_df[psi_data_df['Provider_Name'] == selected_provider]
    results2plot_df = df1.append(benchmark_df, ignore_index=True, sort=True)
    return px.bar(results2plot_df,
                  x='Measure_ID',
                  y='Rate',
                  color='Provider_Name',
                  barmode='group',
                  hover_name='Measure_Name')
Ejemplo n.º 5
0
def update_figure(value):
    if value == "TE19": df = df_TE19
    elif value == "NA19": df = df_NA19

    fig = px.bar(df,
                 y="Närvarograd",
                 title=f"Närvarograd i procent för {value}")
    fig.update_layout(transition_duration=500)
    return fig
Ejemplo n.º 6
0
def draw_interactive_prob_bar_plot_for_simulations(df):
    _df = df.copy()
    _df['ctp_bin_prob'] = _df['ctp_bin_counts'] / _df['simulations']

    return px.bar(_df,
                  x='ctp_bin_labels',
                  y='ctp_bin_prob',
                  animation_frame='sim_index',
                  range_y=[0, 0.4])
    def plot_simple_histogram(self,
                              metric_name,
                              x="value",
                              y="count",
                              **kwargs):
        if not self.has(metric_name):
            return

        fig = px.bar(self.metrics[metric_name], x=x, y=y, **kwargs)
        fig.show()
Ejemplo n.º 8
0
def top_nations_bar(df):
    j = px.bar(df.groupby(['nation_abbrname'
                           ]).size().to_frame('count').sort_values(
                               ['count'],
                               ascending=False).reset_index().head(25),
               x='nation_abbrname',
               y='count',
               title='Number of Players by Nation')
    j.update_xaxes(title='Nation')
    j.update_yaxes(title='# of Players')
    st.plotly_chart(j)
Ejemplo n.º 9
0
def top_leagues_bar(df):
    i = px.bar(df.groupby(['league_name'
                           ]).size().to_frame('count').sort_values(
                               ['count'],
                               ascending=False).reset_index().head(25),
               x='league_name',
               y='count',
               title='Number of Players by League')
    i.update_xaxes(title='League')
    i.update_yaxes(title='# of Players')
    st.plotly_chart(i)
Ejemplo n.º 10
0
def top_clubs_bar(df):
    h = px.bar(df.groupby(['club_abbrname'
                           ]).size().to_frame('count').sort_values(
                               ['count'],
                               ascending=False).reset_index().head(25),
               x='club_abbrname',
               y='count',
               title='Number of Players by Club')
    h.update_xaxes(title='Club')
    h.update_yaxes(title='# of Players')
    st.plotly_chart(h)
Ejemplo n.º 11
0
def stacked_bar_chart(sample: pd.DataFrame, grouper_col: str, x: str, y: str,
                      orientation: str, color_col: str, x_title: str,
                      y_title: str, main_title: str, file: str):
    """
    :param sample: A pandas DataFrame
    :param grouper_col:
    :param x: Column from which x values will be derived
    :param y: Column from which y values will be derived
    :param orientation: Either 'v' or 'h' for a vertical or horizontal orientation respectively
    :param color_col: Column with values to use as colour traces
    :param x_title: String for x axis title
    :param y_title: String for y axis title
    :param main_title: String to input as chart title
    :param file: String representing .png filename
    :return: A plot.ly graph objects figure
    """
    df = sample.copy()
    df = df.sort_values(color_col)

    pio.templates.default = 'plotly_white'
    color_map = color_formatter(sample=df, color_col=color_col)

    chart = px.bar(data_frame=df,
                   x=x,
                   y=y,
                   color=color_col,
                   orientation=orientation,
                   color_discrete_map=color_map,
                   title=main_title)

    # To ensure that bar heights are arranged in order
    df_grouped_for_ordering = df.groupby([grouper_col]).sum().reset_index()
    df_grouped_for_ordering = df_grouped_for_ordering.sort_values(
        by=[x], ascending=True)
    array_ordering = df_grouped_for_ordering['brand'].values
    chart.update_layout(barmode='stack',
                        yaxis={
                            'categoryorder': 'array',
                            'categoryarray': array_ordering
                        })

    chart.update_xaxes(title_text=x_title,
                       showgrid=False,
                       tickfont=dict(family='Arial', color='Black', size=12),
                       zeroline=False)
    chart.update_yaxes(title_text=y_title,
                       showgrid=False,
                       tickfont=dict(family='Arial', color='Black', size=12),
                       zeroline=False)

    chart_formatter(chart=chart, main_title=main_title, legend_pos=-0.15)
    pio.write_image(fig=chart, file=filepath + file + '.png')

    return chart
    def plot_linear_datetimes(self,
                              time_component,
                              x="value",
                              y="count",
                              **kwargs):
        METRIC_NAME = "dates_linear." + time_component

        if not self.has(METRIC_NAME):
            return

        fig = px.bar(self.metrics[METRIC_NAME]["counts"], x=x, y=y, **kwargs)
        fig.show()
def bar_chart_2(df):

    fig = px.bar(df,
                 y='Priority',
                 x="Costs",
                 color='Campaing',
                 barmode="group",
                 orientation="h",
                 title="POWER BI DASHBOARD")

    fig.update_layout(title_x=.5, margin=dict(t=50))

    return fig
def bar_chart_2_produc(df):

    tmp = df['Products'].value_counts().sort_index().reset_index()

    fig = px.bar(tmp,
                 x='index',
                 y="Products",
                 barmode="group",
                 title="PRODUCTS")

    fig.update_layout(title_x=.5, margin=dict(t=50))

    return fig
Ejemplo n.º 15
0
def make_fig2(arg, taxlevel):
    levels = {1: "phylum", 2: "class", 3: "order", 4: "family", 5: "genus", 6: "species"}
    a = deep[deep["predicted_ARG-class"] == arg]
    b = a.groupby(levels[taxlevel]).count()[["predicted_ARG-class"]]
    # not use colors if level is species (too many colors)
    if taxlevel == 6:
        fig = go.Figure(px.bar(b.reset_index(), y="predicted_ARG-class", x=levels[taxlevel], template='plotly_white',
                               title="Number of " + str(arg) +" resistance genes found per " + str(levels[taxlevel])).for_each_trace(
            lambda t: t.update(name=t.name.replace(str(levels[taxlevel]) + "=", ""))))
        fig.update_layout(margin=go.layout.Margin(b=200, l=0, r=0))
    else:
        fig = go.Figure(
            px.bar(b.reset_index(), y="predicted_ARG-class", x=levels[taxlevel], template='plotly_white', color=levels[taxlevel],
                   title="Number of " + str(arg) +" resistance genes found per " + str(levels[taxlevel])).for_each_trace(
                lambda t: t.update(name=t.name.replace(str(levels[taxlevel]) + "=", ""))))
        fig.update_layout(margin=go.layout.Margin(b=0, l=0, r=0))

    fig.update_xaxes(title_text=None)
    fig.update_yaxes(title_text="Number of ORFs")

    fig.update_layout(autosize=True, titlefont={"size": 20})
    fig.update_layout(plot_bgcolor="#F9F9F9", paper_bgcolor="#F9F9F9")
    return fig
Ejemplo n.º 16
0
def analise_dados():
    st.header('** Análise das variavéis categoricas**')
    st.subheader('Rainfall x Location')
    df_process.dropna(inplace=True)  # quebra galho retirar
    cities_lst = list(df_process['location'].unique())
    cities = st.multiselect('Escolha as cidades que deseja ver os dados',
                            cities_lst,
                            default=cities_lst)
    df_filter = df_process[(df_process['location'].isin(cities))]
    soma_local = df_filter.groupby('location')['location',
                                               'rainfall'].sum().reset_index()
    soma_local = soma_local.sort_values(by='rainfall')
    fig = px.bar(soma_local, x='location', y='rainfall')
    st.plotly_chart(fig)
def bar_chart_3_browser(df):

    tmp = df.groupby(["Funnel", 'SocialMedia'])['email'].count().reset_index()

    fig = px.bar(tmp,
                 x='SocialMedia',
                 y="email",
                 color="Funnel",
                 barmode="group",
                 title="REACHABILITY")

    fig.update_layout(title_x=.5, margin=dict(t=50))

    return fig
Ejemplo n.º 18
0
def plot_tweets_total(df):
    df_count = df.groupby(['handle'], as_index=False).count().iloc[:, 0:2]
    df_count.columns = ['handle', 'number of tweets']
    # create plot
    fig = px.bar(df_count,
                 x='handle',
                 y='number of tweets',
                 color="handle",
                 color_discrete_map=colour_dict,
                 title="Number of Tweets",
                 height=400)
    fig.update_layout({"showlegend": False})
    fig.update_layout(margin=dict(l=0, r=0, t=30, b=30), autosize=True)
    return (fig)
Ejemplo n.º 19
0
def Exit_Analysis(Employee_ID):

    exp = explainer.explain_instance(X.loc[Employee_ID],
                                     predict_fn_ada,
                                     num_features=5)

    tmp_lime = pd.DataFrame(exp.as_list(), columns=['feature', 'weight'])
    tmp_lime['weight%'] = (round(tmp_lime['weight'] * 10000,
                                 2)).astype(str) + '%'
    tmp_lime['Exit'] = (tmp_lime['weight'] > 0).astype('str')
    tmp_lime = tmp_lime.replace(regex={'True': 'Yes', 'False': 'No'})

    fig = px.bar(
        tmp_lime[::-1],
        y='feature',
        x='weight',
        color='Exit',
        orientation='h',
        color_discrete_map={
            'No': 'green',
            'Yes': 'red'
        },
        opacity=0.8,
        category_orders={'Exit': ['No', 'Yes']},
        text='weight%',
        template='plotly_white+presentation+xgridoff',
    )

    fig = fig.update(layout=dict(title=dict(
        text='Top Exit Risk Attributes',
        font=dict(family='Arial', size=28, color='black')),
                                 legend=dict(orientation='h', x=0.2, y=1.15),
                                 yaxis=dict(title=None,
                                            ticks='outside',
                                            showline=True,
                                            showgrid=False,
                                            mirror=True,
                                            linecolor='black'),
                                 xaxis=dict(title=None,
                                            showticklabels=False,
                                            showline=True,
                                            mirror=True,
                                            linecolor='black'),
                                 autosize=False,
                                 width=1300,
                                 height=500,
                                 margin=go.layout.Margin(l=350, r=200, t=100)))

    return fig
Ejemplo n.º 20
0
    def display_value(value):
        if value == "Records lost by Entity":
            fig = px.scatter(
                df,
                x='Records Lost',
                y='Year',
                range_x=[5000, 3500000000],
                symbol='Sector',
                animation_group='Sector',
                color='Sector',
                hover_name='Entity',
                hover_data=["Method of Leak"],
                color_discrete_sequence=px.colors.qualitative.Alphabet,
                log_x=True,
                height=900,
                opacity=1,
                render_mode='webgl',
                width=1400)

            fig.update_traces(marker=dict(size=15,
                                          line=dict(width=1,
                                                    color='DarkSlateGrey')),
                              selector=dict(mode='markers'))
            return fig
        elif value == "Records lost by Method":
            return go.Figure(data=[
                go.Pie(labels=df["Method of Leak"],
                       values=df["Records Lost"],
                       hole=0.2)
            ])
        elif value == "Records lost by Year":
            return px.bar(df,
                          x='Year',
                          y='Records Lost',
                          color='Method of Leak',
                          hover_data=['Entity'],
                          height=800,
                          width=1400)
        elif value == 'Records lost by Sector':
            fig_pie = go.Figure(
                data=[go.Pie(labels=df["Sector"], values=df["Records Lost"])])

            fig_pie.update_traces(hoverinfo='label+percent',
                                  textinfo='value',
                                  textfont_size=10,
                                  marker=dict(colors=df["Sector"],
                                              line=dict(color='#000000',
                                                        width=1.2)))
            return fig_pie
Ejemplo n.º 21
0
def redraft_bar(year, df):
    d = redraft_data(year, df)
    fig = px.bar(d.loc[d.WSPS != 0].sort_values('WSPS', ascending=True),
                 y='Player',
                 x='WSPS',
                 title='Win Shares Per Season (WSPS) by Player',
                 hover_data=['Pk', 'Redraft', 'Tm', 'College'],
                 orientation='h')

    fig.update_yaxes(tickfont=dict(size=8))
    fig.update_xaxes(tickfont=dict(size=8))

    fig.update_layout(height=800)

    st.plotly_chart(fig)
Ejemplo n.º 22
0
    def get_plot(self, parameters):
        target_dict = {
            1: "COUNT(*)",
            2: "AVG(AvgTone)",
            3: "Sum(NumMentions)",
            4: "AVG(GoldsteinScale)"
        }

        qe = QueryExecutor()
        query = self.query.format(
            month=parameters['month'].value,
            role_1=parameters['actor_type'].value,
            role_2=(3 - parameters['actor_type'].value),
            target_type=target_dict[parameters['target_type'].value],
        )
        df = qe.get_result_dataframe(query)
        df = df.iloc[::-1]
        df['Actor1'] = df['Actor1'].map(
            Utils().get_fips_country_id_to_name_mapping())
        df['Actor2'] = df['Actor2'].map(
            Utils().get_fips_country_id_to_name_mapping())
        df['Country name'] = df['Actor1'] + ' & ' + df['Actor2']
        df['Correlation coefficient'] = df['TargetCorr']

        target_name_dict = {
            1: 'Event Count',
            2: 'Average Tone',
            3: 'Sum of Mentions',
            4: 'Average Goldstein scale'
        }

        fig = px.bar(
            data_frame=df,
            x='Correlation coefficient',
            y='Country name',
            text='Country name',
            orientation='h',
            title="Correlation between {} of each day to each country for {}".
            format(target_name_dict[parameters['target_type'].value],
                   Utils().format_months_names([parameters['month'].value
                                                ])[0]),
        )
        fig.update_traces(marker_color='rgb(158,202,225)',
                          marker_line_color='rgb(8,48,107)',
                          marker_line_width=1.5,
                          opacity=0.6)
        fig.update_yaxes(title='', showticklabels=False)
        return plot(fig, include_plotlyjs=True, output_type='div')
Ejemplo n.º 23
0
def gen_plotly_datetime(df, args, var):
    columns = filter_columns(df, args)
    df_temp = df[columns]
    df_temp = df_temp[df_temp[args[var]].notnull()]
    df_temp = df_temp[['Date', args[var]]]
    df_temp.drop_duplicates(inplace=True)
    df_temp = pd.DataFrame(df_temp['Date'].value_counts())
    df_temp.sort_index(inplace=True)
    df_temp.reset_index(inplace=True)
    df_temp.columns = ['Date', args.get(var)]
    df_temp.rename(columns={args[var]: var}, inplace=True)

    fig = px.bar(df_temp, x='Date', y=var, title="{} per day".format(var))
    fig.update_xaxes(tickformat="%Y-%m-%d", type="category")
    fig.update_layout(showlegend=False)

    return fig
Ejemplo n.º 24
0
def PermImportanceplot(X, y, clf, metric, num_iterations=100):
    import plotly_express as px
    baseline, scores = PermImportance(X, y, clf, metric, num_iterations)
    percent_changes = {c: [] for c in X.columns}
    for c in scores:
        for i in range(len(scores[c])):
            percent_changes[c].append(scores[c][i] / baseline * 100)

    return (px.bar(pd.DataFrame.from_dict(percent_changes).melt().groupby(
        ['variable']).mean().reset_index().sort_values(['value'],
                                                       ascending=False)[:25],
                   x='variable',
                   y='value',
                   labels={
                       'variable': 'column',
                       'value': '% change in recall'
                   }))
Ejemplo n.º 25
0
def gen_plotly_intents(df, threshold=(0.6, 1.0)):
    logger.info({"message": "Generating intents plot."})
    df_temp = df[[
        "response.intents.0.intent", "response.intents.0.confidence"
    ]]
    df_temp.columns = ["intent", "confidence"]
    df_temp = df_temp[(df_temp["confidence"] >= threshold[0])
                      & (df_temp["confidence"] <= threshold[1])]

    df_temp = df_temp.groupby("intent").count().sort_values(by="confidence")
    df_temp.reset_index(inplace=True)
    df_temp.columns = ["intent", "quantity"]
    df_temp = df_temp.head(20)
    return px.bar(df_temp,
                  x="quantity",
                  y="intent",
                  title="Top 20 intents",
                  height=600)
Ejemplo n.º 26
0
def build_Wash_map():
    '''Build Simple bar chart of Party choices specific to Washignton State'''
    set_pandas()
    df_pres = pd.read_csv("../archive/president_county_candidate.csv")
    #set party variables
    rep = df_pres['party'] == 'REP'
    dem = df_pres['party'] == 'DEM'
    df_pres = df_pres[rep | dem]
    #select just columns where State == Washington
    Washginton = df_pres.loc[df_pres['state'] == 'Washington']
    #group df based on total votes & aggregate
    wash_votes = Washginton.groupby('party')['total_votes'].sum()
    fig = px.bar(
        wash_votes,
        title=
        "2020 USA Election: Number of Votes per Party in Washington (Repulcian vs. Democrat)"
    )
    fig.show()
    return
Ejemplo n.º 27
0
def turnover_rate_plot(feature):

    df = data.sort_values(by=[feature, 'Attrition'])
    tmp = pd.crosstab(df[feature], df['Attrition']).reset_index()
    tmp['sum'] = tmp.sum(axis=1)
    tmp['Turnover Rate (%)'] = tmp['Yes'] / (tmp['Yes'] + tmp['No']) * 100

    fig = px.bar(
        tmp,
        x=feature,
        y='Turnover Rate (%)',
        color=feature,
        #text='Turnover Rate (%)',
        title='Turnover Rate cross %s' % feature,
        template='plotly_white+presentation')
    fig = fig.update(layout=dict(showlegend=False,
                                 autosize=False,
                                 width=1100,
                                 height=600,
                                 margin=go.layout.Margin(l=200, r=200, t=100)))
    return dcc.Graph(figure=fig)
Ejemplo n.º 28
0
def update_graph(manager_dropdown_value):
    
    if manager_dropdown_value is None:
        return fig_all
    else:
        df_plot = df.query('Manager == "{}"'.format(manager_dropdown_value))
        title = 'Sales funnel of {}'.format(manager_dropdown_value)
        
        orders = (df_plot
                .groupby(['Name','Status'])
                .Quantity.sum()
                .reset_index()
                )
            
        fig = px.bar(orders, 
            x='Name', 
            y='Quantity',
            color='Status',
            title=title)
        
        return fig
def fugas_ingresos_por_mes(df):
    df_productos = df.loc[:, [
        "pk_cid",
        "pk_partition",
    ] + PRODUCTS]
    df_productos.drop('pk_cid', axis=1, inplace=True)
    clientes_producto = df_productos.groupby('pk_partition').sum()
    clientes_mes = pd.DataFrame(clientes_producto.sum(axis=1))
    clientes_mes.columns = ['Clientes']
    clientes_producto = df_productos.groupby('pk_partition').sum()
    clientes_mes['Clientes_Mes_Anterior'] = clientes_mes['Clientes'].shift(1)
    clientes_mes['Fugas_Ingresos'] = clientes_mes['Clientes'] - clientes_mes[
        'Clientes_Mes_Anterior']
    clientes_mes['Fugas_vs_ingresos'] = np.where(
        clientes_mes['Fugas_Ingresos'] > 0, 'Ingresos', 'Fugas')
    df_fugas_ingresos = clientes_mes[1:]
    fig = px.bar(df_fugas_ingresos,
                 x=df_fugas_ingresos.index,
                 y='Fugas_Ingresos',
                 color='Fugas_vs_ingresos',
                 barmode='group')
    return fig
Ejemplo n.º 30
0
def update_metric_bar_graph(tn, fp, fn, tp, beta):
    """Plot classification metrics as a bar chart"""
    m = calc_metrics(tn, fp, fn, tp, beta)
    metric_df = pd.DataFrame({
        'Metric': list(m.keys()),
        'Value': list(m.values())
    })
    metric_df['display_value'] = round(metric_df['Value'], 3)

    fig = px.bar(metric_df,
                 x='Metric',
                 y='Value',
                 color='Metric',
                 text='display_value')
    fig.update_yaxes(range=[0, 1])
    fig.layout.update(showlegend=True,
                      title={
                          'xanchor': 'center',
                          'x': 0.5,
                          'text': 'Accuracy Metrics'
                      })

    return fig