-
Notifications
You must be signed in to change notification settings - Fork 1
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 and alignmentgroup #211
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -304,6 +304,158 @@ fig.update_layout( | |
fig.show() | ||
``` | ||
|
||
### Control Bar Position in Different Subplots | ||
|
||
To control bars positional range among several subplots, set the same axes to the same [alignmentgroup](https://plot.ly/python/reference/#bar-alignmentgroup). In the following example we have two subplots sharing an x axis with two bar traces (trace0, trace1) on the top, and one bar trace (trace2) on the bottom, that all are aligned by setting the same `alignmentgroup`. | ||
You also can line up bars of the same positional coordinate by setting [offsetgroup](https://plot.ly/python/reference/#bar-offsetgroup). | ||
|
||
```python | ||
import plotly.graph_objects as go | ||
|
||
fig = go.Figure(go.Bar( | ||
alignmentgroup = "a", | ||
offsetgroup = 0, | ||
x = [1,2,3], | ||
y = [2,3,4], | ||
xaxis = 'x', | ||
yaxis = 'y2')) | ||
|
||
fig.add_trace(go.Bar( | ||
alignmentgroup = "a", | ||
offsetgroup = 1, | ||
x = [1,2,3], | ||
y = [2,3,4], | ||
xaxis = 'x', | ||
yaxis = 'y2')) | ||
|
||
fig.add_trace(go.Bar( | ||
alignmentgroup = "a", | ||
offsetgroup = 1, | ||
x = [1,2,3], | ||
y = [2,3,4], | ||
xaxis = 'x', | ||
yaxis = 'y')) | ||
|
||
|
||
fig.update_layout( | ||
xaxis = { | ||
'anchor': 'y'}, | ||
yaxis2 = { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. here could you define y before defining y2? No big deal, but it's just that these examples can be a bit long so it helps if things are always in an expected order. Same for the other examples. |
||
'domain': [.55,1], | ||
'anchor': 'x'}, | ||
yaxis = { | ||
'domain': [0,.45], | ||
'anchor': 'x'}) | ||
|
||
fig.show() | ||
``` | ||
Let's compare the impact of `offsetgroup` vs. `alignmentgroup`. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could you please make this a title (Offsetgroup vs alignmentgroup) so that it appears in the nav bar and it's possible to link directly to this example? Same for the other traces. |
||
|
||
```python | ||
|
||
import plotly.graph_objects as go | ||
|
||
fig = go.Figure(go.Bar( | ||
alignmentgroup = "a", | ||
offsetgroup = 0, | ||
x = [1,2,3], | ||
y = [2,3,4], | ||
xaxis = 'x', | ||
yaxis = 'y2')) | ||
|
||
fig.add_trace(go.Bar( | ||
alignmentgroup = "a", | ||
offsetgroup = 1, | ||
x = [1,2,3], | ||
y = [2,3,4], | ||
xaxis = 'x', | ||
yaxis = 'y2')) | ||
|
||
fig.add_trace(go.Bar( | ||
alignmentgroup = "a", | ||
offsetgroup = 2, | ||
x = [1,2,3], | ||
y = [2,3,4], | ||
xaxis = 'x', | ||
yaxis = 'y')) | ||
|
||
fig.add_trace(go.Bar( | ||
alignmentgroup = "a", | ||
offsetgroup = 0, | ||
x = [1,2,3], | ||
y = [2,3,4], | ||
xaxis = 'x2', | ||
yaxis = 'y3')) | ||
|
||
fig.add_trace(go.Bar( | ||
alignmentgroup = "b", | ||
offsetgroup = 1, | ||
x = [1,2,3], | ||
y = [2,3,4], | ||
xaxis = 'x2', | ||
yaxis = 'y4')) | ||
|
||
fig.add_trace(go.Bar( | ||
alignmentgroup = "a", | ||
offsetgroup = 1, | ||
x = [1,2,3], | ||
y = [2,3,4], | ||
xaxis = 'x2', | ||
yaxis = 'y3')) | ||
|
||
fig.add_trace(go.Bar( | ||
alignmentgroup = "a", | ||
offsetgroup = 0, | ||
x = [1,2,3], | ||
y = [2,3,4], | ||
xaxis = 'x3', | ||
yaxis = 'y5')) | ||
|
||
fig.add_trace(go.Bar( | ||
alignmentgroup = "a", | ||
offsetgroup = 1, | ||
x = [1,2,3], | ||
y = [2,3,4], | ||
xaxis = 'x3', | ||
yaxis = 'y6')) | ||
|
||
fig.add_trace(go.Bar( | ||
alignmentgroup = "a", | ||
offsetgroup = 1, | ||
x = [1,2,3], | ||
y = [2,3,4], | ||
xaxis = 'x3', | ||
yaxis = 'y5')) | ||
|
||
fig.update_layout( | ||
xaxis = { | ||
'domain': [0, .35], | ||
'anchor': 'y', | ||
'title': "=alignment<br>≠offset"}, | ||
xaxis2 = { | ||
'domain': [.42, .65], | ||
'title': "≠alignment<br>=offset", | ||
'anchor': 'y' | ||
}, | ||
xaxis3 = { | ||
'domain': [.72, 1], | ||
'title': "=alignment<br>=offset", | ||
'anchor': 'y' | ||
}, | ||
yaxis2 = { | ||
'domain': [.55,1], | ||
'anchor': 'x'}, | ||
yaxis = { | ||
'domain': [0,.45], | ||
'anchor': 'x'}, | ||
yaxis3 = {'domain': [.55,1], 'anchor': 'x2'}, | ||
yaxis4 = {'domain': [0, .5], 'anchor': 'x2'}, | ||
yaxis5 = {'domain': [.55, 1], 'anchor': 'x3'}, | ||
yaxis6 = {'domain': [0, .5], 'anchor': 'x3'}) | ||
|
||
fig.show() | ||
``` | ||
|
||
### Bar Chart with Relative Barmode | ||
|
||
With "relative" barmode, the bars are stacked on top of one another, with negative values | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
could you please define traces so that they use first "y" then "y2" etc.? The order can be a bit confusing.