I want to display total
and available
bars side by side for each fruit
.
Here is the data I'm using
import plotly.express as px
data_frame = {
"fruits": ["orange", "apple", "banana", "cherry"],
"total": [10, 20, 30, 25],
"available": [7, 10, 27, 15],
}
And I used plotly.express
as follow:
fig = px.bar(
data_frame,
x="fruits",
y=["total", "available"],
color="fruits",
barmode="group", # Is ignored
)
fig.show()
However, bars are still shown in stack
mode instead. What am I missing here?
Thanks in advance.
There might be a way to do this without changing your data from wide to long format, but I think it's more intuitive to melt your dataframe so that you have
variable
andvalue
columns using:This gives you the following long format dataframe.
Then you can create the bar chart using:
This will allow plotly to differentiate the between
total
andavailable
bars within eachfruit
.