From 18a116762596956affe56b5c2a51f29e6253516f Mon Sep 17 00:00:00 2001 From: dinkel <kevin.dinkel@jpl.nasa.gov> Date: Thu, 4 Jun 2015 09:11:41 -0700 Subject: [PATCH] updated tester example --- SimpleTester.ipynb | 426 --------------------------------- examples/PyDyGraphTester.ipynb | 37 ++- 2 files changed, 33 insertions(+), 430 deletions(-) delete mode 100644 SimpleTester.ipynb diff --git a/SimpleTester.ipynb b/SimpleTester.ipynb deleted file mode 100644 index d281e89..0000000 --- a/SimpleTester.ipynb +++ /dev/null @@ -1,426 +0,0 @@ -{ - "metadata": { - "kernelspec": { - "codemirror_mode": { - "name": "ipython", - "version": 2 - }, - "display_name": "IPython (Python 2)", - "language": "python", - "name": "python2" - }, - "name": "", - "signature": "sha256:1a4e3ec53b6c3e946d0a591ceec6a6bb5268fcad9914d0a6ea463d62968d86b8" - }, - "nbformat": 3, - "nbformat_minor": 0, - "worksheets": [ - { - "cells": [ - { - "cell_type": "code", - "collapsed": false, - "input": [ - "# Import pydygraphs and numpy\n", - "\n", - "import pydygraphs\n", - "import numpy as np" - ], - "language": "python", - "metadata": {}, - "outputs": [], - "prompt_number": 1 - }, - { - "cell_type": "code", - "collapsed": false, - "input": [ - "# Single Figure Example\n", - "fig = pydygraphs.figure(width = 600, height = 400)\n", - "\n", - "# Form data for plot\n", - "x = np.array(range(1000))\n", - "y = [np.sin(np.random.rand(1000)),-np.sin(np.random.rand(1000))]\n", - "\n", - "# Plot figure\n", - "fig.plot(x,y, color=['navy','magenta'])\n", - "fig.title(\"Figure 1\")\n", - "fig.xlabel('Series')\n", - "fig.ylabel('Value')\n", - "\n", - "# Show figure:\n", - "fig.show()" - ], - "language": "python", - "metadata": {}, - "outputs": [ - { - "html": [ - "\n", - " <script src=\"http://dygraphs.com/dygraph-combined.js\"></script>\n", - " <table style=\"width: 600px; border-style: hidden;\">\n", - " <tr><td style=\"border-style: hidden;\"><div id='Figure1' style=\"width: 600px; height: 400px;\"></div></td></tr>\n", - " <tr><td style=\"border-style: hidden;\"><div style=\"text-align:right; width: 600px; height: auto;\"; id='Figure1_legend'></div></td></tr>\n", - " </table>\n", - " " - ], - "metadata": {}, - "output_type": "display_data", - "text": [ - "<IPython.core.display.HTML object>" - ] - }, - { - "html": [ - "\n", - "\t <script type=\"text/javascript\">\n", - "\t function convertToDataTable_Figure1(d) {\n", - "\t var columns = _.keys(d);\n", - "\t var x_col = '_x_axis_label_';\n", - "\t columns.splice(columns.indexOf(x_col), 1); // Get index column. (prob index). Don't need to do this just to plot all\n", - "\t var out = [];\n", - "\t var i = 0;\n", - "\t for (var k in d[x_col]) {\n", - "\t var row = [d[x_col][k]];\n", - "\t columns.forEach(function(col) {\n", - "\t row.push(d[col][k]);\n", - "\t });\n", - "\t out.push(row);\n", - "\t }\n", - "\t return {data:out, labels:[x_col].concat(columns)};\n", - "\t }\n", - "\n", - "\t function handle_output_Figure1(out) {\n", - "\t var json = out.content.data['text/plain'];\n", - "\t var data = JSON.parse(eval(json));\n", - "\t var tabular = convertToDataTable_Figure1(data);\n", - "\t \n", - " g = new Dygraph(document.getElementById('Figure1'), tabular.data, {\n", - " legend: 'always',\n", - " labels: tabular.labels,\n", - " labelsDivStyles: { 'textAlign': 'right' },\n", - " rollPeriod: 1,\n", - " showRoller: true,\n", - " animatedZooms: true,\n", - "\t \n", - " showRoller: true,\n", - " \n", - " colors: [\"navy\",\"magenta\"],\n", - " \n", - " title: 'Figure 1',\n", - " xlabel: 'Series',\n", - " \n", - " ylabel: 'Value',\n", - " \n", - " labelsDiv: 'Figure1_legend',\n", - "\t errorBars: false\n", - "\t })\n", - "\t }\n", - "\t var kernel = IPython.notebook.kernel;\n", - "\t var callbacks_Figure1 = { 'iopub' : {'output' : handle_output_Figure1}};\n", - "\t kernel.execute(\"pydygraphs.__PYDYGRAPH__FIGURE__JSON__[1]\", callbacks_Figure1, {silent:false});\n", - "\t </script>\n", - "\t " - ], - "metadata": {}, - "output_type": "display_data", - "text": [ - "<IPython.core.display.HTML object>" - ] - } - ], - "prompt_number": 3 - }, - { - "cell_type": "code", - "collapsed": false, - "input": [ - "# Subplot example\n", - "[fig1],[fig2] = pydygraphs.subplot(2,1, title=\"PyDyGraphs Example Subplot\")\n", - "\n", - "# Form data for plot 1\n", - "x = np.array(range(100))\n", - "y1 = [np.sin(np.array(range(100)) * np.pi / 180.), np.sin(np.array(range(100)) * np.pi / 360)]\n", - "\n", - "# Plot figure 1\n", - "fig1.plot(x,y1)\n", - "fig1.title(\"Figure 1\")\n", - "fig1.xlabel('Series')\n", - "fig1.ylabel('Value')\n", - "\n", - "# Form data for plot 2\n", - "y2 = [np.sin(np.random.rand(100))]\n", - "\n", - "# Plot figure 2\n", - "fig2.plot(x, y2, ylabels=[\"Random Variable\"], color=['orange'], rangeselector=True, showroller=False)\n", - "fig2.title(\"Figure 2\")\n", - "fig2.xlabel('Series')\n", - "fig2.ylabel('Value')\n", - "\n", - "# Show plots:\n", - "fig1.show()\n", - "fig2.show()" - ], - "language": "python", - "metadata": {}, - "outputs": [ - { - "html": [ - "<script src=\"http://dygraphs.com/dygraph-combined.js\"></script>\n", - " <table style=\"width: 1050px; border-style: hidden;\">\n", - " <tr>\n", - " <th COLSPAN='1'>\n", - " <h1 align=\"center\">PyDyGraphs Example Subplot</h1>\n", - " </th>\n", - " <tr><tr><td style=\"border-style: hidden;\">\n", - " <script src=\"http://dygraphs.com/dygraph-combined.js\"></script>\n", - " <table style=\"width: 1050px; border-style: hidden;\">\n", - " <tr><td style=\"border-style: hidden;\"><div id='Figure2' style=\"width: 1050px; height: 200px;\"></div></td></tr>\n", - " <tr><td style=\"border-style: hidden;\"><div style=\"text-align:right; width: 1050px; height: auto;\"; id='Figure2_legend'></div></td></tr>\n", - " </table>\n", - " </td></tr><tr><td style=\"border-style: hidden;\">\n", - " <script src=\"http://dygraphs.com/dygraph-combined.js\"></script>\n", - " <table style=\"width: 1050px; border-style: hidden;\">\n", - " <tr><td style=\"border-style: hidden;\"><div id='Figure3' style=\"width: 1050px; height: 200px;\"></div></td></tr>\n", - " <tr><td style=\"border-style: hidden;\"><div style=\"text-align:right; width: 1050px; height: auto;\"; id='Figure3_legend'></div></td></tr>\n", - " </table>\n", - " </td></tr></table>" - ], - "metadata": {}, - "output_type": "display_data", - "text": [ - "<IPython.core.display.HTML object>" - ] - }, - { - "html": [ - "\n", - "\t <script type=\"text/javascript\">\n", - "\t function convertToDataTable_Figure2(d) {\n", - "\t var columns = _.keys(d);\n", - "\t var x_col = '_x_axis_label_';\n", - "\t columns.splice(columns.indexOf(x_col), 1); // Get index column. (prob index). Don't need to do this just to plot all\n", - "\t var out = [];\n", - "\t var i = 0;\n", - "\t for (var k in d[x_col]) {\n", - "\t var row = [d[x_col][k]];\n", - "\t columns.forEach(function(col) {\n", - "\t row.push(d[col][k]);\n", - "\t });\n", - "\t out.push(row);\n", - "\t }\n", - "\t return {data:out, labels:[x_col].concat(columns)};\n", - "\t }\n", - "\n", - "\t function handle_output_Figure2(out) {\n", - "\t var json = out.content.data['text/plain'];\n", - "\t var data = JSON.parse(eval(json));\n", - "\t var tabular = convertToDataTable_Figure2(data);\n", - "\t \n", - " g = new Dygraph(document.getElementById('Figure2'), tabular.data, {\n", - " legend: 'always',\n", - " labels: tabular.labels,\n", - " labelsDivStyles: { 'textAlign': 'right' },\n", - " rollPeriod: 1,\n", - " showRoller: true,\n", - " animatedZooms: true,\n", - "\t \n", - " showRoller: true,\n", - " \n", - " title: 'Figure 1',\n", - " xlabel: 'Series',\n", - " \n", - " ylabel: 'Value',\n", - " \n", - " labelsDiv: 'Figure2_legend',\n", - "\t errorBars: false\n", - "\t })\n", - "\t }\n", - "\t var kernel = IPython.notebook.kernel;\n", - "\t var callbacks_Figure2 = { 'iopub' : {'output' : handle_output_Figure2}};\n", - "\t kernel.execute(\"pydygraphs.__PYDYGRAPH__FIGURE__JSON__[2]\", callbacks_Figure2, {silent:false});\n", - "\t </script>\n", - "\t " - ], - "metadata": {}, - "output_type": "display_data", - "text": [ - "<IPython.core.display.HTML object>" - ] - }, - { - "html": [ - "\n", - "\t <script type=\"text/javascript\">\n", - "\t function convertToDataTable_Figure3(d) {\n", - "\t var columns = _.keys(d);\n", - "\t var x_col = '_x_axis_label_';\n", - "\t columns.splice(columns.indexOf(x_col), 1); // Get index column. (prob index). Don't need to do this just to plot all\n", - "\t var out = [];\n", - "\t var i = 0;\n", - "\t for (var k in d[x_col]) {\n", - "\t var row = [d[x_col][k]];\n", - "\t columns.forEach(function(col) {\n", - "\t row.push(d[col][k]);\n", - "\t });\n", - "\t out.push(row);\n", - "\t }\n", - "\t return {data:out, labels:[x_col].concat(columns)};\n", - "\t }\n", - "\n", - "\t function handle_output_Figure3(out) {\n", - "\t var json = out.content.data['text/plain'];\n", - "\t var data = JSON.parse(eval(json));\n", - "\t var tabular = convertToDataTable_Figure3(data);\n", - "\t \n", - " g = new Dygraph(document.getElementById('Figure3'), tabular.data, {\n", - " legend: 'always',\n", - " labels: tabular.labels,\n", - " labelsDivStyles: { 'textAlign': 'right' },\n", - " rollPeriod: 1,\n", - " showRoller: true,\n", - " animatedZooms: true,\n", - "\t \n", - " showRoller: false,\n", - " \n", - " colors: [\"orange\"],\n", - " \n", - " title: 'Figure 2',\n", - " xlabel: 'Series',\n", - " \n", - " ylabel: 'Value',\n", - " \n", - " showRangeSelector: true,\n", - " rangeSelectorHeight: 50,\n", - " \n", - " labelsDiv: 'Figure3_legend',\n", - "\t errorBars: false\n", - "\t })\n", - "\t }\n", - "\t var kernel = IPython.notebook.kernel;\n", - "\t var callbacks_Figure3 = { 'iopub' : {'output' : handle_output_Figure3}};\n", - "\t kernel.execute(\"pydygraphs.__PYDYGRAPH__FIGURE__JSON__[3]\", callbacks_Figure3, {silent:false});\n", - "\t </script>\n", - "\t " - ], - "metadata": {}, - "output_type": "display_data", - "text": [ - "<IPython.core.display.HTML object>" - ] - } - ], - "prompt_number": 4 - }, - { - "cell_type": "code", - "collapsed": false, - "input": [ - "## Dataframe example\n", - "import pandas as pd\n", - "import numpy as np\n", - "\n", - "# Form a dataframe\n", - "df = pd.DataFrame(columns=['a','b','c'])\n", - "df.a=np.arange(1000)\n", - "df.b=np.sin(df.a*0.02*np.pi/10) + (np.random.ranf(size=len(df.a))-0.5)*0.25\n", - "df.c=np.cos(df.a*np.pi/5)\n", - "\n", - "# Create a plot directly from a Pandas dataframe\n", - "fig3 = pydygraphs.figure()\n", - "xaxis = 'a'\n", - "fig3.plotDataFrame(df,xaxis)\n", - "fig3.xlabel('a');fig3.ylabel('Units of Awesome');fig3.title('Dataframe Example')\n", - "fig3.show()" - ], - "language": "python", - "metadata": {}, - "outputs": [ - { - "html": [ - "\n", - " <script src=\"http://dygraphs.com/dygraph-combined.js\"></script>\n", - " <table style=\"width: 1050px; border-style: hidden;\">\n", - " <tr><td style=\"border-style: hidden;\"><div id='Figure6' style=\"width: 1050px; height: 400px;\"></div></td></tr>\n", - " <tr><td style=\"border-style: hidden;\"><div style=\"text-align:right; width: 1050px; height: auto;\"; id='Figure6_legend'></div></td></tr>\n", - " </table>\n", - " " - ], - "metadata": {}, - "output_type": "display_data", - "text": [ - "<IPython.core.display.HTML object>" - ] - }, - { - "html": [ - "\n", - "\t <script type=\"text/javascript\">\n", - "\t function convertToDataTable_Figure6(d) {\n", - "\t var columns = _.keys(d);\n", - "\t var x_col = 'a';\n", - "\t columns.splice(columns.indexOf(x_col), 1); // Get index column. (prob index). Don't need to do this just to plot all\n", - "\t var out = [];\n", - "\t var i = 0;\n", - "\t for (var k in d[x_col]) {\n", - "\t var row = [d[x_col][k]];\n", - "\t columns.forEach(function(col) {\n", - "\t row.push(d[col][k]);\n", - "\t });\n", - "\t out.push(row);\n", - "\t }\n", - "\t return {data:out, labels:[x_col].concat(columns)};\n", - "\t }\n", - "\n", - "\t function handle_output_Figure6(out) {\n", - "\t var json = out.content.data['text/plain'];\n", - "\t var data = JSON.parse(eval(json));\n", - "\t var tabular = convertToDataTable_Figure6(data);\n", - "\t \n", - " g = new Dygraph(document.getElementById('Figure6'), tabular.data, {\n", - " legend: 'always',\n", - " labels: tabular.labels,\n", - " labelsDivStyles: { 'textAlign': 'right' },\n", - " rollPeriod: 1,\n", - " showRoller: true,\n", - " animatedZooms: true,\n", - "\t \n", - " showRoller: true,\n", - " \n", - " title: 'Dataframe Example',\n", - " xlabel: 'a',\n", - " \n", - " ylabel: 'Units of Awesome',\n", - " \n", - " labelsDiv: 'Figure6_legend',\n", - "\t errorBars: false\n", - "\t })\n", - "\t }\n", - "\t var kernel = IPython.notebook.kernel;\n", - "\t var callbacks_Figure6 = { 'iopub' : {'output' : handle_output_Figure6}};\n", - "\t kernel.execute(\"pydygraphs.__PYDYGRAPH__FIGURE__JSON__[6]\", callbacks_Figure6, {silent:false});\n", - "\t </script>\n", - "\t " - ], - "metadata": {}, - "output_type": "display_data", - "text": [ - "<IPython.core.display.HTML object>" - ] - } - ], - "prompt_number": 10 - }, - { - "cell_type": "code", - "collapsed": false, - "input": [], - "language": "python", - "metadata": {}, - "outputs": [] - } - ], - "metadata": {} - } - ] -} \ No newline at end of file diff --git a/examples/PyDyGraphTester.ipynb b/examples/PyDyGraphTester.ipynb index bde6f25..7efb904 100644 --- a/examples/PyDyGraphTester.ipynb +++ b/examples/PyDyGraphTester.ipynb @@ -1,7 +1,16 @@ { "metadata": { + "kernelspec": { + "codemirror_mode": { + "name": "ipython", + "version": 2 + }, + "display_name": "IPython (Python 2)", + "language": "python", + "name": "python2" + }, "name": "", - "signature": "sha256:37caa5f06b7f4da31df438b4f2c0f071c5f964d5b7af5d10b0ebc807bc3f3f88" + "signature": "sha256:1b51651295c302303f5424b95ea14e53f5a08ac2f302350cba87adc0cfc67799" }, "nbformat": 3, "nbformat_minor": 0, @@ -85,16 +94,36 @@ "cell_type": "code", "collapsed": false, "input": [ - "print pydygraphs.__PYDYGRAPH__DYGRAPHS_LIB_STRING__" + "## Dataframe example\n", + "import pandas as pd\n", + "import numpy as np\n", + "\n", + "# Form a dataframe\n", + "df = pd.DataFrame(columns=['a','b','c'])\n", + "df.a=np.arange(1000)\n", + "df.b=np.sin(df.a*0.02*np.pi/10) + (np.random.ranf(size=len(df.a))-0.5)*0.25\n", + "df.c=np.cos(df.a*np.pi/5)\n", + "\n", + "# Create a plot directly from a Pandas dataframe\n", + "fig3 = pydygraphs.figure()\n", + "xaxis = 'a'\n", + "fig3.plotDataFrame(df,xaxis)\n", + "fig3.xlabel('a');fig3.ylabel('Units of Awesome');fig3.title('Dataframe Example')\n", + "fig3.show()" ], "language": "python", "metadata": {}, "outputs": [] }, { - "cell_type": "raw", + "cell_type": "code", + "collapsed": false, + "input": [ + "print pydygraphs.__PYDYGRAPH__DYGRAPHS_LIB_STRING__" + ], + "language": "python", "metadata": {}, - "source": [] + "outputs": [] } ], "metadata": {}