Grouped Stacked Bar Chart - offsetgroup not being respected
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:
Expected Output:
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
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
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!
I can confirm that disabling the VSCode extenstion "Jupyter Notebook Renderers" workarounds the problem.