Ejemplo n.º 1
0
def test_pie_like_px():
    # Pie
    labels = ["Oxygen", "Hydrogen", "Carbon_Dioxide", "Nitrogen"]
    values = [4500, 2500, 1053, 500]

    fig = px.pie(names=labels, values=values)
    trace = go.Pie(labels=labels, values=values)
    _compare_figures(trace, fig)

    labels = [
        "Eve", "Cain", "Seth", "Enos", "Noam", "Abel", "Awan", "Enoch", "Azura"
    ]
    parents = ["", "Eve", "Eve", "Seth", "Seth", "Eve", "Eve", "Awan", "Eve"]
    values = [10, 14, 12, 10, 2, 6, 6, 4, 4]
    # Sunburst
    fig = px.sunburst(names=labels, parents=parents, values=values)
    trace = go.Sunburst(labels=labels, parents=parents, values=values)
    _compare_figures(trace, fig)
    # Treemap
    fig = px.treemap(names=labels, parents=parents, values=values)
    trace = go.Treemap(labels=labels, parents=parents, values=values)
    _compare_figures(trace, fig)

    # Funnel
    x = ["A", "B", "C"]
    y = [3, 2, 1]
    fig = px.funnel(y=y, x=x)
    trace = go.Funnel(y=y, x=x)
    _compare_figures(trace, fig)
    # Funnelarea
    fig = px.funnel_area(values=y, names=x)
    trace = go.Funnelarea(values=y, labels=x)
    _compare_figures(trace, fig)
Ejemplo n.º 2
0
    hover_name="country",
    animation_frame="year",
    range_color=[20, 80],
)
fig.write_html(os.path.join(dir_name, "choropleth.html"), auto_play=False)

import plotly.express as px

tips = px.data.tips()
fig = px.pie(tips, names="smoker", values="total_bill")
fig.write_html(os.path.join(dir_name, "pie.html"), auto_play=False)

import plotly.express as px

tips = px.data.tips()
fig = px.funnel_area(tips, names="smoker", values="total_bill")
fig.write_html(os.path.join(dir_name, "funnel_area.html"), auto_play=False)

import plotly.express as px

fig = px.treemap(
    names=[
        "Eve", "Cain", "Seth", "Enos", "Noam", "Abel", "Awan", "Enoch", "Azura"
    ],
    parents=["", "Eve", "Eve", "Seth", "Seth", "Eve", "Eve", "Awan", "Eve"],
    values=[10, 14, 12, 10, 2, 6, 6, 4, 4],
)
fig.write_html(os.path.join(dir_name, "treemap.html"), auto_play=False)

import plotly.express as px
Ejemplo n.º 3
0
fig.add_trace(go.Funnel(
    name = 'Vancouver',
    orientation = "h",
    y = ["Website visit", "Downloads", "Potential customers", "Requested price", "invoice sent", "Finalized"],
    x = [90, 70, 50, 30, 10, 5],
    textposition = "outside",
    textinfo = "value+percent total"))

fig.show()


# In[ ]:


import plotly.express as px
fig = px.funnel_area(names=["The 1st","The 2nd", "The 3rd", "The 4th", "The 5th"],
                    values=[5, 4, 3, 2, 1])
fig.show()


# In[ ]:


from plotly import graph_objects as go

fig = go.Figure(go.Funnelarea(
    text = ["The 1st","The 2nd", "The 3rd", "The 4th", "The 5th"],
    values = [5, 4, 3, 2, 1]
    ))
fig.show()

    'data': [go.Pie(labels=labels, values=values, hole=.3, textinfo='none')],
    'layout': {
        'title': 'Statewise distribution of cases'
    }
}

# processing data for 'age wise'
bins = [0, 13, 20, 60, 110]
labels = ['Kid', 'Teen', 'Adult', 'Senior citizen']

data_age = pd.to_numeric(data['Age Bracket'], errors='coerce')
data_age = data_age.replace('NA', -1)
age_categorical = pd.cut(data_age, bins=bins, labels=labels, right=False)
age_pivot = age_categorical.value_counts()

fig_age_data = px.funnel_area(names=age_pivot.index,
                              values=age_pivot.values.flatten())

fig_age_data.update_layout(title='Age wise distribution of cases')

# processing data for 'patient current status'
status_pivot = pd.pivot_table(data,
                              values="Patient Number",
                              index=["Current Status"],
                              aggfunc=len).sort_values(by='Patient Number',
                                                       ascending=False)

labels = status_pivot.index
values = status_pivot.values.flatten()

fig_status_data = {
    'data': [go.Pie(labels=labels, values=values)],