From fc44c19172ed57144452256cf7341b1bfd5613a0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=80=9Cmahdis-z=E2=80=9D?= <“maahhddiiss@gmail.com”> Date: Wed, 13 Nov 2019 17:16:01 -0500 Subject: [PATCH 1/3] bingroup --- python/2D-Histogram.md | 28 ++++++++++++++++++++++++++-- python/histograms.md | 38 ++++++++++++++++++++++++++++++-------- 2 files changed, 56 insertions(+), 10 deletions(-) diff --git a/python/2D-Histogram.md b/python/2D-Histogram.md index 89059d50a..2ebf09c35 100644 --- a/python/2D-Histogram.md +++ b/python/2D-Histogram.md @@ -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() +``` + ### 2D Histogram Overlaid with a Scatter Chart ### ```python diff --git a/python/histograms.md b/python/histograms.md index 6ff910166..c4fbf667f 100644 --- a/python/histograms.md +++ b/python/histograms.md @@ -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, 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 +In this example both histograms have a compatible bin settings using [bingroup](https://plot.ly/python/reference/#histogram-bingroup) attribute. + +```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 From 1a7e61bec846cd0d321f590dbdc98af80dabc306 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=80=9Cmahdis-z=E2=80=9D?= <“maahhddiiss@gmail.com”> Date: Thu, 14 Nov 2019 14:40:28 -0500 Subject: [PATCH 2/3] minor revisions --- python/2D-Histogram.md | 22 ++++++++++++++-------- python/histograms.md | 20 ++++++++------------ 2 files changed, 22 insertions(+), 20 deletions(-) diff --git a/python/2D-Histogram.md b/python/2D-Histogram.md index 2ebf09c35..471719061 100644 --- a/python/2D-Histogram.md +++ b/python/2D-Histogram.md @@ -71,27 +71,33 @@ fig = go.Figure(go.Histogram2d(x=x, y=y, histnorm='probability', fig.show() ``` -### 2D Histogram Share Binning +### 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 = make_subplots(2,2) fig.add_trace(go.Histogram2d( x = [ 1, 2, 2, 3, 4 ], y = [ 1, 2, 2, 3, 4 ], - bingroup = 1, + #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, + #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() ``` diff --git a/python/histograms.md b/python/histograms.md index c4fbf667f..b0b29c2fe 100644 --- a/python/histograms.md +++ b/python/histograms.md @@ -299,27 +299,23 @@ fig = make_subplots(rows=3, cols=2) trace0 = go.Histogram(x=x, nbinsx=4) trace1 = go.Histogram(x=x, nbinsx=8) trace2 = go.Histogram(x=x, nbinsx=10) -trace3 = go.Histogram(x=x,bingroup=1, +trace3 = go.Histogram(x=x, xbins=dict( start='1969-11-15', end='1972-03-31', - size='M18'), # M18 stands for 18 months + size='M18'), # M18 stands for 18 months) - ) -trace4 = go.Histogram(x=x,bingroup=1, +trace4 = go.Histogram(x=x, xbins=dict( start='1969-11-15', end='1972-03-31', - size='M4'), # 4 months bin size - - ) + size='M4') # 4 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'), # 2 months) fig.append_trace(trace0, 1, 1) fig.append_trace(trace1, 1, 2) @@ -331,8 +327,8 @@ fig.append_trace(trace5, 3, 2) fig.show() ``` -### Share Binning -In this example both histograms have a compatible bin settings using [bingroup](https://plot.ly/python/reference/#histogram-bingroup) attribute. +### 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`. ```python import plotly.graph_objects as go From 98ec7f745ce5d05834c118b5f70182fdc4fb6a82 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=80=9Cmahdis-z=E2=80=9D?= <“maahhddiiss@gmail.com”> Date: Thu, 14 Nov 2019 14:54:56 -0500 Subject: [PATCH 3/3] fixing code --- python/histograms.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/python/histograms.md b/python/histograms.md index b0b29c2fe..a2bdb6124 100644 --- a/python/histograms.md +++ b/python/histograms.md @@ -303,19 +303,19 @@ trace3 = go.Histogram(x=x, xbins=dict( start='1969-11-15', end='1972-03-31', - size='M18'), # M18 stands for 18 months) + 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) + 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) + size='M2')) # M2 months fig.append_trace(trace0, 1, 1) fig.append_trace(trace1, 1, 2)