# AUTOGENERATED! DO NOT EDIT! File to edit: ../nbs/08_ecdf.ipynb.

# %% auto 0
__all__ = ['ecdf']

# %% ../nbs/08_ecdf.ipynb 3
import advertools as adv
import pandas as pd
import plotly.express as px

# %% ../nbs/08_ecdf.ipynb 5
def ecdf(df, x, hover_name=None, height=None, width=None, **kwargs):
    df = df.sort_values(x)
    df['count below'] = range(len(df))
    df['count above'] = range(len(df)-1, -1, -1)
    df['total count'] = len(df)
    fig = px.ecdf(
        df.dropna(subset=[x]),
        x=x,
        lines=False,
        markers=True,
        category_orders={x: df.sort_values(x)[x]},
        marginal='histogram',
        hover_name=hover_name,
        height=height,
        width=width,
        hover_data=['count below', 'count above', 'total count'],
        ecdfnorm='percent', **kwargs)
    # fig.data[0].hovertemplate = f'<b>{x.replace("_", " ").title()}</b><br><br>{x}' + ': %{x}<br>percent: %{y}<br><br>count below: %{customdata[0]:,}<br>count above: %{customdata[1]:,}<br>total count: %{customdata[2]:,}<extra></extra>'
    fig.update_yaxes(ticksuffix='%', showspikes=True)
    fig.update_xaxes(showspikes=True)
    return fig
