Open
Description
It appears the feature to allow offsetgroup to work with stacked/relative bar traces (plotly/plotly.js#7009) does not work with horizontally oriented bar traces. Taking the example from the documentation
https://plotly.com/python/bar-charts/#grouped-stacked-bar-chart
if I reverse the x and y axis and set orientation to 'h', the traces are not separated by the different offset groups:
import plotly.graph_objects as go
data = [
go.Bar(
y=['Q1', 'Q2', 'Q3', 'Q4'],
x=[150, 200, 250, 300],
name='New York',
offsetgroup="USA",
orientation='h'
),
go.Bar(
y=['Q1', 'Q2', 'Q3', 'Q4'],
x=[180, 220, 270, 320],
name='Boston',
offsetgroup="USA",
orientation='h'
),
go.Bar(
y=['Q1', 'Q2', 'Q3', 'Q4'],
x=[130, 170, 210, 260],
name='Montreal',
offsetgroup="Canada",
orientation='h'
),
go.Bar(
y=['Q1', 'Q2', 'Q3', 'Q4'],
x=[160, 210, 260, 310],
name='Toronto',
offsetgroup="Canada",
orientation='h'
)
]
layout = go.Layout(
title={
'text': 'Quarterly Sales by City, Grouped by Country'
},
yaxis={
'title': {
'text': 'Quarter'
}
},
xaxis={
'title': {
'text': 'Sales'
}
},
barmode='stack'
)
fig = go.Figure(data=data, layout=layout)
fig.show()
Using plotly 6.0.0.
Metadata
Metadata
Assignees
Type
Projects
Milestone
Relationships
Development
No branches or pull requests
Activity
gvwilson commentedon Feb 3, 2025
Thanks for the report @neutralino - I'll see if we can find someone to work on this in the next cycle. If not, we can prioritize a pull request if you or someone else is able to put one together. Thanks - @gvwilson
my-tien commentedon Feb 6, 2025
Interestingly, this seems to only be the case for plotly.py, in plotly.js it works fine:
https://codepen.io/toffi-fee/pen/ByBgbyX
gvwilson commentedon Feb 6, 2025
nice catch @my-tien - I'll see if we can find someone to dig into it in the next cycle.
my-tien commentedon Feb 7, 2025
@gvwilson I am quite curious why there is a difference in behaviour, so I'm also digging into it a bit.
@neutralino Just to make sure: Where did you try this code? Because the corresponding renderer extension in VSCode isn't yet upgraded to plotly.js 3.0.0 see here. But that means that neither rotation should display correctly in VSCode.
But if you avoid the VSCode renderer by e.g. picking another renderer or saving the image to png, it looks correct for me:
neutralino commentedon Feb 7, 2025
Ah I see, thanks @my-tien! Yes, I was trying it from both VSCode and PyCharm's notebook integration. Using the browser as the renderer works for me as well.
pendyurinandrey commentedon Mar 9, 2025
I have the same issue, but in the Jupyter environment. I tried plotly 6.0.0 and following Jupyter setup:
When I used code from the docs https://plotly.com/python/bar-charts/#grouped-stacked-bar-chart, I got bar charts without grouping by offsetgroup.
my-tien commentedon Mar 10, 2025
Hi @pendyurinandrey
the issue isn't with the plotly.py version but with the plotly.js dependency that the vscode-notebook-renderer uses. It is still at 2.35.2. The new feature was introduced in plotly.js 3.0.0 and plotly.py uses plotly.js under the hood for rendering: https://github.com/microsoft/vscode-notebook-renderers/blob/0ef2be324acaf56a505db81701da6bea4e727ebd/package.json#L168