Plotly stacked bar chart

In this Plotly tutorial, you will learn how to plot a stacked bar chart in Python. You can use px.bar() function to plot the bar chart.

# Import Plotly Module
import plotly.express as px

# Import Dataset
dataset = px.data.gapminder().query("continent=='Oceania'")

# Stacked Bar Chart
plot = px.bar(dataset, x="country", y="pop", color="year", barmode="stack", title='Plotly Stacked Bar Chart', height=400, width=800)

# Show the Plot
plot.show()

Output:

Plotly stacked bar chart

Free learning resources: AiHintsCodeAllow

Leave a Comment

Your email address will not be published.