Skip to content

Grouped Stacked Bar Chart - offsetgroup not being respected #5100

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

Open
Mad-Mint opened this issue Mar 19, 2025 · 2 comments
Open

Grouped Stacked Bar Chart - offsetgroup not being respected #5100

Mad-Mint opened this issue Mar 19, 2025 · 2 comments
Labels
bug something broken P2 considered for next cycle

Comments

@Mad-Mint
Copy link

Hello, I was trying to make a grouped stack bar chart with plotly 6.0.0 and 6.0.1 and both fail to respect offsetgroup. Running the example in the documentation does not yield the documentation's result.

import plotly.graph_objects as go

data = [
    go.Bar(
        x=['Q1', 'Q2', 'Q3', 'Q4'],
        y=[150, 200, 250, 300],
        name='New York',
        offsetgroup="USA"
    ),
    go.Bar(
        x=['Q1', 'Q2', 'Q3', 'Q4'],
        y=[180, 220, 270, 320],
        name='Boston',
        offsetgroup="USA"
    ),
    go.Bar(
        x=['Q1', 'Q2', 'Q3', 'Q4'],
        y=[130, 170, 210, 260],
        name='Montreal',
        offsetgroup="Canada"
    ),
    go.Bar(
        x=['Q1', 'Q2', 'Q3', 'Q4'],
        y=[160, 210, 260, 310],
        name='Toronto',
        offsetgroup="Canada"
    )
]

layout = go.Layout(
    title={
        'text': 'Quarterly Sales by City, Grouped by Country'
    },
    xaxis={
        'title': {
            'text': 'Quarter'
        }
    },
    yaxis={
        'title': {
            'text': 'Sales'
        }
    },
    barmode='stack'
)

fig = go.Figure(data=data, layout=layout)

fig.show()

Output:
Image

Expected Output:
Image

It looks like they are using different plotly.js versions but I can not find out how to update the plotly.js version to v3 with the python package

@gvwilson
Copy link
Contributor

Hi @Mad-Mint - the plotly.js versioning should happen automatically. Can you please post this in https://community.plotly.com/ ? Tech support questions usually get a faster answer there. Thanks - @gvwilson

@gvwilson gvwilson added bug something broken P2 considered for next cycle labels Mar 19, 2025
@pSpitzner
Copy link

pSpitzner commented Apr 24, 2025

I can confirm this problem, and isolated it a bit more, on my setup.

  • The plotly python package ships its own plotly js version. For 6.0.1 that is 3.0.1.
  • For me, it works when running the example in an interactive python terminal. In this case, plotly.js v3.0.1 is used.
  • In vscode, it seems the extension Jupyter Notebook Renderers has not been updated yet -> plotly.js v2.
    The extension was enabled on my system by default when installing jupyter for vscode.
  • disabeling it solved the problem, and i still get inline renders for plotly with
import plotly.io as pio
import plotly

pio.renderers.default = "jupyterlab"
plotly.offline.init_notebook_mode()

fig = ...
plotly.offline.plot(fig)

I only tested this with vscode, but this could also be an issue with jupyter lab.
hope this helps!

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