<jupyter_start><jupyter_text>Plotly - Create Vertical Barchart group **Tags:** plotly chart verticalbarchart group dataviz snippet operations image html **Author:** [<NAME>](https://www.linkedin.com/in/ACoAABCNSioBW3YZHc2lBHVG0E_TXYWitQkmwog/)  Input  Import libraries<jupyter_code>import naas
import plotly.graph_objects as go
import pandas as pd<jupyter_output><empty_output><jupyter_text>Variables<jupyter_code>title = "Sales Evolution (group)"

# Output paths
output_image = f"{title}.png"
output_html = f"{title}.html"<jupyter_output><empty_output><jupyter_text>Get data<jupyter_code>x_axis = [1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012]
y_axis_value1 = [219, 146, 112, 127, 124, 180, 236, 207, 236, 263, 350, 430, 474, 526, 488, 537, 500, 439]
y_axis_value2 = [16, 13, 10, 11, 28, 37, 43, 55, 56, 88, 105, 156, 270, 299, 340, 403, 549, 499]

df1 = pd.DataFrame(zip(x_axis, y_axis_value1), columns=["LABEL", "VALUE"])
df1["GROUPS"] = "USA"

df2 = pd.DataFrame(zip(x_axis, y_axis_value2), columns=["LABEL", "VALUE"])
df2["GROUPS"] = "Rest of world"

df = pd.concat([df1, df2])
df<jupyter_output><empty_output><jupyter_text>Model  Create Vertical Barchart stacked<jupyter_code>def create_barchart(df, label, groups, value, title):
    fig = go.Figure()
    
    list_groups = df[groups].unique()
    for group in list_groups:
        tmp_df = df[df[groups] == group]
        fig.add_trace(go.Bar(x=tmp_df[label],
                             y=tmp_df[value],
                             name=group))
    fig.update_layout(
        title=title ,
        plot_bgcolor="#ffffff",
        width=1200,
        height=800,
        xaxis_tickfont_size=14,
        legend=dict(
            bgcolor='white',
            bordercolor='white'
        ),
        barmode='group',
        bargap=0.1, # gap between bars of adjacent location coordinates.
        bargroupgap=0.1 # gap between bars of the same location coordinate.
    )
    config = {'displayModeBar': False}
    fig.show(config=config)
    return df

fig = create_barchart(df, label="LABEL", groups="GROUPS", value="VALUE", title=title)<jupyter_output><empty_output><jupyter_text>Output  Export in PNG and HTML<jupyter_code>fig.write_image(output_image, width=1200)
fig.write_html(output_html)<jupyter_output><empty_output><jupyter_text>Generate shareable assets<jupyter_code>link_image = naas.asset.add(output_image)
link_html = naas.asset.add(output_html, {"inline":True})

#-> Uncomment the line below to remove your assets
# naas.asset.delete(output_image)
# naas.asset.delete(output_html)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.13275340393343418, 'fraction_numerical': 0.07564296520423601, 'mean_word_length': 4.408997955010225, 'pattern_counts': {'":': 1, '<': 26, '<?xml version=': 0, '>': 27, 'https://': 1, 'lorem ipsum': 0, 'www.': 1, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '6', 'dir': 'jupyter-structured-clean-dedup', 'id': '76083', 'license': 'BSD-3-Clause', 'n_tokens_mistral': 1125, 'n_tokens_neox': 935, 'n_words': 200, 'path': 'Plotly/Plotly_Create_Vertical_Barchart_group.ipynb', 'repo_name': 'techthiyanes/awesome-notebooks', 'size': '2653'}