Interactive Bar Charts
Basic bar chart
Interactive bar
import pandas as pd
import plotly.express as px
df = pd.DataFrame({
"city": ["Pune", "Delhi", "Mumbai", "Bengaluru"],
"sales": [120, 180, 90, 160],
})
fig = px.bar(df, x="city", y="sales", title="Sales by city")
fig.show()Interactive bar
import pandas as pd
import plotly.express as px
df = pd.DataFrame({
"city": ["Pune", "Delhi", "Mumbai", "Bengaluru"],
"sales": [120, 180, 90, 160],
})
fig = px.bar(df, x="city", y="sales", title="Sales by city")
fig.show()Sorted bars
Sorted bar
import pandas as pd
import plotly.express as px
df = pd.DataFrame({
"city": ["Pune", "Delhi", "Mumbai", "Bengaluru"],
"sales": [120, 180, 90, 160],
}).sort_values("sales", ascending=False)
fig = px.bar(df, x="city", y="sales", title="Sales by city (sorted)")
fig.show()Sorted bar
import pandas as pd
import plotly.express as px
df = pd.DataFrame({
"city": ["Pune", "Delhi", "Mumbai", "Bengaluru"],
"sales": [120, 180, 90, 160],
}).sort_values("sales", ascending=False)
fig = px.bar(df, x="city", y="sales", title="Sales by city (sorted)")
fig.show()Horizontal bar
Horizontal
import plotly.express as px
fig = px.bar(df, x="sales", y="city", orientation="h", title="Sales by city")
fig.show()Horizontal
import plotly.express as px
fig = px.bar(df, x="sales", y="city", orientation="h", title="Sales by city")
fig.show()If this helped you, consider buying me a coffee ☕
Buy me a coffeeWas this page helpful?
Let us know how we did
