Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

offsetgroup with horizontally stacked/relative bar traces #5007

Open
neutralino opened this issue Feb 3, 2025 · 5 comments
Open

offsetgroup with horizontally stacked/relative bar traces #5007

neutralino opened this issue Feb 3, 2025 · 5 comments
Labels
bug something broken P2 considered for next cycle

Comments

@neutralino
Copy link

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()

Image

Using plotly 6.0.0.

@gvwilson gvwilson added bug something broken P2 considered for next cycle labels Feb 3, 2025
@gvwilson
Copy link
Contributor

gvwilson commented 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
Copy link

my-tien commented 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

Image

@gvwilson
Copy link
Contributor

gvwilson commented 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
Copy link

my-tien commented 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:

# try another renderer
fig.show("browser") 
# save to png
with open("mytest.png", "wb") as f:
    f.write(pio.to_image(fig))

@neutralino
Copy link
Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug something broken P2 considered for next cycle
Projects
None yet
Development

No branches or pull requests

3 participants