Skip to content

Commit fc44c19

Browse files
author
“mahdis-z”
committed
bingroup
1 parent 5ceaaeb commit fc44c19

File tree

2 files changed

+56
-10
lines changed

2 files changed

+56
-10
lines changed

python/2D-Histogram.md

+26-2
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ jupyter:
66
extension: .md
77
format_name: markdown
88
format_version: '1.1'
9-
jupytext_version: 1.1.1
9+
jupytext_version: 1.2.1
1010
kernelspec:
1111
display_name: Python 3
1212
language: python
@@ -20,7 +20,7 @@ jupyter:
2020
name: python
2121
nbconvert_exporter: python
2222
pygments_lexer: ipython3
23-
version: 3.6.7
23+
version: 3.7.3
2424
plotly:
2525
description: How to make 2D Histograms in Python with Plotly.
2626
display_as: statistical
@@ -71,6 +71,30 @@ fig = go.Figure(go.Histogram2d(x=x, y=y, histnorm='probability',
7171
fig.show()
7272
```
7373

74+
### 2D Histogram Share Binning
75+
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`.
76+
77+
```python
78+
import plotly.graph_objects as go
79+
from plotly.subplots import make_subplots
80+
81+
fig = make_subplots(1,2)
82+
83+
fig.add_trace(go.Histogram2d(
84+
x = [ 1, 2, 2, 3, 4 ],
85+
y = [ 1, 2, 2, 3, 4 ],
86+
bingroup = 1,
87+
xbins = {'start':1, 'size':1}), 1,1)
88+
89+
fig.add_trace(go.Histogram2d(
90+
x = [ 4, 5, 5, 5, 6 ],
91+
y = [ 4, 5, 5, 5, 6 ],
92+
bingroup = 1,
93+
ybins = {'start': 3, 'size': 1}),1,2)
94+
95+
fig.show()
96+
```
97+
7498
### 2D Histogram Overlaid with a Scatter Chart ###
7599

76100
```python

python/histograms.md

+30-8
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ jupyter:
66
extension: .md
77
format_name: markdown
88
format_version: '1.1'
9-
jupytext_version: 1.1.1
9+
jupytext_version: 1.2.1
1010
kernelspec:
1111
display_name: Python 3
1212
language: python
@@ -20,7 +20,7 @@ jupyter:
2020
name: python
2121
nbconvert_exporter: python
2222
pygments_lexer: ipython3
23-
version: 3.6.7
23+
version: 3.7.3
2424
plotly:
2525
description: How to make Histograms in Python with Plotly.
2626
display_as: statistical
@@ -297,27 +297,27 @@ x = ['1970-01-01', '1970-01-01', '1970-02-01', '1970-04-01', '1970-01-02',
297297
fig = make_subplots(rows=3, cols=2)
298298

299299
trace0 = go.Histogram(x=x, nbinsx=4)
300-
trace1 = go.Histogram(x=x, nbinsx = 8)
300+
trace1 = go.Histogram(x=x, nbinsx=8)
301301
trace2 = go.Histogram(x=x, nbinsx=10)
302-
trace3 = go.Histogram(x=x,
302+
trace3 = go.Histogram(x=x,bingroup=1,
303303
xbins=dict(
304304
start='1969-11-15',
305305
end='1972-03-31',
306306
size='M18'), # M18 stands for 18 months
307-
autobinx=False
307+
308308
)
309-
trace4 = go.Histogram(x=x,
309+
trace4 = go.Histogram(x=x,bingroup=1,
310310
xbins=dict(
311311
start='1969-11-15',
312312
end='1972-03-31',
313313
size='M4'), # 4 months bin size
314-
autobinx=False
314+
315315
)
316316
trace5 = go.Histogram(x=x,
317317
xbins=dict(
318318
start='1969-11-15',
319319
end='1972-03-31',
320-
size= 'M2'), # 2 months
320+
size='M2'), # 2 months
321321
autobinx = False
322322
)
323323

@@ -331,6 +331,28 @@ fig.append_trace(trace5, 3, 2)
331331
fig.show()
332332
```
333333

334+
### Share Binning
335+
In this example both histograms have a compatible bin settings using [bingroup](https://plot.ly/python/reference/#histogram-bingroup) attribute.
336+
337+
```python
338+
import plotly.graph_objects as go
339+
import numpy as np
340+
341+
fig = go.Figure(go.Histogram(
342+
x=np.random.randint(7, size=100),
343+
bingroup=1))
344+
345+
fig.add_trace(go.Histogram(
346+
x=np.random.randint(7, size=20),
347+
bingroup=1))
348+
349+
fig.update_layout(
350+
barmode="overlay",
351+
bargap=0.1)
352+
353+
fig.show()
354+
```
355+
334356
### Dash Example
335357

336358

0 commit comments

Comments
 (0)