diff --git a/_posts/python/statistical/histogram/2015-06-30-histograms.html b/_posts/python/statistical/histogram/2015-06-30-histograms.html index f49f39893a52..e5baa9206bcc 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,7 +104,7 @@ 

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,7 +153,7 @@ 

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,7 +201,7 @@ 

Horizontal Histogram -
Out[5]:
+
Out[4]:
@@ -219,13 +219,13 @@

Horizontal Histogram
-

Overlaid Histgram¶

+

Overlaid Histogram

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

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,7 +320,7 @@ 

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,7 +457,7 @@ 

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,7 +518,7 @@ 

Specify Binning Function -
Out[11]:
+
Out[9]:
@@ -536,7 +536,115 @@

Specify Binning Function
-

Reference¶

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

+

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.

+ +
+
+

+
+
+
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]:
+ + + +
+ +
+ +
+ +
+
+ +
+
+
+
+
+

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..d634f75c26e1 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,7 +48,7 @@ }, { "cell_type": "code", - "execution_count": 3, + "execution_count": 2, "metadata": {}, "outputs": [ { @@ -60,7 +60,7 @@ "" ] }, - "execution_count": 3, + "execution_count": 2, "metadata": {}, "output_type": "execute_result" } @@ -86,7 +86,7 @@ }, { "cell_type": "code", - "execution_count": 4, + "execution_count": 3, "metadata": {}, "outputs": [ { @@ -98,7 +98,7 @@ "" ] }, - "execution_count": 4, + "execution_count": 3, "metadata": {}, "output_type": "execute_result" } @@ -125,7 +125,7 @@ }, { "cell_type": "code", - "execution_count": 5, + "execution_count": 4, "metadata": {}, "outputs": [ { @@ -137,7 +137,7 @@ "" ] }, - "execution_count": 5, + "execution_count": 4, "metadata": {}, "output_type": "execute_result" } @@ -158,12 +158,12 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "### Overlaid Histgram ###" + "### Overlaid Histogram ###" ] }, { "cell_type": "code", - "execution_count": 6, + "execution_count": 5, "metadata": {}, "outputs": [ { @@ -175,7 +175,7 @@ "" ] }, - "execution_count": 6, + "execution_count": 5, "metadata": {}, "output_type": "execute_result" } @@ -214,7 +214,7 @@ }, { "cell_type": "code", - "execution_count": 7, + "execution_count": 6, "metadata": {}, "outputs": [ { @@ -226,7 +226,7 @@ "" ] }, - "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,7 +340,7 @@ }, { "cell_type": "code", - "execution_count": 9, + "execution_count": 8, "metadata": {}, "outputs": [ { @@ -352,7 +352,7 @@ "" ] }, - "execution_count": 9, + "execution_count": 8, "metadata": {}, "output_type": "execute_result" } @@ -379,7 +379,7 @@ }, { "cell_type": "code", - "execution_count": 11, + "execution_count": 9, "metadata": {}, "outputs": [ { @@ -391,7 +391,7 @@ "" ] }, - "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 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`." + ] + }, + { + "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-m55txi\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-dfu9fo\\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,