Grouped bar charts do not work with multiple Y axes
Hi,
it seems that having a graph with group bar charts and multiple Y axis doesn't work. I've created the trivial graph https://plot.ly/~iustin/4/grouped-bar-chart-with-multiple-axes/ and tested that switching Col3 between yaxis and yaxis2 also toggles between grouped and non-grouped.
Is this intended? Logically speaking, it makes sense to be able to do this, so I guess it's only a technical limitation.
@real-np yeah if you can attach some source code for that it would be great as I can't seem to figure out how to do two separate bar charts with two y axes
this issue has been on for 3 years, is their any plans to include it in the near future?
+1 Workaround looks off (the hidden data still shows kind of and shifts the sizing of things), box plot has the same issue. Grouping and multiple y axes could be accommodated in overlay mode for box types if explicit width and offset were available as they are for bar types.
Hello, does Plotly have an ETA to solve this issue?
The code below would be a workaround if you really need grouped bar charts with multiple axes. Here trace2 stacks on trace 0, trace 3 stacks on trace 1.
trace0 = go.Bar(x = ['a','b','c'], y=[10,20,30])
trace1 = go.Bar(x = ['a','b','c'], y=[0],showlegend=False,hoverinfo='none')
trace2 = go.Bar(x = ['a','b','c'], y=[0], yaxis='y2',showlegend=False,hoverinfo='none')
trace3 = go.Bar(x = ['a','b','c'], y=[30,35,60], yaxis='y2')
data = [trace0,trace1,trace2,trace3]#,trace2
layout = go.Layout(barmode='group',
legend=dict(x=0, y=1.1,orientation="h"),
yaxis=dict(title='2017 Increase(%)'),
yaxis2=dict(title = 'Transaction Count 2016(AUD)',
overlaying = 'y',
side='right'))
fig = go.Figure(data=data, layout=layout)
offline.iplot(fig)
+1 on looking for native solution to this. @XianjingFan in the meantime that workaround did the trick.
Also having the same issue. Grouping works fine with 1 axes but when you add another, they overlay on top of each other.
PR https://github.com/plotly/plotly.js/pull/3529 introduced (set to be released in v1.45.0) will introduced a way around to default behavior using a new bar attribute: offsetgroup.
See https://codepen.io/etpinard/pen/yZQYzq?editors=1010 for an example.
PR #3529 introduced (set to be released in
v1.45.0) will introduced a way around to default behavior using a new bar attribute:offsetgroup.See https://codepen.io/etpinard/pen/yZQYzq?editors=1010 for an example.
Hi etpinard,
is it intended that the yaxis and yaxis2 grids are not aligned? I thought {"anchor":"x"} was doing that. I also have unaligned grid axis with an horizontal bar chart I made (see below, sorry did not make it with codepen):
{'data': [{'name': 'some_metric',
'offsetgroup': '0',
'orientation': 'h',
'x': array([0.61354582, 0.33720317]),
'xaxis': 'x',
'y': ['orangoutans', 'chimpanzee'],
'type': 'bar',
'uid': 'fe706d20-fccc-427c-8931-760de1217db7'},
{'name': 'another_metric',
'offsetgroup': '1',
'orientation': 'h',
'x': array([0.61354582, 0.04379947]),
'xaxis': 'x',
'y': ['orangoutans', 'chimpanzee'],
'type': 'bar',
'uid': '5cb8bafe-c455-4df3-ad9e-445b81f68682'},
{'name': 'yet_another_metric',
'offsetgroup': '2',
'orientation': 'h',
'x': array([0.00398406, 0.01002639]),
'xaxis': 'x',
'y': ['orangoutans', 'chimpanzee'],
'type': 'bar',
'uid': 'fc5e2de7-aa67-4df5-8f0b-03c748f7bb2e'},
{'marker': {'color': '#7f8793'},
'name': 'some_metric_on_other_axis',
'offsetgroup': '3',
'orientation': 'h',
'x': array([ 251, 1895], dtype=int64),
'xaxis': 'x2',
'y': ['orangoutans', 'chimpanzee'],
'type': 'bar',
'uid': '73351dfa-03d7-499e-afe4-ff4f9f851f14'}],
'layout': {'bargap': 0,
'bargroupgap': 0,
'height': 100,
'margin': {'autoexpand': True, 'l': 325.5, 'pad': 10},
'title': {'text': 'Dual axis horizontal'},
'xaxis': {'anchor': 'y',
'automargin': True,
'overlaying': 'x2',
'side': 'top'},
'xaxis2': {'anchor': 'y', 'automargin': True, 'side': 'bottom'}}}

@ThibTrip please use https://community.plot.ly/c/plotly-js for questions of the likes. Thank you!
@etpinard's demo using latest plotly.js seems to be working fine. Wondering if that workaround is enough to close this issue?
@archmoj for that specific case it's working OK, but if you e.g. omit orangutans from the second trace, they overlap weirdly again.
This issue has been tagged with NEEDS SPON$OR
A community PR for this feature would certainly be welcome, but our experience is deeper features like this are difficult to complete without the Plotly maintainers leading the effort.
Sponsorship range: $10k-$15k
What Sponsorship includes:
- Completion of this feature to the Sponsor's satisfaction, in a manner coherent with the rest of the Plotly.js library and API
- Tests for this feature
- Long-term support (continued support of this feature in the latest version of Plotly.js)
- Documentation at plotly.com/javascript
- Possibility of integrating this feature with Plotly Graphing Libraries (Python, R, F#, Julia, MATLAB, etc)
- Possibility of integrating this feature with Dash
- Feature announcement on community.plotly.com with shout out to Sponsor (or can remain anonymous)
- Gratification of advancing the world's most downloaded, interactive scientific graphing libraries (>50M downloads across supported languages)
Please include the link to this issue when contacting us to discuss.
@real-np Hi, I have tried and looked up for many methods to plot such figure, but I still can't overlay two grouped barchart. Can you explain how you do it? Many thanks.
Hi - this issue has been sitting for a while, so as part of our effort to tidy up our public repositories I'm going to close it. If it's still a concern, we'd be grateful if you could open a new issue (with a short reproducible example if appropriate) so that we can add it to our stack. Cheers - @gvwilson