diff --git a/_posts/python/subplots/ff-subplots/2015-06-30-ff-subplots.html b/_posts/python/subplots/ff-subplots/2015-06-30-ff-subplots.html index cef1fd188769..8916d75766e9 100644 --- a/_posts/python/subplots/ff-subplots/2015-06-30-ff-subplots.html +++ b/_posts/python/subplots/ff-subplots/2015-06-30-ff-subplots.html @@ -15,15 +15,14 @@ page_type: u-guide --- {% raw %} -
-
+
-

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!

-

Version Check

Plotly's python package is updated frequently. Run pip install plotly --upgrade to use the latest version.

+

Version Check¶

Plotly's python package is updated frequently. Run pip install plotly --upgrade to use the latest version.

@@ -45,11 +44,15 @@

Version Check - -
-
+
-

Plotly's Figure Factory Module

Plotly's Python API contains a figure factory module which includes many wrapper functions that create unique chart types that are not yet included in plotly.js, Plotly's open-source graphing library. The figure factory functions create a full figure, so some Plotly features, such as subplotting, should be implemented slightly differently with these charts.

+

Plotly's Figure Factory Module¶

Plotly's Python API contains a figure factory module which includes many wrapper functions that create unique chart types that are not yet included in plotly.js, Plotly's open-source graphing library. The figure factory functions create a full figure, so some Plotly features, such as subplotting, should be implemented slightly differently with these charts.

@@ -85,7 +87,11 @@

Plotly's Figure Factory Module -
+
+ +
+ +
Help on package plotly.figure_factory in plotly:
 
@@ -98,9 +104,12 @@ 

Plotly's Figure Factory ModulePlotly's Figure Factory Module -
+
-

Vertical Figure Factory Charts

First create the figures that you'd like to appear in the subplot:

+

Vertical Figure Factory Charts¶

First create the figures that you'd like to appear in the subplot:

-
In [4]:
+
In [3]:
-
-
+
@@ -179,7 +207,7 @@

Vertical Figure Factory Charts
-
In [5]:
+
In [4]:
@@ -202,25 +234,27 @@

Vertical Figure Factory Charts -
+
-

Add the data and layout objects:

+

Combine the data and layout objects to create a figure

-
In [6]:
+
In [5]:
-
fig1.data.extend(fig2.data)
-fig1.layout.update(fig2.layout)
+
fig = go.Figure()
+fig.add_traces([fig1.data[0], fig2.data[0]])
+
+fig.layout.update(fig1.layout)
+fig.layout.update(fig2.layout)
 
-py.iplot(fig1, filename='figure_factory_subplot')
+py.iplot(fig, filename='figure_factory_subplot')
 
@@ -231,7 +265,11 @@

Vertical Figure Factory Charts -
Out[6]:
+
+ +
Out[5]:
+ +
@@ -243,18 +281,17 @@

Vertical Figure Factory Charts -
+
-

Horizontal Table and Chart

+

Horizontal Table and Chart¶

-
In [8]:
+
In [6]:
import plotly.plotly as py
@@ -286,14 +323,20 @@ 

Horizontal Table and Chartname='Goals Against<br>Per Game', xaxis='x2', yaxis='y2') -figure['data'].extend(go.Data([trace1, trace2])) +figure.add_traces([trace1, trace2]) + +# initialize xaxis2 and yaxis2 +figure['layout']['xaxis2'] = {} +figure['layout']['yaxis2'] = {} # Edit layout for subplots figure.layout.xaxis.update({'domain': [0, .5]}) figure.layout.xaxis2.update({'domain': [0.6, 1.]}) + # The graph's yaxis MUST BE anchored to the graph's xaxis figure.layout.yaxis2.update({'anchor': 'x2'}) figure.layout.yaxis2.update({'title': 'Goals'}) + # Update the margins to add a title and see graph x-labels. figure.layout.margin.update({'t':50, 'b':100}) figure.layout.update({'title': '2016 Hockey Stats'}) @@ -309,7 +352,11 @@

Horizontal Table and Chart -
Out[8]:
+
+ +
Out[6]:
+ +
@@ -321,18 +368,17 @@

Horizontal Table and Chart -
+
-

Vertical Table and Chart

+

Vertical Table and Chart¶

-
In [9]:
+
In [7]:
import plotly.plotly as py
@@ -347,6 +393,7 @@ 

Vertical Table and Chart['Boston<br>Bruins', 13, 8, 0], ['Chicago<br>Blackhawks', 13, 8, 0], ['Ottawa<br>Senators', 12, 5, 0]] + # Initialize a figure with ff.create_table(table_data) figure = ff.create_table(table_data, height_constant=60) @@ -355,6 +402,7 @@

Vertical Table and Chart'Boston Bruins', 'Chicago Blackhawks', 'Ottawa Senators'] GFPG = [3.54, 3.48, 3.0, 3.27, 2.83, 3.18] GAPG = [2.17, 2.57, 2.0, 2.91, 2.57, 2.77] + # Make traces for graph trace1 = go.Bar(x=teams, y=GFPG, xaxis='x2', yaxis='y2', marker=dict(color='#0099ff'), @@ -364,18 +412,25 @@

Vertical Table and Chartname='Goals Against<br>Per Game') # Add trace data to figure -figure['data'].extend(go.Data([trace1, trace2])) +figure.add_traces([trace1, trace2]) + +# initialize xaxis2 and yaxis2 +figure['layout']['xaxis2'] = {} +figure['layout']['yaxis2'] = {} # Edit layout for subplots figure.layout.yaxis.update({'domain': [0, .45]}) figure.layout.yaxis2.update({'domain': [.6, 1]}) + # The graph's yaxis2 MUST BE anchored to the graph's xaxis2 and vice versa figure.layout.yaxis2.update({'anchor': 'x2'}) figure.layout.xaxis2.update({'anchor': 'y2'}) figure.layout.yaxis2.update({'title': 'Goals'}) + # Update the margins to add a title and see graph x-labels. figure.layout.margin.update({'t':75, 'l':50}) figure.layout.update({'title': '2016 Hockey Stats'}) + # Update the height because adding a graph vertically will interact with # the plot height calculated for the table figure.layout.update({'height':800}) @@ -392,7 +447,11 @@

Vertical Table and Chart -
Out[9]:
+
+ +
Out[7]:
+ +
-
-
+
-

Reference

See https://plot.ly/python/reference/ for more information regarding chart attributes!

+

Reference¶

See https://plot.ly/python/reference/ for more information regarding chart attributes!

-
{% endraw %} \ No newline at end of file +
+ + +{% endraw %} \ No newline at end of file diff --git a/_posts/python/subplots/ff-subplots/ff-subplots.ipynb b/_posts/python/subplots/ff-subplots/ff-subplots.ipynb index 8275889d9ffd..f3fcfee4b6a3 100644 --- a/_posts/python/subplots/ff-subplots/ff-subplots.ipynb +++ b/_posts/python/subplots/ff-subplots/ff-subplots.ipynb @@ -20,7 +20,7 @@ { "data": { "text/plain": [ - "'2.0.7'" + "'3.3.0'" ] }, "execution_count": 1, @@ -61,9 +61,12 @@ "PACKAGE CONTENTS\n", " _2d_density\n", " _annotated_heatmap\n", + " _bullet\n", " _candlestick\n", + " _county_choropleth\n", " _dendrogram\n", " _distplot\n", + " _facet_grid\n", " _gantt\n", " _ohlc\n", " _quiver\n", @@ -96,9 +99,20 @@ }, { "cell_type": "code", - "execution_count": 4, + "execution_count": 3, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stderr", + "output_type": "stream", + "text": [ + "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/plotly/figure_factory/_streamline.py:357: RuntimeWarning:\n", + "\n", + "invalid value encountered in divide\n", + "\n" + ] + } + ], "source": [ "import plotly.plotly as py\n", "import plotly.figure_factory as ff\n", @@ -133,10 +147,8 @@ }, { "cell_type": "code", - "execution_count": 5, - "metadata": { - "collapsed": true - }, + "execution_count": 4, + "metadata": {}, "outputs": [], "source": [ "for i in range(len(fig1.data)):\n", @@ -150,6 +162,10 @@ " fig2.data[i].xaxis='x2'\n", " fig2.data[i].yaxis='y2'\n", "\n", + "# initialize xaxis2 and yaxis2\n", + "fig2['layout']['xaxis2'] = {}\n", + "fig2['layout']['yaxis2'] = {}\n", + "\n", "fig2.layout.xaxis2.update({'anchor': 'y2'})\n", "fig2.layout.yaxis2.update({'anchor': 'x2', 'domain': [0, .45]})" ] @@ -158,12 +174,12 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "Add the data and layout objects:" + "Combine the data and layout objects to create a figure" ] }, { "cell_type": "code", - "execution_count": 6, + "execution_count": 5, "metadata": {}, "outputs": [ { @@ -175,16 +191,19 @@ "" ] }, - "execution_count": 6, + "execution_count": 5, "metadata": {}, "output_type": "execute_result" } ], "source": [ - "fig1.data.extend(fig2.data)\n", - "fig1.layout.update(fig2.layout)\n", + "fig = go.Figure()\n", + "fig.add_traces([fig1.data[0], fig2.data[0]])\n", + "\n", + "fig.layout.update(fig1.layout)\n", + "fig.layout.update(fig2.layout)\n", "\n", - "py.iplot(fig1, filename='figure_factory_subplot')" + "py.iplot(fig, filename='figure_factory_subplot')" ] }, { @@ -196,7 +215,7 @@ }, { "cell_type": "code", - "execution_count": 7, + "execution_count": 6, "metadata": {}, "outputs": [ { @@ -208,7 +227,7 @@ "" ] }, - "execution_count": 7, + "execution_count": 6, "metadata": {}, "output_type": "execute_result" } @@ -243,14 +262,20 @@ " name='Goals Against
Per Game',\n", " xaxis='x2', yaxis='y2')\n", "\n", - "figure['data'].extend(go.Data([trace1, trace2]))\n", + "figure.add_traces([trace1, trace2])\n", + "\n", + "# initialize xaxis2 and yaxis2\n", + "figure['layout']['xaxis2'] = {}\n", + "figure['layout']['yaxis2'] = {}\n", "\n", "# Edit layout for subplots\n", "figure.layout.xaxis.update({'domain': [0, .5]})\n", "figure.layout.xaxis2.update({'domain': [0.6, 1.]})\n", + "\n", "# The graph's yaxis MUST BE anchored to the graph's xaxis\n", "figure.layout.yaxis2.update({'anchor': 'x2'})\n", "figure.layout.yaxis2.update({'title': 'Goals'})\n", + "\n", "# Update the margins to add a title and see graph x-labels. \n", "figure.layout.margin.update({'t':50, 'b':100})\n", "figure.layout.update({'title': '2016 Hockey Stats'})\n", @@ -267,7 +292,7 @@ }, { "cell_type": "code", - "execution_count": 8, + "execution_count": 7, "metadata": {}, "outputs": [ { @@ -279,7 +304,7 @@ "" ] }, - "execution_count": 8, + "execution_count": 7, "metadata": {}, "output_type": "execute_result" } @@ -297,6 +322,7 @@ " ['Boston
Bruins', 13, 8, 0],\n", " ['Chicago
Blackhawks', 13, 8, 0],\n", " ['Ottawa
Senators', 12, 5, 0]]\n", + "\n", "# Initialize a figure with ff.create_table(table_data)\n", "figure = ff.create_table(table_data, height_constant=60)\n", "\n", @@ -305,6 +331,7 @@ " 'Boston Bruins', 'Chicago Blackhawks', 'Ottawa Senators']\n", "GFPG = [3.54, 3.48, 3.0, 3.27, 2.83, 3.18]\n", "GAPG = [2.17, 2.57, 2.0, 2.91, 2.57, 2.77]\n", + "\n", "# Make traces for graph\n", "trace1 = go.Bar(x=teams, y=GFPG, xaxis='x2', yaxis='y2',\n", " marker=dict(color='#0099ff'),\n", @@ -314,18 +341,25 @@ " name='Goals Against
Per Game')\n", "\n", "# Add trace data to figure\n", - "figure['data'].extend(go.Data([trace1, trace2]))\n", + "figure.add_traces([trace1, trace2])\n", + "\n", + "# initialize xaxis2 and yaxis2\n", + "figure['layout']['xaxis2'] = {}\n", + "figure['layout']['yaxis2'] = {}\n", "\n", "# Edit layout for subplots\n", "figure.layout.yaxis.update({'domain': [0, .45]})\n", "figure.layout.yaxis2.update({'domain': [.6, 1]})\n", + "\n", "# The graph's yaxis2 MUST BE anchored to the graph's xaxis2 and vice versa\n", "figure.layout.yaxis2.update({'anchor': 'x2'})\n", "figure.layout.xaxis2.update({'anchor': 'y2'})\n", "figure.layout.yaxis2.update({'title': 'Goals'})\n", + "\n", "# Update the margins to add a title and see graph x-labels. \n", "figure.layout.margin.update({'t':75, 'l':50})\n", "figure.layout.update({'title': '2016 Hockey Stats'})\n", + "\n", "# Update the height because adding a graph vertically will interact with\n", "# the plot height calculated for the table\n", "figure.layout.update({'height':800})\n", @@ -370,20 +404,6 @@ }, "metadata": {}, "output_type": "display_data" - }, - { - "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": [ @@ -400,7 +420,7 @@ " 'Subplots with Plotly Figure Factory Charts',\n", " title= 'Figure Factory Subplots in Python | plotly',\n", " name = 'Figure Factory Subplots',\n", - " has_thumbnail='true', thumbnail='thumbnail/ff-subplots.jpg', \n", + " has_thumbnail='true', thumbnail='thumbnail/ff-subplots.jpg',\n", " language='python', \n", " display_as='multiple_axes', order=10,\n", " ipynb= '~PythonPlotBot/1828')" @@ -433,7 +453,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython2", - "version": "2.7.11" + "version": "2.7.12" } }, "nbformat": 4,