I am trying to run the below code:
import pandas as pd
import plotly.express as px
Sample DataFrame
df = pd.DataFrame({
‘Category’: [‘A’, ‘A’, ‘B’, ‘B’],
‘Subgroup’: [‘X’, ‘Y’, ‘X’, ‘Y’],
‘Value’: [10, 15, 8, 12],
‘Flag’: [‘Winner’, ‘Loser’, ‘Loser’, ‘Winner’]
})
Create a grouped bar chart
fig = px.bar(
df,
x=‘Category’,
y=‘Value’,
color=‘Subgroup’,
barmode=‘group’,
# Use ‘Flag’ to determine which pattern to apply
pattern_shape=‘Flag’,
# Pattern shapes are applied in the order ‘Winner’, ‘Loser’, etc.
# If your data’s first Flag category is “Winner”, it will get the first shape, second gets the next, etc.
pattern_shape_sequence=[‘/’, ‘\’],
# Title for clarity
title=‘Example of pattern_shape_sequence in a grouped bar chart’
)
It is showing me the below image. How can I fix the gap between bars?
Thank you.