From 6230994e9a9c7a46223e50acef1fb80cb5de5139 Mon Sep 17 00:00:00 2001 From: Priyatharsan Rajasekar Date: Wed, 29 Aug 2018 18:33:55 -0400 Subject: [PATCH 1/3] Added Custom Binning tut for histogram doc --- .../histogram/2015-06-30-histograms.html | 186 ++++++++++++++---- .../statistical/histogram/histograms.ipynb | 179 ++++++++++++----- 2 files changed, 276 insertions(+), 89 deletions(-) diff --git a/_posts/python/statistical/histogram/2015-06-30-histograms.html b/_posts/python/statistical/histogram/2015-06-30-histograms.html index f49f39893a52..008a14b5b068 100644 --- a/_posts/python/statistical/histogram/2015-06-30-histograms.html +++ b/_posts/python/statistical/histogram/2015-06-30-histograms.html @@ -20,7 +20,7 @@
-

New to Plotly?¶

Plotly's Python library is free and open source! Get started by downloading the client and reading the primer. +

New to Plotly?

Plotly's Python library is free and open source! Get started by downloading the client and reading the primer.
You can set up Plotly to work in online or offline mode, or in jupyter notebooks.
We also have a quick-reference cheatsheet (new!) to help you get started!

@@ -31,14 +31,14 @@

New to Plotly?
-

Version Check¶

Run pip install plotly --upgrade to update your Plotly version

+

Version Check

Run pip install plotly --upgrade to update your Plotly version

-
In [2]:
+
In [1]:
-
In [3]:
+
In [2]:
import plotly.plotly as py
@@ -104,12 +104,12 @@ 

Basic Histogram -
Out[3]:
+
Out[2]:
- +

@@ -122,13 +122,13 @@

Basic Histogram
-

Normalized Histogram¶

+

Normalized Histogram

-
In [4]:
+
In [3]:
import plotly.plotly as py
@@ -153,12 +153,12 @@ 

Normalized Histogram -
Out[4]:
+
Out[3]:
- +

@@ -171,13 +171,13 @@

Normalized Histogram
-

Horizontal Histogram¶

+

Horizontal Histogram

-
In [5]:
+
In [4]:
import plotly.plotly as py
@@ -201,12 +201,12 @@ 

Horizontal Histogram -
Out[5]:
+
Out[4]:
- +

@@ -219,13 +219,13 @@

Horizontal Histogram
-

Overlaid Histgram¶

+

Overlaid Histgram

-
In [6]:
+
In [5]:
import plotly.plotly as py
@@ -262,12 +262,12 @@ 

Overlaid Histgram -
Out[6]:
+
Out[5]:
- +

@@ -280,13 +280,13 @@

Overlaid Histgram
-

Stacked Histograms¶

+

Stacked Histograms

-
In [7]:
+
In [6]:
import plotly.plotly as py
@@ -320,12 +320,12 @@ 

Stacked Histograms -
Out[7]:
+
Out[6]:
- +

@@ -338,13 +338,13 @@

Stacked Histograms
-

Styled Histogram¶

+

Styled Histogram

-
In [1]:
+
In [7]:
import plotly.plotly as py
@@ -408,12 +408,12 @@ 

Styled Histogram -
Out[1]:
+
Out[7]:
- +

@@ -426,13 +426,13 @@

Styled Histogram
-

Cumulative Histogram¶

+

Cumulative Histogram

-
In [9]:
+
In [8]:
import plotly.plotly as py
@@ -457,12 +457,12 @@ 

Cumulative Histogram -
Out[9]:
+
Out[8]:
- +

@@ -475,19 +475,19 @@

Cumulative Histogram
-

Specify Binning Function¶

+

Specify Binning Function

-
In [11]:
+
In [9]:
import plotly.plotly as py
 import plotly.graph_objs as go
 
-x = ["Apples","Apples","Apples","Organges", "Bananas"]
+x = ["Apples","Apples","Apples","Oranges", "Bananas"]
 y = ["5","10","3","10","5"]
 
 data = [
@@ -518,12 +518,120 @@ 

Specify Binning Function -
Out[11]:
+
Out[9]:
+ + + +
+ +
+ +

+ +
+
+ +
+
+
+
+
+

Custom Binning

For custom binning along x-axis, use the attribute nbinsx. Please note that no matter how many bins being specified, the autobin algorithm will still give a 'nice' round bin sizes and edges. Alternatively, you can set the exact values for xbins along with autobinx = False.

+ +
+
+
+
+
+
In [10]:
+
+
+
from plotly import tools
+import plotly.plotly as py
+import plotly.graph_objs as go
+
+x = ['1970-01-01', '1970-01-01', '1970-02-01', '1970-04-01', '1970-01-02', '1972-01-31', '1970-02-13', '1971-04-19']
+
+
+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,
+    xbins=dict(
+        start='1969-11-15',
+        end='1972-03-31',
+        size= 'M18'),
+    autobinx = False
+)
+trace4 = go.Histogram(
+    x=x,
+    xbins=dict(
+        start='1969-11-15',
+        end='1972-03-31',
+        size= 'M4'),
+    autobinx = False
+)
+trace5 = go.Histogram(
+    x=x,
+    xbins=dict(
+        start='1969-11-15',
+        end='1972-03-31',
+        size= 'M2'),
+    autobinx = False
+)
+  
+fig = tools.make_subplots(rows=3, cols=2)
+fig.append_trace(trace0, 1, 1)
+fig.append_trace(trace1, 1, 2)
+fig.append_trace(trace2, 2, 1)
+fig.append_trace(trace3, 2, 2)
+fig.append_trace(trace4, 3, 1)
+fig.append_trace(trace5, 3, 2)
+
+py.iplot(fig, filename='custom binning')
+
+ +
+
+
+ +
+
+ + +
+ +
+ + +
+
This is the format of your plot grid:
+[ (1,1) x1,y1 ]  [ (1,2) x2,y2 ]
+[ (2,1) x3,y3 ]  [ (2,2) x4,y4 ]
+[ (3,1) x5,y5 ]  [ (3,2) x6,y6 ]
+
+
+
+
+ +
+ +
Out[10]:
- +
@@ -536,7 +644,7 @@

Specify Binning Function
-

Reference¶

See https://plot.ly/python/reference/#histogram for more information and chart attribute options!

+

Reference

See https://plot.ly/python/reference/#histogram for more information and chart attribute options!

diff --git a/_posts/python/statistical/histogram/histograms.ipynb b/_posts/python/statistical/histogram/histograms.ipynb index 186a071b3b46..d6c9138aa76b 100644 --- a/_posts/python/statistical/histogram/histograms.ipynb +++ b/_posts/python/statistical/histogram/histograms.ipynb @@ -20,16 +20,16 @@ }, { "cell_type": "code", - "execution_count": 2, + "execution_count": 1, "metadata": {}, "outputs": [ { "data": { "text/plain": [ - "'2.4.1'" + "'3.1.1'" ] }, - "execution_count": 2, + "execution_count": 1, "metadata": {}, "output_type": "execute_result" } @@ -48,19 +48,19 @@ }, { "cell_type": "code", - "execution_count": 3, + "execution_count": 2, "metadata": {}, "outputs": [ { "data": { "text/html": [ - "" + "" ], "text/plain": [ "" ] }, - "execution_count": 3, + "execution_count": 2, "metadata": {}, "output_type": "execute_result" } @@ -86,19 +86,19 @@ }, { "cell_type": "code", - "execution_count": 4, + "execution_count": 3, "metadata": {}, "outputs": [ { "data": { "text/html": [ - "" + "" ], "text/plain": [ "" ] }, - "execution_count": 4, + "execution_count": 3, "metadata": {}, "output_type": "execute_result" } @@ -125,19 +125,19 @@ }, { "cell_type": "code", - "execution_count": 5, + "execution_count": 4, "metadata": {}, "outputs": [ { "data": { "text/html": [ - "" + "" ], "text/plain": [ "" ] }, - "execution_count": 5, + "execution_count": 4, "metadata": {}, "output_type": "execute_result" } @@ -163,19 +163,19 @@ }, { "cell_type": "code", - "execution_count": 6, + "execution_count": 5, "metadata": {}, "outputs": [ { "data": { "text/html": [ - "" + "" ], "text/plain": [ "" ] }, - "execution_count": 6, + "execution_count": 5, "metadata": {}, "output_type": "execute_result" } @@ -214,19 +214,19 @@ }, { "cell_type": "code", - "execution_count": 7, + "execution_count": 6, "metadata": {}, "outputs": [ { "data": { "text/html": [ - "" + "" ], "text/plain": [ "" ] }, - "execution_count": 7, + "execution_count": 6, "metadata": {}, "output_type": "execute_result" } @@ -262,19 +262,19 @@ }, { "cell_type": "code", - "execution_count": 1, + "execution_count": 7, "metadata": {}, "outputs": [ { "data": { "text/html": [ - "" + "" ], "text/plain": [ "" ] }, - "execution_count": 1, + "execution_count": 7, "metadata": {}, "output_type": "execute_result" } @@ -340,19 +340,19 @@ }, { "cell_type": "code", - "execution_count": 9, + "execution_count": 8, "metadata": {}, "outputs": [ { "data": { "text/html": [ - "" + "" ], "text/plain": [ "" ] }, - "execution_count": 9, + "execution_count": 8, "metadata": {}, "output_type": "execute_result" } @@ -379,19 +379,19 @@ }, { "cell_type": "code", - "execution_count": 11, + "execution_count": 9, "metadata": {}, "outputs": [ { "data": { "text/html": [ - "" + "" ], "text/plain": [ "" ] }, - "execution_count": 11, + "execution_count": 9, "metadata": {}, "output_type": "execute_result" } @@ -400,7 +400,7 @@ "import plotly.plotly as py\n", "import plotly.graph_objs as go\n", "\n", - "x = [\"Apples\",\"Apples\",\"Apples\",\"Organges\", \"Bananas\"]\n", + "x = [\"Apples\",\"Apples\",\"Apples\",\"Oranges\", \"Bananas\"]\n", "y = [\"5\",\"10\",\"3\",\"10\",\"5\"]\n", "\n", "data = [\n", @@ -421,6 +421,100 @@ "py.iplot(data, filename='binning function')" ] }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### Custom Binning\n", + "For custom binning along x-axis, use the attribute [`nbinsx`](https://plot.ly/python/reference/#histogram-nbinsx). Please note that no matter how many bins being specified, the autobin algorithm will still give a 'nice' round bin sizes and edges. Alternatively, you can set the exact values for [`xbins`](https://plot.ly/python/reference/#histogram-xbins) along with `autobinx = False`." + ] + }, + { + "cell_type": "code", + "execution_count": 10, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "This is the format of your plot grid:\n", + "[ (1,1) x1,y1 ] [ (1,2) x2,y2 ]\n", + "[ (2,1) x3,y3 ] [ (2,2) x4,y4 ]\n", + "[ (3,1) x5,y5 ] [ (3,2) x6,y6 ]\n", + "\n" + ] + }, + { + "data": { + "text/html": [ + "" + ], + "text/plain": [ + "" + ] + }, + "execution_count": 10, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "from plotly import tools\n", + "import plotly.plotly as py\n", + "import plotly.graph_objs as go\n", + "\n", + "x = ['1970-01-01', '1970-01-01', '1970-02-01', '1970-04-01', '1970-01-02', '1972-01-31', '1970-02-13', '1971-04-19']\n", + "\n", + "\n", + "trace0 = go.Histogram(\n", + " x=x,\n", + " nbinsx = 4, \n", + " )\n", + "trace1 = go.Histogram(\n", + " x=x,\n", + " nbinsx = 8, \n", + " )\n", + "trace2 = go.Histogram(\n", + " x=x,\n", + " nbinsx = 10, \n", + " )\n", + "trace3 = go.Histogram(\n", + " x=x,\n", + " xbins=dict(\n", + " start='1969-11-15',\n", + " end='1972-03-31',\n", + " size= 'M18'),\n", + " autobinx = False\n", + ")\n", + "trace4 = go.Histogram(\n", + " x=x,\n", + " xbins=dict(\n", + " start='1969-11-15',\n", + " end='1972-03-31',\n", + " size= 'M4'),\n", + " autobinx = False\n", + ")\n", + "trace5 = go.Histogram(\n", + " x=x,\n", + " xbins=dict(\n", + " start='1969-11-15',\n", + " end='1972-03-31',\n", + " size= 'M2'),\n", + " autobinx = False\n", + ")\n", + " \n", + "fig = tools.make_subplots(rows=3, cols=2)\n", + "fig.append_trace(trace0, 1, 1)\n", + "fig.append_trace(trace1, 1, 2)\n", + "fig.append_trace(trace2, 2, 1)\n", + "fig.append_trace(trace3, 2, 2)\n", + "fig.append_trace(trace4, 3, 1)\n", + "fig.append_trace(trace5, 3, 2)\n", + "\n", + "py.iplot(fig, filename='custom binning')" + ] + }, { "cell_type": "markdown", "metadata": {}, @@ -431,7 +525,7 @@ }, { "cell_type": "code", - "execution_count": 2, + "execution_count": 12, "metadata": {}, "outputs": [ { @@ -463,10 +557,11 @@ "output_type": "stream", "text": [ "Collecting git+https://github.com/plotly/publisher.git\n", - " Cloning https://github.com/plotly/publisher.git to /private/var/folders/tc/bs9g6vrd36q74m5t8h9cgphh0000gn/T/pip-req-build-vLqig0\n", + " Cloning https://github.com/plotly/publisher.git to c:\\users\\thars\\appdata\\local\\temp\\pip-req-build-jq6h4q\n", "Building wheels for collected packages: publisher\n", - " Running setup.py bdist_wheel for publisher ... \u001b[?25ldone\n", - "\u001b[?25h Stored in directory: /private/var/folders/tc/bs9g6vrd36q74m5t8h9cgphh0000gn/T/pip-ephem-wheel-cache-mKb20V/wheels/99/3e/a0/fbd22ba24cca72bdbaba53dbc23c1768755fb17b3af0f33966\n", + " Running setup.py bdist_wheel for publisher: started\n", + " Running setup.py bdist_wheel for publisher: finished with status 'done'\n", + " Stored in directory: c:\\users\\thars\\appdata\\local\\temp\\pip-ephem-wheel-cache-nls1yn\\wheels\\99\\3e\\a0\\fbd22ba24cca72bdbaba53dbc23c1768755fb17b3af0f33966\n", "Successfully built publisher\n", "Installing collected packages: publisher\n", " Found existing installation: publisher 0.11\n", @@ -474,20 +569,6 @@ " Successfully uninstalled publisher-0.11\n", "Successfully installed publisher-0.11\n" ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/IPython/nbconvert.py:13: ShimWarning:\n", - "\n", - "The `IPython.nbconvert` package has been deprecated since IPython 4.0. You should import from nbconvert instead.\n", - "\n", - "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/publisher/publisher.py:53: UserWarning:\n", - "\n", - "Did you \"Save\" this notebook before running this command? Remember to save, always save.\n", - "\n" - ] } ], "source": [ @@ -513,9 +594,7 @@ { "cell_type": "code", "execution_count": null, - "metadata": { - "collapsed": true - }, + "metadata": {}, "outputs": [], "source": [] } @@ -537,7 +616,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython2", - "version": "2.7.12" + "version": "2.7.14" } }, "nbformat": 4, From 861078c72ecd3b04b0549834f50ce8bcccf20acc Mon Sep 17 00:00:00 2001 From: Priyatharsan Rajasekar Date: Thu, 30 Aug 2018 10:27:17 -0400 Subject: [PATCH 2/3] updated the description and the spelling correction --- .../statistical/histogram/2015-06-30-histograms.html | 4 ++-- _posts/python/statistical/histogram/histograms.ipynb | 10 +++++----- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/_posts/python/statistical/histogram/2015-06-30-histograms.html b/_posts/python/statistical/histogram/2015-06-30-histograms.html index 008a14b5b068..edc46bdd9289 100644 --- a/_posts/python/statistical/histogram/2015-06-30-histograms.html +++ b/_posts/python/statistical/histogram/2015-06-30-histograms.html @@ -219,7 +219,7 @@

Horizontal Histogram
-

Overlaid Histgram

+

Overlaid Histogram

@@ -536,7 +536,7 @@

Specify Binning Function
-

Custom Binning

For custom binning along x-axis, use the attribute nbinsx. Please note that no matter how many bins being specified, the autobin algorithm will still give a 'nice' round bin sizes and edges. Alternatively, you can set the exact values for xbins along with autobinx = False.

+

Custom Binning

For custom binning along x-axis, use the attribute nbinsx. Please note that the autobin algorithm will choose a 'nice' round bin size that may result in somewhat fewer than nbinsx total bins. Alternatively, you can set the exact values for xbins along with autobinx = False.

diff --git a/_posts/python/statistical/histogram/histograms.ipynb b/_posts/python/statistical/histogram/histograms.ipynb index d6c9138aa76b..5cc3bd5a5f58 100644 --- a/_posts/python/statistical/histogram/histograms.ipynb +++ b/_posts/python/statistical/histogram/histograms.ipynb @@ -158,7 +158,7 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "### Overlaid Histgram ###" + "### Overlaid Histogram ###" ] }, { @@ -426,7 +426,7 @@ "metadata": {}, "source": [ "### Custom Binning\n", - "For custom binning along x-axis, use the attribute [`nbinsx`](https://plot.ly/python/reference/#histogram-nbinsx). Please note that no matter how many bins being specified, the autobin algorithm will still give a 'nice' round bin sizes and edges. Alternatively, you can set the exact values for [`xbins`](https://plot.ly/python/reference/#histogram-xbins) along with `autobinx = False`." + "For custom binning along x-axis, use the attribute [`nbinsx`](https://plot.ly/python/reference/#histogram-nbinsx). Please note that the autobin algorithm will choose a 'nice' round bin size that may result in somewhat fewer than `nbinsx` total bins. Alternatively, you can set the exact values for [`xbins`](https://plot.ly/python/reference/#histogram-xbins) along with `autobinx = False`." ] }, { @@ -525,7 +525,7 @@ }, { "cell_type": "code", - "execution_count": 12, + "execution_count": 13, "metadata": {}, "outputs": [ { @@ -557,11 +557,11 @@ "output_type": "stream", "text": [ "Collecting git+https://github.com/plotly/publisher.git\n", - " Cloning https://github.com/plotly/publisher.git to c:\\users\\thars\\appdata\\local\\temp\\pip-req-build-jq6h4q\n", + " Cloning https://github.com/plotly/publisher.git to c:\\users\\thars\\appdata\\local\\temp\\pip-req-build-iw0pnu\n", "Building wheels for collected packages: publisher\n", " Running setup.py bdist_wheel for publisher: started\n", " Running setup.py bdist_wheel for publisher: finished with status 'done'\n", - " Stored in directory: c:\\users\\thars\\appdata\\local\\temp\\pip-ephem-wheel-cache-nls1yn\\wheels\\99\\3e\\a0\\fbd22ba24cca72bdbaba53dbc23c1768755fb17b3af0f33966\n", + " Stored in directory: c:\\users\\thars\\appdata\\local\\temp\\pip-ephem-wheel-cache-kqmvuc\\wheels\\99\\3e\\a0\\fbd22ba24cca72bdbaba53dbc23c1768755fb17b3af0f33966\n", "Successfully built publisher\n", "Installing collected packages: publisher\n", " Found existing installation: publisher 0.11\n", From 96fa00affabe60295b7fa5a456bb7a8c757532cd Mon Sep 17 00:00:00 2001 From: Priyatharsan Rajasekar Date: Wed, 5 Sep 2018 11:24:35 -0400 Subject: [PATCH 3/3] updated the plot embeddings URLs to PythonPlotBot --- .../histogram/2015-06-30-histograms.html | 18 +++++++------- .../statistical/histogram/histograms.ipynb | 24 +++++++++---------- 2 files changed, 21 insertions(+), 21 deletions(-) diff --git a/_posts/python/statistical/histogram/2015-06-30-histograms.html b/_posts/python/statistical/histogram/2015-06-30-histograms.html index edc46bdd9289..e5baa9206bcc 100644 --- a/_posts/python/statistical/histogram/2015-06-30-histograms.html +++ b/_posts/python/statistical/histogram/2015-06-30-histograms.html @@ -109,7 +109,7 @@

Basic Histogram - +

@@ -158,7 +158,7 @@

Normalized Histogram - +

@@ -206,7 +206,7 @@

Horizontal Histogram - +

@@ -267,7 +267,7 @@

Overlaid Histogram - +

@@ -325,7 +325,7 @@

Stacked Histograms - +

@@ -413,7 +413,7 @@

Styled Histogram - +

@@ -462,7 +462,7 @@

Cumulative Histogram - +

@@ -523,7 +523,7 @@

Specify Binning Function - +

@@ -631,7 +631,7 @@

Custom Binning - +

diff --git a/_posts/python/statistical/histogram/histograms.ipynb b/_posts/python/statistical/histogram/histograms.ipynb index 5cc3bd5a5f58..d634f75c26e1 100644 --- a/_posts/python/statistical/histogram/histograms.ipynb +++ b/_posts/python/statistical/histogram/histograms.ipynb @@ -54,7 +54,7 @@ { "data": { "text/html": [ - "" + "" ], "text/plain": [ "" @@ -92,7 +92,7 @@ { "data": { "text/html": [ - "" + "" ], "text/plain": [ "" @@ -131,7 +131,7 @@ { "data": { "text/html": [ - "" + "" ], "text/plain": [ "" @@ -169,7 +169,7 @@ { "data": { "text/html": [ - "" + "" ], "text/plain": [ "" @@ -220,7 +220,7 @@ { "data": { "text/html": [ - "" + "" ], "text/plain": [ "" @@ -268,7 +268,7 @@ { "data": { "text/html": [ - "" + "" ], "text/plain": [ "" @@ -346,7 +346,7 @@ { "data": { "text/html": [ - "" + "" ], "text/plain": [ "" @@ -385,7 +385,7 @@ { "data": { "text/html": [ - "" + "" ], "text/plain": [ "" @@ -448,7 +448,7 @@ { "data": { "text/html": [ - "" + "" ], "text/plain": [ "" @@ -525,7 +525,7 @@ }, { "cell_type": "code", - "execution_count": 13, + "execution_count": 12, "metadata": {}, "outputs": [ { @@ -557,11 +557,11 @@ "output_type": "stream", "text": [ "Collecting git+https://github.com/plotly/publisher.git\n", - " Cloning https://github.com/plotly/publisher.git to c:\\users\\thars\\appdata\\local\\temp\\pip-req-build-iw0pnu\n", + " Cloning https://github.com/plotly/publisher.git to c:\\users\\thars\\appdata\\local\\temp\\pip-req-build-m55txi\n", "Building wheels for collected packages: publisher\n", " Running setup.py bdist_wheel for publisher: started\n", " Running setup.py bdist_wheel for publisher: finished with status 'done'\n", - " Stored in directory: c:\\users\\thars\\appdata\\local\\temp\\pip-ephem-wheel-cache-kqmvuc\\wheels\\99\\3e\\a0\\fbd22ba24cca72bdbaba53dbc23c1768755fb17b3af0f33966\n", + " Stored in directory: c:\\users\\thars\\appdata\\local\\temp\\pip-ephem-wheel-cache-dfu9fo\\wheels\\99\\3e\\a0\\fbd22ba24cca72bdbaba53dbc23c1768755fb17b3af0f33966\n", "Successfully built publisher\n", "Installing collected packages: publisher\n", " Found existing installation: publisher 0.11\n",