Skip to content

bingroup #200

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

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
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
28 changes: 26 additions & 2 deletions python/2D-Histogram.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ jupyter:
extension: .md
format_name: markdown
format_version: '1.1'
jupytext_version: 1.1.1
jupytext_version: 1.2.1
kernelspec:
display_name: Python 3
language: python
Expand All @@ -20,7 +20,7 @@ jupyter:
name: python
nbconvert_exporter: python
pygments_lexer: ipython3
version: 3.6.7
version: 3.7.3
plotly:
description: How to make 2D Histograms in Python with Plotly.
display_as: statistical
Expand Down Expand Up @@ -71,6 +71,30 @@ fig = go.Figure(go.Histogram2d(x=x, y=y, histnorm='probability',
fig.show()
```

### 2D Histogram Share Binning
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sharing bin settings between 2D Histograms

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`.

```python
import plotly.graph_objects as go
from plotly.subplots import make_subplots

fig = make_subplots(1,2)

fig.add_trace(go.Histogram2d(
x = [ 1, 2, 2, 3, 4 ],
y = [ 1, 2, 2, 3, 4 ],
bingroup = 1,
xbins = {'start':1, 'size':1}), 1,1)

fig.add_trace(go.Histogram2d(
x = [ 4, 5, 5, 5, 6 ],
y = [ 4, 5, 5, 5, 6 ],
bingroup = 1,
ybins = {'start': 3, 'size': 1}),1,2)

fig.show()
```

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It could be interesting to show the behaviour with and without bingroup, for example

import plotly.graph_objects as go
from plotly.subplots import make_subplots
fig = make_subplots(2,2)
fig.add_trace(go.Histogram2d(
    x = [ 1, 2, 2, 3, 4 ],
    y = [ 1, 2, 2, 3, 4 ],
    #bingroup = 1,
    xbins = {'start':1, 'size':1}), 1,1)
fig.add_trace(go.Histogram2d(
    x = [ 4, 5, 5, 5, 6 ],
    y = [ 4, 5, 5, 5, 6 ],
    #bingroup = 1,
    ybins = {'start': 3, 'size': 1}),1,2)
fig.add_trace(go.Histogram2d(
    x = [ 1, 2, 2, 3, 4 ],
    y = [ 1, 2, 2, 3, 4 ],
    bingroup = 1,
    xbins = {'start':1, 'size':1}), 2,1)
fig.add_trace(go.Histogram2d(
    x = [ 4, 5, 5, 5, 6 ],
    y = [ 4, 5, 5, 5, 6 ],
    bingroup = 1,
    ybins = {'start': 3, 'size': 1}),2,2)
fig.show()

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

```python
Expand Down
38 changes: 30 additions & 8 deletions python/histograms.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ jupyter:
extension: .md
format_name: markdown
format_version: '1.1'
jupytext_version: 1.1.1
jupytext_version: 1.2.1
kernelspec:
display_name: Python 3
language: python
Expand All @@ -20,7 +20,7 @@ jupyter:
name: python
nbconvert_exporter: python
pygments_lexer: ipython3
version: 3.6.7
version: 3.7.3
plotly:
description: How to make Histograms in Python with Plotly.
display_as: statistical
Expand Down Expand Up @@ -297,27 +297,27 @@ x = ['1970-01-01', '1970-01-01', '1970-02-01', '1970-04-01', '1970-01-02',
fig = make_subplots(rows=3, cols=2)

trace0 = go.Histogram(x=x, nbinsx=4)
trace1 = go.Histogram(x=x, nbinsx = 8)
trace1 = go.Histogram(x=x, nbinsx=8)
trace2 = go.Histogram(x=x, nbinsx=10)
trace3 = go.Histogram(x=x,
trace3 = go.Histogram(x=x,bingroup=1,
xbins=dict(
start='1969-11-15',
end='1972-03-31',
size='M18'), # M18 stands for 18 months
autobinx=False

)
trace4 = go.Histogram(x=x,
trace4 = go.Histogram(x=x,bingroup=1,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't understand why you define here a bingroup since the different traces have a different bin size. Also, please remove all the autobinx and autobiny from this tutorial since these parameters are described as obsolete in the doc.

xbins=dict(
start='1969-11-15',
end='1972-03-31',
size='M4'), # 4 months bin size
autobinx=False

)
trace5 = go.Histogram(x=x,
xbins=dict(
start='1969-11-15',
end='1972-03-31',
size= 'M2'), # 2 months
size='M2'), # 2 months
autobinx = False
)

Expand All @@ -331,6 +331,28 @@ fig.append_trace(trace5, 3, 2)
fig.show()
```

### Share Binning
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Share bins between histograms

In this example both histograms have a compatible bin settings using [bingroup](https://plot.ly/python/reference/#histogram-bingroup) attribute.
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 add here a comment saying that histograms in the same subplot are forced into the same default to barmode stack, relative or group, but not for overlay?


```python
import plotly.graph_objects as go
import numpy as np

fig = go.Figure(go.Histogram(
x=np.random.randint(7, size=100),
bingroup=1))

fig.add_trace(go.Histogram(
x=np.random.randint(7, size=20),
bingroup=1))

fig.update_layout(
barmode="overlay",
bargap=0.1)

fig.show()
```

### Dash Example


Expand Down