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 and alignmentgroup #211

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
152 changes: 152 additions & 0 deletions python/bar-charts.md
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'))
Copy link
Contributor

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.


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 = {
Copy link
Contributor

Choose a reason for hiding this comment

The 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`.
Copy link
Contributor

Choose a reason for hiding this comment

The 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
141 changes: 141 additions & 0 deletions python/box-plots.md
Original file line number Diff line number Diff line change
@@ -398,6 +398,147 @@ fig.update_layout(
showlegend=False
)

fig.show()
```
### Control Box Position in Different Subplots

To control box plot positional range among several subplots, set the same axes to the same [alignmentgroup](https://plot.ly/python/reference/#box-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/#box-offsetgroup).

```python
import plotly.graph_objects as go

fig = go.Figure(go.Box(
alignmentgroup = "a",
offsetgroup = 0,
y = [2,6,10,2,7,1,5],
x = [1,1,1,1,1,1,1],
xaxis = 'x',
yaxis = 'y2'))

fig.add_trace(go.Box(
y = [2,6,10,2,7,1,5],
x = [1,1,1,1,1,1,1],
alignmentgroup = "a",
offsetgroup = 1,
xaxis = 'x',
yaxis = 'y2'))

fig.add_trace(go.Box(
alignmentgroup = "a",
offsetgroup = 0,
y = [2,6,10,2,7,1,5],
x = [1,1,1,1,1,1,1],
xaxis = 'x',
yaxis = 'y'))

fig.update_layout(
yaxis2 = {'domain': [.55,1]},
yaxis = {'domain': [0,.45]},
boxmode = 'group')

fig.show()
```
Let's compare the impact of `offsetgroup` vs. `alignmentgroup`.

```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 = 'y2'))

fig.add_trace(go.Bar(
alignmentgroup = "b",
offsetgroup = 1,
x = [1,2,3],
y = [2,3,4],
xaxis = 'x2',
yaxis = 'y'))

fig.add_trace(go.Bar(
alignmentgroup = "a",
offsetgroup = 1,
x = [1,2,3],
y = [2,3,4],
xaxis = 'x2',
yaxis = 'y2'))

fig.add_trace(go.Bar(
alignmentgroup = "a",
offsetgroup = 0,
x = [1,2,3],
y = [2,3,4],
xaxis = 'x3',
yaxis = 'y2'))

fig.add_trace(go.Bar(
alignmentgroup = "a",
offsetgroup = 1,
x = [1,2,3],
y = [2,3,4],
xaxis = 'x3',
yaxis = 'y'))

fig.add_trace(go.Bar(
alignmentgroup = "a",
offsetgroup = 1,
x = [1,2,3],
y = [2,3,4],
xaxis = 'x3',
yaxis = 'y2'))

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'})

fig.show()
```

Loading
Oops, something went wrong.