|
@@ -1,507 +0,0 @@
|
|
|
-{
|
|
|
- "cells": [
|
|
|
- {
|
|
|
- "cell_type": "markdown",
|
|
|
- "metadata": {},
|
|
|
- "source": [
|
|
|
- "# Introduction: Plotting with Plotly\n",
|
|
|
- "\n",
|
|
|
- "In this notebook, we will take a look at using the plotly library for plotting in Python. This library allows us to quickly make great plots and add interactive elements to our figures."
|
|
|
- ]
|
|
|
- },
|
|
|
- {
|
|
|
- "cell_type": "code",
|
|
|
- "execution_count": 1,
|
|
|
- "metadata": {
|
|
|
- "ExecuteTime": {
|
|
|
- "end_time": "2018-12-09T14:23:51.790476Z",
|
|
|
- "start_time": "2018-12-09T14:23:50.493881Z"
|
|
|
- }
|
|
|
- },
|
|
|
- "outputs": [],
|
|
|
- "source": [
|
|
|
- "# Standard data science libraries\n",
|
|
|
- "import pandas as pd\n",
|
|
|
- "import numpy as np\n",
|
|
|
- "from scipy import stats\n",
|
|
|
- "import featuretools as ft\n",
|
|
|
- "\n",
|
|
|
- "# Visualization\n",
|
|
|
- "import matplotlib.pyplot as plt\n",
|
|
|
- "import seaborn as sns\n",
|
|
|
- "plt.style.use('bmh')\n",
|
|
|
- "\n",
|
|
|
- "# Options for pandas\n",
|
|
|
- "pd.options.display.max_columns = 20\n",
|
|
|
- "\n",
|
|
|
- "# Display all cell outputs\n",
|
|
|
- "from IPython.core.interactiveshell import InteractiveShell\n",
|
|
|
- "InteractiveShell.ast_node_interactivity = 'all'\n"
|
|
|
- ]
|
|
|
- },
|
|
|
- {
|
|
|
- "cell_type": "code",
|
|
|
- "execution_count": 5,
|
|
|
- "metadata": {
|
|
|
- "ExecuteTime": {
|
|
|
- "end_time": "2018-12-09T14:26:08.588372Z",
|
|
|
- "start_time": "2018-12-09T14:26:06.974868Z"
|
|
|
- }
|
|
|
- },
|
|
|
- "outputs": [
|
|
|
- {
|
|
|
- "data": {
|
|
|
- "text/html": [
|
|
|
- "<iframe id=\"igraph\" scrolling=\"no\" style=\"border:none;\" seamless=\"seamless\" src=\"https://plot.ly/~wjk68/13.embed\" height=\"525px\" width=\"100%\"></iframe>"
|
|
|
- ],
|
|
|
- "text/plain": [
|
|
|
- "<plotly.tools.PlotlyDisplay object>"
|
|
|
- ]
|
|
|
- },
|
|
|
- "execution_count": 5,
|
|
|
- "metadata": {},
|
|
|
- "output_type": "execute_result"
|
|
|
- }
|
|
|
- ],
|
|
|
- "source": [
|
|
|
- "import plotly.plotly as py\n",
|
|
|
- "import plotly.graph_objs as go\n",
|
|
|
- "\n",
|
|
|
- "trace1 = go.Scatter(x=[1,2,3], y=[10,5,6], marker={'color': 'red', 'symbol': 104, 'size': 10}, \n",
|
|
|
- " mode=\"markers+lines\", text=[\"one\",\"two\",\"three\"], name='1st Trace')\n",
|
|
|
- " \n",
|
|
|
- "data=go.Data([trace1])\n",
|
|
|
- "layout=go.Layout(title=\"First Plot\", xaxis={'title':'x1'}, yaxis={'title':'x2'})\n",
|
|
|
- "figure=go.Figure(data=data,layout=layout)\n",
|
|
|
- "py.iplot(figure, filename='pyguide_1')"
|
|
|
- ]
|
|
|
- },
|
|
|
- {
|
|
|
- "cell_type": "code",
|
|
|
- "execution_count": 6,
|
|
|
- "metadata": {
|
|
|
- "ExecuteTime": {
|
|
|
- "end_time": "2018-12-09T16:51:09.084641Z",
|
|
|
- "start_time": "2018-12-09T16:51:07.771289Z"
|
|
|
- }
|
|
|
- },
|
|
|
- "outputs": [
|
|
|
- {
|
|
|
- "data": {
|
|
|
- "text/plain": [
|
|
|
- "Figure({\n",
|
|
|
- " 'data': [{'marker': {'color': 'red', 'size': 10, 'symbol': 104},\n",
|
|
|
- " 'mode': 'markers+lines',\n",
|
|
|
- " 'name': '1st Trace',\n",
|
|
|
- " 'text': [one, two, three],\n",
|
|
|
- " 'type': 'scatter',\n",
|
|
|
- " 'uid': '5dc16f36-fbbe-11e8-a878-acde48001122',\n",
|
|
|
- " 'x': [1, 2, 3],\n",
|
|
|
- " 'y': [10, 5, 6]}],\n",
|
|
|
- " 'layout': {'title': 'Plot update', 'xaxis': {'title': 'x1'}, 'yaxis': {'title': 'x2'}}\n",
|
|
|
- "})"
|
|
|
- ]
|
|
|
- },
|
|
|
- "execution_count": 6,
|
|
|
- "metadata": {},
|
|
|
- "output_type": "execute_result"
|
|
|
- },
|
|
|
- {
|
|
|
- "data": {
|
|
|
- "text/html": [
|
|
|
- "<iframe id=\"igraph\" scrolling=\"no\" style=\"border:none;\" seamless=\"seamless\" src=\"https://plot.ly/~wjk68/15.embed\" height=\"525px\" width=\"100%\"></iframe>"
|
|
|
- ],
|
|
|
- "text/plain": [
|
|
|
- "<plotly.tools.PlotlyDisplay object>"
|
|
|
- ]
|
|
|
- },
|
|
|
- "execution_count": 6,
|
|
|
- "metadata": {},
|
|
|
- "output_type": "execute_result"
|
|
|
- }
|
|
|
- ],
|
|
|
- "source": [
|
|
|
- "figure.update(dict(layout=dict(title='Plot update'), data=dict(marker=dict(color='blue'))))\n",
|
|
|
- "py.iplot(figure, filename='pyguide_2')"
|
|
|
- ]
|
|
|
- },
|
|
|
- {
|
|
|
- "cell_type": "code",
|
|
|
- "execution_count": 13,
|
|
|
- "metadata": {
|
|
|
- "ExecuteTime": {
|
|
|
- "end_time": "2018-12-09T17:09:08.724233Z",
|
|
|
- "start_time": "2018-12-09T17:09:06.805967Z"
|
|
|
- }
|
|
|
- },
|
|
|
- "outputs": [
|
|
|
- {
|
|
|
- "data": {
|
|
|
- "text/html": [
|
|
|
- "<iframe id=\"igraph\" scrolling=\"no\" style=\"border:none;\" seamless=\"seamless\" src=\"https://plot.ly/~wjk68/13.embed\" height=\"525px\" width=\"100%\"></iframe>"
|
|
|
- ],
|
|
|
- "text/plain": [
|
|
|
- "<plotly.tools.PlotlyDisplay object>"
|
|
|
- ]
|
|
|
- },
|
|
|
- "execution_count": 13,
|
|
|
- "metadata": {},
|
|
|
- "output_type": "execute_result"
|
|
|
- }
|
|
|
- ],
|
|
|
- "source": [
|
|
|
- "x = pd.date_range(pd.datetime(2018, 3, 1), pd.datetime(2018, 12, 1))\n",
|
|
|
- "y = np.random.randn(len(x))\n",
|
|
|
- "\n",
|
|
|
- "trace1 = go.Scatter(x=x, y=y, marker={'color': 'red', 'symbol': 104, 'size': 10}, \n",
|
|
|
- " mode=\"markers+lines\", name='1st Trace')\n",
|
|
|
- " \n",
|
|
|
- "#data=go.Scatter([trace1])\n",
|
|
|
- "layout=go.Layout(title=\"First Plot\", xaxis={'title':'x1'}, yaxis={'title':'x2'})\n",
|
|
|
- "figure=go.Figure(data=[trace1],\n",
|
|
|
- " layout=layout)\n",
|
|
|
- "py.iplot(figure, filename='pyguide_1')"
|
|
|
- ]
|
|
|
- },
|
|
|
- {
|
|
|
- "cell_type": "code",
|
|
|
- "execution_count": 18,
|
|
|
- "metadata": {
|
|
|
- "ExecuteTime": {
|
|
|
- "end_time": "2018-12-09T17:13:46.753471Z",
|
|
|
- "start_time": "2018-12-09T17:13:46.746181Z"
|
|
|
- }
|
|
|
- },
|
|
|
- "outputs": [],
|
|
|
- "source": [
|
|
|
- "line1 = go.Scatter(x=[pd.datetime(2018, 12, 1, 5, 30),\n",
|
|
|
- " pd.datetime(2018, 12, 1, 5, 30)], \n",
|
|
|
- " y = [0, 2], mode = 'lines')"
|
|
|
- ]
|
|
|
- },
|
|
|
- {
|
|
|
- "cell_type": "code",
|
|
|
- "execution_count": 20,
|
|
|
- "metadata": {
|
|
|
- "ExecuteTime": {
|
|
|
- "end_time": "2018-12-09T17:13:59.767756Z",
|
|
|
- "start_time": "2018-12-09T17:13:57.685957Z"
|
|
|
- }
|
|
|
- },
|
|
|
- "outputs": [
|
|
|
- {
|
|
|
- "name": "stderr",
|
|
|
- "output_type": "stream",
|
|
|
- "text": [
|
|
|
- "/usr/local/lib/python3.6/site-packages/IPython/core/display.py:689: UserWarning:\n",
|
|
|
- "\n",
|
|
|
- "Consider using IPython.display.IFrame instead\n",
|
|
|
- "\n"
|
|
|
- ]
|
|
|
- },
|
|
|
- {
|
|
|
- "data": {
|
|
|
- "text/html": [
|
|
|
- "<iframe id=\"igraph\" scrolling=\"no\" style=\"border:none;\" seamless=\"seamless\" src=\"https://plot.ly/~wjk68/13.embed\" height=\"525px\" width=\"100%\"></iframe>"
|
|
|
- ],
|
|
|
- "text/plain": [
|
|
|
- "<plotly.tools.PlotlyDisplay object>"
|
|
|
- ]
|
|
|
- },
|
|
|
- "execution_count": 20,
|
|
|
- "metadata": {},
|
|
|
- "output_type": "execute_result"
|
|
|
- }
|
|
|
- ],
|
|
|
- "source": [
|
|
|
- "x = pd.date_range(pd.datetime(2018, 12, 1, 2, 30), \n",
|
|
|
- " pd.datetime(2018, 12, 1, 14, 30),\n",
|
|
|
- " freq = '15 min')\n",
|
|
|
- "y = np.random.randn(len(x))\n",
|
|
|
- "\n",
|
|
|
- "trace1 = go.Scatter(x=x, y=y, marker={'color': 'red', 'symbol': 104, 'size': 10}, \n",
|
|
|
- " mode=\"markers+lines\", name='1st Trace')\n",
|
|
|
- " \n",
|
|
|
- "#data=go.Scatter([trace1])\n",
|
|
|
- "layout=go.Layout(title=\"First Plot with vertical line\", xaxis={'title':'x1'}, yaxis={'title':'x2'})\n",
|
|
|
- "figure=go.Figure(data=[trace1, line1],\n",
|
|
|
- " layout=layout)\n",
|
|
|
- "py.iplot(figure, filename='pyguide_1')"
|
|
|
- ]
|
|
|
- },
|
|
|
- {
|
|
|
- "cell_type": "code",
|
|
|
- "execution_count": 24,
|
|
|
- "metadata": {
|
|
|
- "ExecuteTime": {
|
|
|
- "end_time": "2018-12-09T17:21:40.308277Z",
|
|
|
- "start_time": "2018-12-09T17:21:40.211468Z"
|
|
|
- }
|
|
|
- },
|
|
|
- "outputs": [
|
|
|
- {
|
|
|
- "data": {
|
|
|
- "text/html": [
|
|
|
- "<div>\n",
|
|
|
- "<style scoped>\n",
|
|
|
- " .dataframe tbody tr th:only-of-type {\n",
|
|
|
- " vertical-align: middle;\n",
|
|
|
- " }\n",
|
|
|
- "\n",
|
|
|
- " .dataframe tbody tr th {\n",
|
|
|
- " vertical-align: top;\n",
|
|
|
- " }\n",
|
|
|
- "\n",
|
|
|
- " .dataframe thead th {\n",
|
|
|
- " text-align: right;\n",
|
|
|
- " }\n",
|
|
|
- "</style>\n",
|
|
|
- "<table border=\"1\" class=\"dataframe\">\n",
|
|
|
- " <thead>\n",
|
|
|
- " <tr style=\"text-align: right;\">\n",
|
|
|
- " <th></th>\n",
|
|
|
- " <th>10726</th>\n",
|
|
|
- " </tr>\n",
|
|
|
- " </thead>\n",
|
|
|
- " <tbody>\n",
|
|
|
- " <tr>\n",
|
|
|
- " <th>count</th>\n",
|
|
|
- " <td>34810.000000</td>\n",
|
|
|
- " </tr>\n",
|
|
|
- " <tr>\n",
|
|
|
- " <th>mean</th>\n",
|
|
|
- " <td>5016.113806</td>\n",
|
|
|
- " </tr>\n",
|
|
|
- " <tr>\n",
|
|
|
- " <th>std</th>\n",
|
|
|
- " <td>1132.176968</td>\n",
|
|
|
- " </tr>\n",
|
|
|
- " <tr>\n",
|
|
|
- " <th>min</th>\n",
|
|
|
- " <td>441.600000</td>\n",
|
|
|
- " </tr>\n",
|
|
|
- " <tr>\n",
|
|
|
- " <th>25%</th>\n",
|
|
|
- " <td>4121.600000</td>\n",
|
|
|
- " </tr>\n",
|
|
|
- " <tr>\n",
|
|
|
- " <th>50%</th>\n",
|
|
|
- " <td>4710.400000</td>\n",
|
|
|
- " </tr>\n",
|
|
|
- " <tr>\n",
|
|
|
- " <th>75%</th>\n",
|
|
|
- " <td>5740.800000</td>\n",
|
|
|
- " </tr>\n",
|
|
|
- " <tr>\n",
|
|
|
- " <th>max</th>\n",
|
|
|
- " <td>9420.800000</td>\n",
|
|
|
- " </tr>\n",
|
|
|
- " </tbody>\n",
|
|
|
- "</table>\n",
|
|
|
- "</div>"
|
|
|
- ],
|
|
|
- "text/plain": [
|
|
|
- " 10726\n",
|
|
|
- "count 34810.000000\n",
|
|
|
- "mean 5016.113806\n",
|
|
|
- "std 1132.176968\n",
|
|
|
- "min 441.600000\n",
|
|
|
- "25% 4121.600000\n",
|
|
|
- "50% 4710.400000\n",
|
|
|
- "75% 5740.800000\n",
|
|
|
- "max 9420.800000"
|
|
|
- ]
|
|
|
- },
|
|
|
- "execution_count": 24,
|
|
|
- "metadata": {},
|
|
|
- "output_type": "execute_result"
|
|
|
- }
|
|
|
- ],
|
|
|
- "source": [
|
|
|
- "df = pd.read_csv('ESB_power.csv', parse_dates = ['measured_at'])\n",
|
|
|
- "df.describe()"
|
|
|
- ]
|
|
|
- },
|
|
|
- {
|
|
|
- "cell_type": "code",
|
|
|
- "execution_count": 27,
|
|
|
- "metadata": {
|
|
|
- "ExecuteTime": {
|
|
|
- "end_time": "2018-12-09T17:23:54.272668Z",
|
|
|
- "start_time": "2018-12-09T17:23:49.753718Z"
|
|
|
- }
|
|
|
- },
|
|
|
- "outputs": [
|
|
|
- {
|
|
|
- "name": "stdout",
|
|
|
- "output_type": "stream",
|
|
|
- "text": [
|
|
|
- "The draw time for this plot will be slow for clients without much RAM.\n"
|
|
|
- ]
|
|
|
- },
|
|
|
- {
|
|
|
- "data": {
|
|
|
- "text/html": [
|
|
|
- "<iframe id=\"igraph\" scrolling=\"no\" style=\"border:none;\" seamless=\"seamless\" src=\"https://plot.ly/~wjk68/13.embed\" height=\"525px\" width=\"100%\"></iframe>"
|
|
|
- ],
|
|
|
- "text/plain": [
|
|
|
- "<plotly.tools.PlotlyDisplay object>"
|
|
|
- ]
|
|
|
- },
|
|
|
- "execution_count": 27,
|
|
|
- "metadata": {},
|
|
|
- "output_type": "execute_result"
|
|
|
- }
|
|
|
- ],
|
|
|
- "source": [
|
|
|
- "x = df['measured_at']\n",
|
|
|
- "y = df['10726']\n",
|
|
|
- "\n",
|
|
|
- "trace1 = go.Scatter(x=x, y=y, marker={'color': 'red', 'symbol': 104, 'size': 10}, \n",
|
|
|
- " mode=\"markers+lines\", name='1st Trace')\n",
|
|
|
- " \n",
|
|
|
- "#data=go.Scatter([trace1])\n",
|
|
|
- "layout=go.Layout(title=\"First Plot with vertical line\", xaxis={'title':'x1'}, yaxis={'title':'x2'})\n",
|
|
|
- "figure=go.Figure(data=[trace1],\n",
|
|
|
- " layout=layout)\n",
|
|
|
- "py.iplot(figure, filename='pyguide_1')"
|
|
|
- ]
|
|
|
- },
|
|
|
- {
|
|
|
- "cell_type": "code",
|
|
|
- "execution_count": 35,
|
|
|
- "metadata": {
|
|
|
- "ExecuteTime": {
|
|
|
- "end_time": "2018-12-09T17:59:22.589569Z",
|
|
|
- "start_time": "2018-12-09T17:59:22.585532Z"
|
|
|
- }
|
|
|
- },
|
|
|
- "outputs": [
|
|
|
- {
|
|
|
- "data": {
|
|
|
- "text/plain": [
|
|
|
- "datetime.date(2017, 12, 6)"
|
|
|
- ]
|
|
|
- },
|
|
|
- "execution_count": 35,
|
|
|
- "metadata": {},
|
|
|
- "output_type": "execute_result"
|
|
|
- }
|
|
|
- ],
|
|
|
- "source": [
|
|
|
- "pd.datetime(2017, 12, 6).date()"
|
|
|
- ]
|
|
|
- },
|
|
|
- {
|
|
|
- "cell_type": "code",
|
|
|
- "execution_count": 40,
|
|
|
- "metadata": {
|
|
|
- "ExecuteTime": {
|
|
|
- "end_time": "2018-12-09T18:00:28.342586Z",
|
|
|
- "start_time": "2018-12-09T18:00:26.951855Z"
|
|
|
- }
|
|
|
- },
|
|
|
- "outputs": [
|
|
|
- {
|
|
|
- "data": {
|
|
|
- "text/html": [
|
|
|
- "<iframe id=\"igraph\" scrolling=\"no\" style=\"border:none;\" seamless=\"seamless\" src=\"https://plot.ly/~wjk68/13.embed\" height=\"525px\" width=\"100%\"></iframe>"
|
|
|
- ],
|
|
|
- "text/plain": [
|
|
|
- "<plotly.tools.PlotlyDisplay object>"
|
|
|
- ]
|
|
|
- },
|
|
|
- "execution_count": 40,
|
|
|
- "metadata": {},
|
|
|
- "output_type": "execute_result"
|
|
|
- }
|
|
|
- ],
|
|
|
- "source": [
|
|
|
- "x = list(df.loc[df['measured_at'].dt.date == pd.datetime(2018, 3, 18).date(),\n",
|
|
|
- " 'measured_at'])\n",
|
|
|
- "y = list(df.loc[df['measured_at'].dt.date == pd.datetime(2018, 3, 18).date(),\n",
|
|
|
- " '10726'])\n",
|
|
|
- "\n",
|
|
|
- "trace1 = go.Scatter(x=x, y=y, marker={'color': 'red', 'symbol': 104, 'size': 10}, \n",
|
|
|
- " mode=\"markers+lines\", name='1st Trace')\n",
|
|
|
- " \n",
|
|
|
- "#data=go.Scatter([trace1])\n",
|
|
|
- "layout=go.Layout(title=\"First Plot with vertical line\", xaxis={'title':'x1'}, yaxis={'title':'x2'})\n",
|
|
|
- "figure=go.Figure(data=[trace1],\n",
|
|
|
- " layout=layout)\n",
|
|
|
- "py.iplot(figure, filename='pyguide_1')"
|
|
|
- ]
|
|
|
- },
|
|
|
- {
|
|
|
- "cell_type": "code",
|
|
|
- "execution_count": null,
|
|
|
- "metadata": {},
|
|
|
- "outputs": [],
|
|
|
- "source": []
|
|
|
- }
|
|
|
- ],
|
|
|
- "metadata": {
|
|
|
- "hide_input": false,
|
|
|
- "kernelspec": {
|
|
|
- "display_name": "Python 3",
|
|
|
- "language": "python",
|
|
|
- "name": "python3"
|
|
|
- },
|
|
|
- "language_info": {
|
|
|
- "codemirror_mode": {
|
|
|
- "name": "ipython",
|
|
|
- "version": 3
|
|
|
- },
|
|
|
- "file_extension": ".py",
|
|
|
- "mimetype": "text/x-python",
|
|
|
- "name": "python",
|
|
|
- "nbconvert_exporter": "python",
|
|
|
- "pygments_lexer": "ipython3",
|
|
|
- "version": "3.6.5"
|
|
|
- },
|
|
|
- "toc": {
|
|
|
- "base_numbering": 1,
|
|
|
- "nav_menu": {},
|
|
|
- "number_sections": true,
|
|
|
- "sideBar": true,
|
|
|
- "skip_h1_title": false,
|
|
|
- "title_cell": "Table of Contents",
|
|
|
- "title_sidebar": "Contents",
|
|
|
- "toc_cell": false,
|
|
|
- "toc_position": {},
|
|
|
- "toc_section_display": true,
|
|
|
- "toc_window_display": false
|
|
|
- },
|
|
|
- "varInspector": {
|
|
|
- "cols": {
|
|
|
- "lenName": 16,
|
|
|
- "lenType": 16,
|
|
|
- "lenVar": 40
|
|
|
- },
|
|
|
- "kernels_config": {
|
|
|
- "python": {
|
|
|
- "delete_cmd_postfix": "",
|
|
|
- "delete_cmd_prefix": "del ",
|
|
|
- "library": "var_list.py",
|
|
|
- "varRefreshCmd": "print(var_dic_list())"
|
|
|
- },
|
|
|
- "r": {
|
|
|
- "delete_cmd_postfix": ") ",
|
|
|
- "delete_cmd_prefix": "rm(",
|
|
|
- "library": "var_list.r",
|
|
|
- "varRefreshCmd": "cat(var_dic_list()) "
|
|
|
- }
|
|
|
- },
|
|
|
- "types_to_exclude": [
|
|
|
- "module",
|
|
|
- "function",
|
|
|
- "builtin_function_or_method",
|
|
|
- "instance",
|
|
|
- "_Feature"
|
|
|
- ],
|
|
|
- "window_display": false
|
|
|
- }
|
|
|
- },
|
|
|
- "nbformat": 4,
|
|
|
- "nbformat_minor": 2
|
|
|
-}
|