-
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 all commits
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,36 @@ fig = go.Figure(go.Histogram2d(x=x, y=y, histnorm='probability', | |
fig.show() | ||
``` | ||
|
||
### 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(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() | ||
``` | ||
|
||
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,29 +297,25 @@ 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, | ||
xbins=dict( | ||
start='1969-11-15', | ||
end='1972-03-31', | ||
size='M18'), # M18 stands for 18 months | ||
autobinx=False | ||
) | ||
size='M18')) # M18 stands for 18 months | ||
|
||
trace4 = go.Histogram(x=x, | ||
xbins=dict( | ||
start='1969-11-15', | ||
end='1972-03-31', | ||
size='M4'), # 4 months bin size | ||
autobinx=False | ||
) | ||
size='M4')) # M4 months bin size | ||
|
||
trace5 = go.Histogram(x=x, | ||
xbins=dict( | ||
start='1969-11-15', | ||
end='1972-03-31', | ||
size= 'M2'), # 2 months | ||
autobinx = False | ||
) | ||
size='M2')) # M2 months | ||
|
||
fig.append_trace(trace0, 1, 1) | ||
fig.append_trace(trace1, 1, 2) | ||
|
@@ -331,6 +327,28 @@ fig.append_trace(trace5, 3, 2) | |
fig.show() | ||
``` | ||
|
||
### Share bins between histograms | ||
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`. | ||
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. This sentence was not completely clear to me, I would say "however traces with 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. Please see plotly/plotly.js#3515 (comment) for a better understanding of what |
||
|
||
```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.
please remove the commented lines, it was just me doing some trial and error but these should not appear