-
Notifications
You must be signed in to change notification settings - Fork 1
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
bingroup #200
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 | ||
|
@@ -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 | ||
|
@@ -71,6 +71,30 @@ fig = go.Figure(go.Histogram2d(x=x, y=y, histnorm='probability', | |
fig.show() | ||
``` | ||
|
||
### 2D Histogram Share Binning | ||
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() | ||
``` | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It could be interesting to show the behaviour with and without
|
||
### 2D Histogram Overlaid with a Scatter Chart ### | ||
|
||
```python | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 | ||
|
@@ -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 | ||
|
@@ -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, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't understand why you define here a |
||
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 | ||
) | ||
|
||
|
@@ -331,6 +331,28 @@ fig.append_trace(trace5, 3, 2) | |
fig.show() | ||
``` | ||
|
||
### Share Binning | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 | ||
|
||
|
||
|
There was a problem hiding this comment.
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