[Python-modules-commits] [python-mplexporter] 43/135: Added subplot example to plotly ipython notebook.

Wolfgang Borgert debacle at moszumanska.debian.org
Tue Sep 23 21:19:02 UTC 2014


This is an automated email from the git hooks/post-receive script.

debacle pushed a commit to branch master
in repository python-mplexporter.

commit 5aa9d06ab798fc646fe8e720795ba264697a50db
Author: theengineear <andseier at gmail.com>
Date:   Mon Feb 24 23:30:33 2014 -0800

    Added subplot example to plotly ipython notebook.
    
    That's all folks.
---
 notebooks/PlotlyTest.ipynb | 151 +++++++++++++++++++++++++++++++++++++++------
 1 file changed, 132 insertions(+), 19 deletions(-)

diff --git a/notebooks/PlotlyTest.ipynb b/notebooks/PlotlyTest.ipynb
index 4910c2b..71ad7f0 100644
--- a/notebooks/PlotlyTest.ipynb
+++ b/notebooks/PlotlyTest.ipynb
@@ -8,18 +8,43 @@
   {
    "cells": [
     {
+     "cell_type": "heading",
+     "level": 1,
+     "metadata": {},
+     "source": [
+      "Plotly, matplotlib, and mplexporter."
+     ]
+    },
+    {
+     "cell_type": "heading",
+     "level": 4,
+     "metadata": {},
+     "source": [
+      "Let's start by calling the IPython 'magic' function for matplotlib so that plots show up inline. The only import necessary to use plotly is the fig_to_plotly function."
+     ]
+    },
+    {
      "cell_type": "code",
      "collapsed": false,
      "input": [
       "%matplotlib inline\n",
       "import matplotlib.pyplot as plt\n",
+      "import matplotlib.gridspec as gridspec\n",
       "import numpy as np\n",
       "from mplexporter.renderers import fig_to_plotly"
      ],
      "language": "python",
      "metadata": {},
      "outputs": [],
-     "prompt_number": 9
+     "prompt_number": 20
+    },
+    {
+     "cell_type": "heading",
+     "level": 4,
+     "metadata": {},
+     "source": [
+      "You can use the IPython.Demo username for now, or switch this for your own Plotly username and api_key. Don't have a username? You might try finding one at: https://plot.ly/"
+     ]
     },
     {
      "cell_type": "code",
@@ -31,23 +56,30 @@
      "language": "python",
      "metadata": {},
      "outputs": [],
-     "prompt_number": 11
+     "prompt_number": 21
+    },
+    {
+     "cell_type": "heading",
+     "level": 4,
+     "metadata": {},
+     "source": [
+      "Here we instantiate a matplotlib figure object and fill it with stuff we want to plot! IPython's matplotlib magic function will pop it inline after you run the code block."
+     ]
     },
     {
      "cell_type": "code",
      "collapsed": false,
      "input": [
-      "# setup matplotlib plot\n",
+      "fig1 = plt.figure()\n",
       "x = np.arange(0,1.0,0.01)\n",
       "y1 = np.sin(2*np.pi*x)\n",
       "y2 = np.cos(4*np.pi*x)\n",
-      "plt.plot(x, y1, 'b--', label='sin')\n",
-      "plt.plot(x, y2, 'ro', label='cos')\n",
-      "plt.title(\"It's a Sign\")\n",
-      "plt.xlabel('time')\n",
-      "plt.ylabel('amplitude')\n",
-      "# plt.legend().set_visible(True)\n",
-      "fig = plt.gcf()"
+      "ax = fig1.add_subplot(111)\n",
+      "ax.plot(x, y1, 'b--', label='sin')\n",
+      "ax.plot(x, y2, 'ro', label='cos')\n",
+      "ax.set_title(\"It's a Sign\")\n",
+      "ax.set_xlabel('time')\n",
+      "ax.set_ylabel('amplitude')"
      ],
      "language": "python",
      "metadata": {},
@@ -57,42 +89,123 @@
        "output_type": "display_data",
        "png": "iVBORw0KGgoAAAANSUhEUgAAAY0AAAEZCAYAAABrUHmEAAAABHNCSVQICAgIfAhkiAAAAAlwSFlz\nAAALEgAACxIB0t1+/AAAIABJREFUeJzt3XtcFdXaB/DfRvCOgKiEwAndeBRFETMVfRW0EEQlu6m9\nnaOmmaV5qc57NNC8lL6a1ZuXjpnlpZOV5fHKxcwS9KSItyNeUUgNUFATRVFDYb1/DCCXvdnD3nNZ\nM/N8P5/94bJnzzyz1mIWM7PWMybGGAMhhBAigpPaARBCCNEO6jQIIYSIRp0GIYQQ0ajTIIQQIhp1\nGoQQQkSjToMQQoho1GkQwpG9e/eiQ4cOaodBiFXUaRBD8ff3x88//wwAWLt2Lfr27Vvl/TFjxmDd\nunWyxnDy5EkMHDgQnp6e8PDwQPfu3ZGUlAQA6Nu3L86cOSPr9glxhLPaARCiJJPJ5ND7Uhg6dCgm\nTZqExMREM [...]
        "text": [
-        "<matplotlib.figure.Figure at 0x10f855c90>"
+        "<matplotlib.figure.Figure at 0x10b4413d0>"
        ]
       }
      ],
-     "prompt_number": 12
+     "prompt_number": 30
+    },
+    {
+     "cell_type": "heading",
+     "level": 4,
+     "metadata": {},
+     "source": [
+      "Like keeping your data around? Want to share your plots and/or data online? The following line takes the matplotlib figure object, extracts the data with mplexporter, renders a new plot with PlotlyRenderer, and sends it to Plotly. The plot shows up inline because of the 'notebook=True' keyword argument. This causes the fig_to_plotly function to call 'plotly.iplot' (IPython plot) instead of the normal 'plotly.plot' function. Taking that keyword argument out defaults to the normal p [...]
+      "\n",
+      "Note how you can zoom, pan, autoscale, and see data points by hovering. The data you plotted is right there. If you want to change the style, layout, etc. on plotly, you can click the link below the plot."
+     ]
     },
     {
      "cell_type": "code",
      "collapsed": false,
      "input": [
-      "fig_to_plotly(fig, username, api_key, notebook=True)"
+      "fig_to_plotly(fig1, username, api_key, notebook=True)"
      ],
      "language": "python",
      "metadata": {},
      "outputs": [
       {
        "html": [
-        "<iframe height=\"500\" id=\"igraph\" scrolling=\"no\" seamless=\"seamless\" src=\"https://plot.ly/~IPython.Demo/1190/600/450\" width=\"650\"></iframe>"
+        "<iframe height=\"500\" id=\"igraph\" scrolling=\"no\" seamless=\"seamless\" src=\"https://plot.ly/~IPython.Demo/1261/600/450\" width=\"650\"></iframe>"
        ],
        "metadata": {},
        "output_type": "pyout",
-       "prompt_number": 13,
+       "prompt_number": 31,
+       "text": [
+        "<IPython.core.display.HTML at 0x10b47ea10>"
+       ]
+      }
+     ],
+     "prompt_number": 31
+    },
+    {
+     "cell_type": "heading",
+     "level": 4,
+     "metadata": {},
+     "source": [
+      "But why have one axes object when you could have five!? Gridspec is a handy way to partition figure space into nice looking subplots. Here are just some simple line plots stretching over a 3x3 grid of plotting areas."
+     ]
+    },
+    {
+     "cell_type": "code",
+     "collapsed": false,
+     "input": [
+      "fig2 = plt.figure() # matplotlib.figure.Figure obj\n",
+      "gs = gridspec.GridSpec(3, 3)\n",
+      "ax1 = fig2.add_subplot(gs[0,:])\n",
+      "ax1.plot([1,2,3,4,5], [10,5,10,5,10], 'r-')\n",
+      "ax2 = fig2.add_subplot(gs[1,:-1])\n",
+      "ax2.plot([1,2,3,4], [1,4,9,16], 'k-')\n",
+      "ax3 = fig2.add_subplot(gs[1:, 2])\n",
+      "ax3.plot([1,2,3,4], [1,10,100,1000], 'b-')\n",
+      "ax4 = fig2.add_subplot(gs[2,0])\n",
+      "ax4.plot([1,2,3,4], [0,0,1,1], 'g-')\n",
+      "ax5 = fig2.add_subplot(gs[2,1])\n",
+      "ax5.plot([1,2,3,4], [1,0,0,1], 'c-')\n",
+      "gs.update(wspace=0.5, hspace=0.5)"
+     ],
+     "language": "python",
+     "metadata": {},
+     "outputs": [
+      {
+       "metadata": {},
+       "output_type": "display_data",
+       "png": "iVBORw0KGgoAAAANSUhEUgAAAXcAAAEACAYAAABI5zaHAAAABHNCSVQICAgIfAhkiAAAAAlwSFlz\nAAALEgAACxIB0t1+/AAAIABJREFUeJztnXtc1HX2/18odFELQwUSMJT7iMKYSda6oYgmBrnrpTCV\n1KzN3bx8d7fMfbRqv0L6umVaq13WXLQU+1qrZkppcVuFMEWzSEGFBARK0BTRQOb8/phm5DL3ec9n\nPp+Z83w8eMDMfD7v9+Gc+Zw5cz7nvN8eRERgGIZhXIpuzhaAYRiGEQ87d4ZhGBeEnTvDMIwLws6d\nYRjGBWHnzjAM44Kwc2cYhnFBrHLuc+bMgZ+fH4YMGaJ/rrGxEYmJiQgPD8e4ceNw8eJF4UIyDMMw\n1mGVc589ezays7M7PJeRkYHExESUlZUhISEBGRkZQgVkGIZhrMfD2iamyspKJCcn4/jx4wCAyMhI\n5OXlwc/PD [...]
        "text": [
-        "<IPython.core.display.HTML at 0x10f86c1d0>"
+        "<matplotlib.figure.Figure at 0x10b1f7290>"
        ]
       }
      ],
-     "prompt_number": 13
+     "prompt_number": 26
+    },
+    {
+     "cell_type": "heading",
+     "level": 4,
+     "metadata": {},
+     "source": [
+      "Again, a simple line of code sends the above figure to Plotly and it responds by sticking back into this notebook."
+     ]
     },
     {
      "cell_type": "code",
      "collapsed": false,
-     "input": [],
+     "input": [
+      "fig_to_plotly(fig2, username=username, api_key=api_key, notebook=True)"
+     ],
      "language": "python",
      "metadata": {},
-     "outputs": []
+     "outputs": [
+      {
+       "html": [
+        "<iframe height=\"500\" id=\"igraph\" scrolling=\"no\" seamless=\"seamless\" src=\"https://plot.ly/~IPython.Demo/1262/600/450\" width=\"650\"></iframe>"
+       ],
+       "metadata": {},
+       "output_type": "pyout",
+       "prompt_number": 32,
+       "text": [
+        "<IPython.core.display.HTML at 0x10b3ea690>"
+       ]
+      }
+     ],
+     "prompt_number": 32
+    },
+    {
+     "cell_type": "heading",
+     "level": 4,
+     "metadata": {},
+     "source": [
+      "Follow and/or contribute to the mplexporter progress at: https://github.com/mpld3/mplexporter"
+     ]
     }
    ],
    "metadata": {}

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/python-modules/packages/python-mplexporter.git



More information about the Python-modules-commits mailing list