From 3de41cb90db3d6f33d7cb907fb131d3a0b0eb14a Mon Sep 17 00:00:00 2001
From: mahdis-z <maahhddiiss@gmail.com>
Date: Fri, 22 Nov 2019 15:40:33 -0500
Subject: [PATCH] offsetgroup and alignmentgroup

---
 python/bar-charts.md | 152 +++++++++++++++++++++++++++++++++++++++++++
 python/box-plots.md  | 141 +++++++++++++++++++++++++++++++++++++++
 python/violin.md     | 123 ++++++++++++++++++++++++++++++++++
 3 files changed, 416 insertions(+)

diff --git a/python/bar-charts.md b/python/bar-charts.md
index 7928f9489..d714f4e63 100644
--- a/python/bar-charts.md
+++ b/python/bar-charts.md
@@ -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 = {
+        'domain': [.55,1],
+        'anchor': 'x'},
+    yaxis = {
+        'domain': [0,.45],
+        'anchor': 'x'})
+
+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 = '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
diff --git a/python/box-plots.md b/python/box-plots.md
index 126e8c9b4..811e733e6 100644
--- a/python/box-plots.md
+++ b/python/box-plots.md
@@ -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()
 ```
 
diff --git a/python/violin.md b/python/violin.md
index aed469fee..680596b4c 100644
--- a/python/violin.md
+++ b/python/violin.md
@@ -157,6 +157,129 @@ fig.update_layout(violinmode='group')
 fig.show()
 ```
 
+### Control Violin Position in Different Subplots
+
+To control violins positional range among several subplots, set the same axes to the same [alignmentgroup](https://plot.ly/python/reference/#violin-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/#violin-offsetgroup).
+
+```python
+import plotly.graph_objects as go
+import pandas as pd
+
+df = pd.read_csv("https://raw.githubusercontent.com/plotly/datasets/master/violin_data.csv")
+
+fig = go.Figure()
+fig.add_trace(go.Violin(x=df['day'][ df['sex'] == 'Male' ],
+                        y=df['total_bill'][df['sex'] == 'Male' ],
+                        alignmentgroup = 'a',
+                        offsetgroup = 0,
+                        xaxis = 'x',
+                        yaxis = 'y'))
+            
+fig.add_trace(go.Violin(x=df['day'][ df['sex'] == 'Female' ],
+                        y=df['total_bill'][df['sex'] == 'Male' ], 
+                        alignmentgroup = 'a',
+                        offsetgroup = 1,
+                        xaxis = 'x',
+                        yaxis = 'y'))
+
+fig.add_trace(go.Violin(x=df['day'][ df['sex'] == 'Male' ],
+                        y=df['total_bill'][df['sex'] == 'Male' ],
+                        alignmentgroup = 'a',
+                        offsetgroup = 0,
+                        xaxis = 'x',
+                        yaxis = 'y2'))
+
+fig.update_layout(
+    violinmode='group',
+    yaxis = {'domain': [.55,1]},
+    yaxis2 = {'domain': [0,.45]})
+
+fig.show()
+```
+Let's compare the impact of `offsetgroup` vs. `alignmentgroup`. 
+
+```python
+import plotly.graph_objects as go
+import pandas as pd
+
+df = pd.read_csv("https://raw.githubusercontent.com/plotly/datasets/master/violin_data.csv")
+
+fig = go.Figure()
+
+fig.add_trace(go.Violin(x=['A','A'],
+                        y=[1,2,3],
+                        alignmentgroup = 'a',
+                        offsetgroup = 0,
+                        xaxis = 'x',
+                        yaxis = 'y'))
+            
+fig.add_trace(go.Violin(x=['A','A'],
+                        y=[1,2,3],
+                        alignmentgroup = 'a',
+                        offsetgroup = 1,
+                        xaxis = 'x',
+                        yaxis = 'y'))
+
+fig.add_trace(go.Violin(x=['A','A'],
+                        y=[1,2,3],
+                        alignmentgroup = 'a',
+                        offsetgroup = 2,
+                        xaxis = 'x',
+                        yaxis = 'y2'))
+
+fig.add_trace(go.Violin(x=['A','A'],
+                        y=[1,2,3],
+                        alignmentgroup = 'a',
+                        offsetgroup = 0,
+                        xaxis = 'x2',
+                        yaxis = 'y'))
+            
+fig.add_trace(go.Violin(x=['A','A'],
+                        y=[1,2,3],
+                        alignmentgroup = 'a',
+                        offsetgroup = 1,
+                        xaxis = 'x2',
+                        yaxis = 'y'))
+
+fig.add_trace(go.Violin(x=['A','A'],
+                        y=[1,2,3],
+                        alignmentgroup = 'b',
+                        offsetgroup = 1,
+                        xaxis = 'x2',
+                        yaxis = 'y2'))
+
+fig.add_trace(go.Violin(x=['A','A'],
+                        y=[1,2,3],
+                        alignmentgroup = 'a',
+                        offsetgroup = 0,
+                        xaxis = 'x3',
+                        yaxis = 'y'))
+            
+fig.add_trace(go.Violin(x=['A','A'],
+                        y=[1,2,3],
+                        alignmentgroup = 'a',
+                        offsetgroup = 1,
+                        xaxis = 'x3',
+                        yaxis = 'y'))
+
+fig.add_trace(go.Violin(x=['A','A'],
+                        y=[1,2,3],
+                        alignmentgroup = 'a',
+                        offsetgroup = 1,
+                        xaxis = 'x3',
+                        yaxis = 'y2'))
+fig.update_layout(
+    showlegend = False,
+    violinmode = 'group',
+    yaxis = {'domain': [.55,1]},
+    yaxis2 = {'domain': [0,.45]},
+    xaxis = {'domain': [0,.30], 'anchor': 'y2', 'title': "=alignment<br>≠offset"},
+    xaxis2 = {'domain': [.35, .65], 'anchor': 'y2', 'title': "≠alignment<br>=offset"},
+    xaxis3 = {'domain': [.7,1], 'anchor': 'y2', 'title': "=alignment<br>=offset"})
+
+fig.show()
+```
 #### Split Violin Plot
 
 ```python