Skip to content

Commit f39d0ca

Browse files
author
mahdis-z
committed
bingroup
1 parent 49e39b1 commit f39d0ca

File tree

2 files changed

+49
-0
lines changed

2 files changed

+49
-0
lines changed

doc/python/2D-Histogram.md

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,33 @@ fig = go.Figure(go.Histogram2d(x=x, y=y, histnorm='probability',
7070
))
7171
fig.show()
7272
```
73+
### Sharing bin settings between 2D Histograms
74+
This example shows how to use [bingroup](https://plot.ly/python/reference/#histogram-bingroup) attribute to have a compatible bin settings for both histograms. To define `start`, `end` and `size` value of x-axis and y-axis seperatly, set [ybins](https://plot.ly/python/reference/#histogram2dcontour-ybins) and `xbins`.
75+
76+
```python
77+
import plotly.graph_objects as go
78+
from plotly.subplots import make_subplots
79+
fig = make_subplots(2,2)
80+
fig.add_trace(go.Histogram2d(
81+
x = [ 1, 2, 2, 3, 4 ],
82+
y = [ 1, 2, 2, 3, 4 ],
83+
xbins = {'start':1, 'size':1}), 1,1)
84+
fig.add_trace(go.Histogram2d(
85+
x = [ 4, 5, 5, 5, 6 ],
86+
y = [ 4, 5, 5, 5, 6 ],
87+
ybins = {'start': 3, 'size': 1}),1,2)
88+
fig.add_trace(go.Histogram2d(
89+
x = [ 1, 2, 2, 3, 4 ],
90+
y = [ 1, 2, 2, 3, 4 ],
91+
bingroup = 1,
92+
xbins = {'start':1, 'size':1}), 2,1)
93+
fig.add_trace(go.Histogram2d(
94+
x = [ 4, 5, 5, 5, 6 ],
95+
y = [ 4, 5, 5, 5, 6 ],
96+
bingroup = 1,
97+
ybins = {'start': 3, 'size': 1}),2,2)
98+
fig.show()
99+
```
73100

74101
### 2D Histogram Overlaid with a Scatter Chart ###
75102

doc/python/histograms.md

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -350,6 +350,28 @@ fig1.show()
350350
fig2.show()
351351
```
352352

353+
### Share bins between histograms
354+
In this example both histograms have a compatible bin settings using [bingroup](https://plot.ly/python/reference/#histogram-bingroup) attribute. Note that traces on the same subplot, and with the same `barmode` ("stack", "relative", "group") are forced into the same `bingroup`, however traces with `barmode = "overlay"` and on different axes (of the same axis type) can have compatible bin settings. Histogram and [histogram2d](https://plot.ly/python/2D-Histogram/) trace can share the same `bingroup`.
355+
356+
```python
357+
import plotly.graph_objects as go
358+
import numpy as np
359+
360+
fig = go.Figure(go.Histogram(
361+
x=np.random.randint(7, size=100),
362+
bingroup=1))
363+
364+
fig.add_trace(go.Histogram(
365+
x=np.random.randint(7, size=20),
366+
bingroup=1))
367+
368+
fig.update_layout(
369+
barmode="overlay",
370+
bargap=0.1)
371+
372+
fig.show()
373+
```
374+
353375
### Dash Example
354376

355377

0 commit comments

Comments
 (0)