{ "cells": [ { "cell_type": "markdown", "metadata": { "hide_input": false }, "source": [ "# pandas Data\n", "\n", "> Marcos Duarte \n", "> Laboratory of Biomechanics and Motor Control ([http://demotu.org/](http://demotu.org/)) \n", "> Federal University of ABC, Brazil" ] }, { "cell_type": "code", "execution_count": 1, "metadata": { "ExecuteTime": { "end_time": "2018-02-25T23:20:18.941681Z", "start_time": "2018-02-25T23:20:18.414004Z" } }, "outputs": [], "source": [ "import numpy as np\n", "import pandas as pd\n", "%matplotlib notebook\n", "# tk qt notebook inline ipympl\n", "import matplotlib as mpl\n", "import matplotlib.pyplot as plt\n", "import sys, os\n", "sys.path.insert(1, r'./../functions')" ] }, { "cell_type": "code", "execution_count": 2, "metadata": { "ExecuteTime": { "end_time": "2018-02-25T23:20:19.679727Z", "start_time": "2018-02-25T23:20:19.676725Z" } }, "outputs": [], "source": [ "path2 = r'./../../../X/Clau/'\n", "name = 'WBDS01walkT06mkr.txt'\n", "fname = os.path.join(path2, name)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## pandas with one index" ] }, { "cell_type": "code", "execution_count": 3, "metadata": { "ExecuteTime": { "end_time": "2018-02-25T23:20:21.249084Z", "start_time": "2018-02-25T23:20:21.119203Z" } }, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
RASISXRASISYRASISZLASISXLASISYLASISZRPSISXRPSISYRPSISZLPSISX...LAnkleZLHeelXLHeelYLHeelZLMT1XLMT1YLMT1ZLMT5XLMT5YLMT5Z
Time
0.0002419.06949.2881349.022413.35961.6551082.062230.66998.1311253.992227.30...1091.202281.75151.2461147.082462.4064.53441127.752419.5266.68521062.12
0.0072417.79947.7841349.552413.24960.3751081.542229.80997.3351253.152226.67...1090.612299.44140.8371146.932483.6662.56061126.092440.2663.18071060.86
0.0132416.51946.1741350.062413.19959.1791081.022229.02996.4481252.322226.06...1089.892317.23130.6181146.532505.0260.91741124.332460.9760.02451058.92
0.0202415.18944.4351350.532413.17957.7981080.532228.22995.5621251.442225.53...1089.182335.72120.5291145.942526.5459.75171122.402482.4057.40571057.61
0.0272414.32942.7171351.652413.07956.2491079.872227.37994.9801249.852225.08...1088.232354.61110.9701145.112547.9958.97031120.412503.6955.21941055.80
\n", "

5 rows × 66 columns

\n", "
" ], "text/plain": [ " RASISX RASISY RASISZ LASISX LASISY LASISZ RPSISX RPSISY \\\n", "Time \n", "0.000 2419.06 949.288 1349.02 2413.35 961.655 1082.06 2230.66 998.131 \n", "0.007 2417.79 947.784 1349.55 2413.24 960.375 1081.54 2229.80 997.335 \n", "0.013 2416.51 946.174 1350.06 2413.19 959.179 1081.02 2229.02 996.448 \n", "0.020 2415.18 944.435 1350.53 2413.17 957.798 1080.53 2228.22 995.562 \n", "0.027 2414.32 942.717 1351.65 2413.07 956.249 1079.87 2227.37 994.980 \n", "\n", " RPSISZ LPSISX ... LAnkleZ LHeelX LHeelY LHeelZ LMT1X \\\n", "Time ... \n", "0.000 1253.99 2227.30 ... 1091.20 2281.75 151.246 1147.08 2462.40 \n", "0.007 1253.15 2226.67 ... 1090.61 2299.44 140.837 1146.93 2483.66 \n", "0.013 1252.32 2226.06 ... 1089.89 2317.23 130.618 1146.53 2505.02 \n", "0.020 1251.44 2225.53 ... 1089.18 2335.72 120.529 1145.94 2526.54 \n", "0.027 1249.85 2225.08 ... 1088.23 2354.61 110.970 1145.11 2547.99 \n", "\n", " LMT1Y LMT1Z LMT5X LMT5Y LMT5Z \n", "Time \n", "0.000 64.5344 1127.75 2419.52 66.6852 1062.12 \n", "0.007 62.5606 1126.09 2440.26 63.1807 1060.86 \n", "0.013 60.9174 1124.33 2460.97 60.0245 1058.92 \n", "0.020 59.7517 1122.40 2482.40 57.4057 1057.61 \n", "0.027 58.9703 1120.41 2503.69 55.2194 1055.80 \n", "\n", "[5 rows x 66 columns]" ] }, "execution_count": 3, "metadata": {}, "output_type": "execute_result" } ], "source": [ "df = pd.read_csv(fname, sep='\\t', header=0, index_col=0, dtype=np.float64, engine='c')\n", "df.columns = df.columns.str.replace('\\.', '')\n", "df.head()" ] }, { "cell_type": "code", "execution_count": 4, "metadata": { "ExecuteTime": { "end_time": "2018-02-25T23:20:22.479564Z", "start_time": "2018-02-25T23:20:22.332701Z" } }, "outputs": [ { "data": { "application/javascript": [ "/* Put everything inside the global mpl namespace */\n", "window.mpl = {};\n", "\n", "\n", "mpl.get_websocket_type = function() {\n", " if (typeof(WebSocket) !== 'undefined') {\n", " return WebSocket;\n", " } else if (typeof(MozWebSocket) !== 'undefined') {\n", " return MozWebSocket;\n", " } else {\n", " alert('Your browser does not have WebSocket support.' +\n", " 'Please try Chrome, Safari or Firefox ≥ 6. ' +\n", " 'Firefox 4 and 5 are also supported but you ' +\n", " 'have to enable WebSockets in about:config.');\n", " };\n", "}\n", "\n", "mpl.figure = function(figure_id, websocket, ondownload, parent_element) {\n", " this.id = figure_id;\n", "\n", " this.ws = websocket;\n", "\n", " this.supports_binary = (this.ws.binaryType != undefined);\n", "\n", " if (!this.supports_binary) {\n", " var warnings = document.getElementById(\"mpl-warnings\");\n", " if (warnings) {\n", " warnings.style.display = 'block';\n", " warnings.textContent = (\n", " \"This browser does not support binary websocket messages. \" +\n", " \"Performance may be slow.\");\n", " }\n", " }\n", "\n", " this.imageObj = new Image();\n", "\n", " this.context = undefined;\n", " this.message = undefined;\n", " this.canvas = undefined;\n", " this.rubberband_canvas = undefined;\n", " this.rubberband_context = undefined;\n", " this.format_dropdown = undefined;\n", "\n", " this.image_mode = 'full';\n", "\n", " this.root = $('
');\n", " this._root_extra_style(this.root)\n", " this.root.attr('style', 'display: inline-block');\n", "\n", " $(parent_element).append(this.root);\n", "\n", " this._init_header(this);\n", " this._init_canvas(this);\n", " this._init_toolbar(this);\n", "\n", " var fig = this;\n", "\n", " this.waiting = false;\n", "\n", " this.ws.onopen = function () {\n", " fig.send_message(\"supports_binary\", {value: fig.supports_binary});\n", " fig.send_message(\"send_image_mode\", {});\n", " if (mpl.ratio != 1) {\n", " fig.send_message(\"set_dpi_ratio\", {'dpi_ratio': mpl.ratio});\n", " }\n", " fig.send_message(\"refresh\", {});\n", " }\n", "\n", " this.imageObj.onload = function() {\n", " if (fig.image_mode == 'full') {\n", " // Full images could contain transparency (where diff images\n", " // almost always do), so we need to clear the canvas so that\n", " // there is no ghosting.\n", " fig.context.clearRect(0, 0, fig.canvas.width, fig.canvas.height);\n", " }\n", " fig.context.drawImage(fig.imageObj, 0, 0);\n", " };\n", "\n", " this.imageObj.onunload = function() {\n", " fig.ws.close();\n", " }\n", "\n", " this.ws.onmessage = this._make_on_message_function(this);\n", "\n", " this.ondownload = ondownload;\n", "}\n", "\n", "mpl.figure.prototype._init_header = function() {\n", " var titlebar = $(\n", " '
');\n", " var titletext = $(\n", " '
');\n", " titlebar.append(titletext)\n", " this.root.append(titlebar);\n", " this.header = titletext[0];\n", "}\n", "\n", "\n", "\n", "mpl.figure.prototype._canvas_extra_style = function(canvas_div) {\n", "\n", "}\n", "\n", "\n", "mpl.figure.prototype._root_extra_style = function(canvas_div) {\n", "\n", "}\n", "\n", "mpl.figure.prototype._init_canvas = function() {\n", " var fig = this;\n", "\n", " var canvas_div = $('
');\n", "\n", " canvas_div.attr('style', 'position: relative; clear: both; outline: 0');\n", "\n", " function canvas_keyboard_event(event) {\n", " return fig.key_event(event, event['data']);\n", " }\n", "\n", " canvas_div.keydown('key_press', canvas_keyboard_event);\n", " canvas_div.keyup('key_release', canvas_keyboard_event);\n", " this.canvas_div = canvas_div\n", " this._canvas_extra_style(canvas_div)\n", " this.root.append(canvas_div);\n", "\n", " var canvas = $('');\n", " canvas.addClass('mpl-canvas');\n", " canvas.attr('style', \"left: 0; top: 0; z-index: 0; outline: 0\")\n", "\n", " this.canvas = canvas[0];\n", " this.context = canvas[0].getContext(\"2d\");\n", "\n", " var backingStore = this.context.backingStorePixelRatio ||\n", "\tthis.context.webkitBackingStorePixelRatio ||\n", "\tthis.context.mozBackingStorePixelRatio ||\n", "\tthis.context.msBackingStorePixelRatio ||\n", "\tthis.context.oBackingStorePixelRatio ||\n", "\tthis.context.backingStorePixelRatio || 1;\n", "\n", " mpl.ratio = (window.devicePixelRatio || 1) / backingStore;\n", "\n", " var rubberband = $('');\n", " rubberband.attr('style', \"position: absolute; left: 0; top: 0; z-index: 1;\")\n", "\n", " var pass_mouse_events = true;\n", "\n", " canvas_div.resizable({\n", " start: function(event, ui) {\n", " pass_mouse_events = false;\n", " },\n", " resize: function(event, ui) {\n", " fig.request_resize(ui.size.width, ui.size.height);\n", " },\n", " stop: function(event, ui) {\n", " pass_mouse_events = true;\n", " fig.request_resize(ui.size.width, ui.size.height);\n", " },\n", " });\n", "\n", " function mouse_event_fn(event) {\n", " if (pass_mouse_events)\n", " return fig.mouse_event(event, event['data']);\n", " }\n", "\n", " rubberband.mousedown('button_press', mouse_event_fn);\n", " rubberband.mouseup('button_release', mouse_event_fn);\n", " // Throttle sequential mouse events to 1 every 20ms.\n", " rubberband.mousemove('motion_notify', mouse_event_fn);\n", "\n", " rubberband.mouseenter('figure_enter', mouse_event_fn);\n", " rubberband.mouseleave('figure_leave', mouse_event_fn);\n", "\n", " canvas_div.on(\"wheel\", function (event) {\n", " event = event.originalEvent;\n", " event['data'] = 'scroll'\n", " if (event.deltaY < 0) {\n", " event.step = 1;\n", " } else {\n", " event.step = -1;\n", " }\n", " mouse_event_fn(event);\n", " });\n", "\n", " canvas_div.append(canvas);\n", " canvas_div.append(rubberband);\n", "\n", " this.rubberband = rubberband;\n", " this.rubberband_canvas = rubberband[0];\n", " this.rubberband_context = rubberband[0].getContext(\"2d\");\n", " this.rubberband_context.strokeStyle = \"#000000\";\n", "\n", " this._resize_canvas = function(width, height) {\n", " // Keep the size of the canvas, canvas container, and rubber band\n", " // canvas in synch.\n", " canvas_div.css('width', width)\n", " canvas_div.css('height', height)\n", "\n", " canvas.attr('width', width * mpl.ratio);\n", " canvas.attr('height', height * mpl.ratio);\n", " canvas.attr('style', 'width: ' + width + 'px; height: ' + height + 'px;');\n", "\n", " rubberband.attr('width', width);\n", " rubberband.attr('height', height);\n", " }\n", "\n", " // Set the figure to an initial 600x600px, this will subsequently be updated\n", " // upon first draw.\n", " this._resize_canvas(600, 600);\n", "\n", " // Disable right mouse context menu.\n", " $(this.rubberband_canvas).bind(\"contextmenu\",function(e){\n", " return false;\n", " });\n", "\n", " function set_focus () {\n", " canvas.focus();\n", " canvas_div.focus();\n", " }\n", "\n", " window.setTimeout(set_focus, 100);\n", "}\n", "\n", "mpl.figure.prototype._init_toolbar = function() {\n", " var fig = this;\n", "\n", " var nav_element = $('
')\n", " nav_element.attr('style', 'width: 100%');\n", " this.root.append(nav_element);\n", "\n", " // Define a callback function for later on.\n", " function toolbar_event(event) {\n", " return fig.toolbar_button_onclick(event['data']);\n", " }\n", " function toolbar_mouse_event(event) {\n", " return fig.toolbar_button_onmouseover(event['data']);\n", " }\n", "\n", " for(var toolbar_ind in mpl.toolbar_items) {\n", " var name = mpl.toolbar_items[toolbar_ind][0];\n", " var tooltip = mpl.toolbar_items[toolbar_ind][1];\n", " var image = mpl.toolbar_items[toolbar_ind][2];\n", " var method_name = mpl.toolbar_items[toolbar_ind][3];\n", "\n", " if (!name) {\n", " // put a spacer in here.\n", " continue;\n", " }\n", " var button = $('');\n", " button.click(method_name, toolbar_event);\n", " button.mouseover(tooltip, toolbar_mouse_event);\n", " nav_element.append(button);\n", " }\n", "\n", " // Add the status bar.\n", " var status_bar = $('');\n", " nav_element.append(status_bar);\n", " this.message = status_bar[0];\n", "\n", " // Add the close button to the window.\n", " var buttongrp = $('
');\n", " var button = $('');\n", " button.click(function (evt) { fig.handle_close(fig, {}); } );\n", " button.mouseover('Stop Interaction', toolbar_mouse_event);\n", " buttongrp.append(button);\n", " var titlebar = this.root.find($('.ui-dialog-titlebar'));\n", " titlebar.prepend(buttongrp);\n", "}\n", "\n", "mpl.figure.prototype._root_extra_style = function(el){\n", " var fig = this\n", " el.on(\"remove\", function(){\n", "\tfig.close_ws(fig, {});\n", " });\n", "}\n", "\n", "mpl.figure.prototype._canvas_extra_style = function(el){\n", " // this is important to make the div 'focusable\n", " el.attr('tabindex', 0)\n", " // reach out to IPython and tell the keyboard manager to turn it's self\n", " // off when our div gets focus\n", "\n", " // location in version 3\n", " if (IPython.notebook.keyboard_manager) {\n", " IPython.notebook.keyboard_manager.register_events(el);\n", " }\n", " else {\n", " // location in version 2\n", " IPython.keyboard_manager.register_events(el);\n", " }\n", "\n", "}\n", "\n", "mpl.figure.prototype._key_event_extra = function(event, name) {\n", " var manager = IPython.notebook.keyboard_manager;\n", " if (!manager)\n", " manager = IPython.keyboard_manager;\n", "\n", " // Check for shift+enter\n", " if (event.shiftKey && event.which == 13) {\n", " this.canvas_div.blur();\n", " event.shiftKey = false;\n", " // Send a \"J\" for go to next cell\n", " event.which = 74;\n", " event.keyCode = 74;\n", " manager.command_mode();\n", " manager.handle_keydown(event);\n", " }\n", "}\n", "\n", "mpl.figure.prototype.handle_save = function(fig, msg) {\n", " fig.ondownload(fig, null);\n", "}\n", "\n", "\n", "mpl.find_output_cell = function(html_output) {\n", " // Return the cell and output element which can be found *uniquely* in the notebook.\n", " // Note - this is a bit hacky, but it is done because the \"notebook_saving.Notebook\"\n", " // IPython event is triggered only after the cells have been serialised, which for\n", " // our purposes (turning an active figure into a static one), is too late.\n", " var cells = IPython.notebook.get_cells();\n", " var ncells = cells.length;\n", " for (var i=0; i= 3 moved mimebundle to data attribute of output\n", " data = data.data;\n", " }\n", " if (data['text/html'] == html_output) {\n", " return [cell, data, j];\n", " }\n", " }\n", " }\n", " }\n", "}\n", "\n", "// Register the function which deals with the matplotlib target/channel.\n", "// The kernel may be null if the page has been refreshed.\n", "if (IPython.notebook.kernel != null) {\n", " IPython.notebook.kernel.comm_manager.register_target('matplotlib', mpl.mpl_figure_comm);\n", "}\n" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "plot_widget(df)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## pandas multiindex\n", "\n", "Data with hierarchical column index ([multiindex](http://pandas.pydata.org/pandas-docs/stable/advanced.html#creating-a-multiindex-hierarchical-index-object)) where columns have multiple levels." ] }, { "cell_type": "code", "execution_count": 7, "metadata": { "ExecuteTime": { "end_time": "2018-02-25T23:20:25.550888Z", "start_time": "2018-02-25T23:20:25.476335Z" } }, "outputs": [], "source": [ "df = pd.read_csv(fname, sep='\\t', header=0, index_col=0, dtype=np.float64, engine='c')\n", "# format columns as multindexes and relabel them\n", "cols = [s[:-1] for s in df.columns.str.replace('\\.', '')]\n", "df.columns = [cols, list('XYZ')*int(df.shape[1]/3)]\n", "df.columns.set_names(names=['Marker', 'Coordinate'], level=[0, 1], inplace=True)\n", "#df = df.swaplevel(0, 1, axis=1) # for 'Coordinate' to go first" ] }, { "cell_type": "code", "execution_count": 8, "metadata": { "ExecuteTime": { "end_time": "2018-02-25T23:20:26.264183Z", "start_time": "2018-02-25T23:20:26.239165Z" } }, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
MarkerRASISLASISRPSISLPSIS...LAnkleLHeelLMT1LMT5
CoordinateXYZXYZXYZX...ZXYZXYZXYZ
Time
0.0002419.06949.2881349.022413.35961.6551082.062230.66998.1311253.992227.30...1091.202281.75151.2461147.082462.4064.53441127.752419.5266.68521062.12
0.0072417.79947.7841349.552413.24960.3751081.542229.80997.3351253.152226.67...1090.612299.44140.8371146.932483.6662.56061126.092440.2663.18071060.86
0.0132416.51946.1741350.062413.19959.1791081.022229.02996.4481252.322226.06...1089.892317.23130.6181146.532505.0260.91741124.332460.9760.02451058.92
0.0202415.18944.4351350.532413.17957.7981080.532228.22995.5621251.442225.53...1089.182335.72120.5291145.942526.5459.75171122.402482.4057.40571057.61
0.0272414.32942.7171351.652413.07956.2491079.872227.37994.9801249.852225.08...1088.232354.61110.9701145.112547.9958.97031120.412503.6955.21941055.80
\n", "

5 rows × 66 columns

\n", "
" ], "text/plain": [ "Marker RASIS LASIS RPSIS \\\n", "Coordinate X Y Z X Y Z X \n", "Time \n", "0.000 2419.06 949.288 1349.02 2413.35 961.655 1082.06 2230.66 \n", "0.007 2417.79 947.784 1349.55 2413.24 960.375 1081.54 2229.80 \n", "0.013 2416.51 946.174 1350.06 2413.19 959.179 1081.02 2229.02 \n", "0.020 2415.18 944.435 1350.53 2413.17 957.798 1080.53 2228.22 \n", "0.027 2414.32 942.717 1351.65 2413.07 956.249 1079.87 2227.37 \n", "\n", "Marker LPSIS ... LAnkle LHeel \\\n", "Coordinate Y Z X ... Z X Y \n", "Time ... \n", "0.000 998.131 1253.99 2227.30 ... 1091.20 2281.75 151.246 \n", "0.007 997.335 1253.15 2226.67 ... 1090.61 2299.44 140.837 \n", "0.013 996.448 1252.32 2226.06 ... 1089.89 2317.23 130.618 \n", "0.020 995.562 1251.44 2225.53 ... 1089.18 2335.72 120.529 \n", "0.027 994.980 1249.85 2225.08 ... 1088.23 2354.61 110.970 \n", "\n", "Marker LMT1 LMT5 \n", "Coordinate Z X Y Z X Y Z \n", "Time \n", "0.000 1147.08 2462.40 64.5344 1127.75 2419.52 66.6852 1062.12 \n", "0.007 1146.93 2483.66 62.5606 1126.09 2440.26 63.1807 1060.86 \n", "0.013 1146.53 2505.02 60.9174 1124.33 2460.97 60.0245 1058.92 \n", "0.020 1145.94 2526.54 59.7517 1122.40 2482.40 57.4057 1057.61 \n", "0.027 1145.11 2547.99 58.9703 1120.41 2503.69 55.2194 1055.80 \n", "\n", "[5 rows x 66 columns]" ] }, "execution_count": 8, "metadata": {}, "output_type": "execute_result" } ], "source": [ "df.head()" ] }, { "cell_type": "code", "execution_count": 9, "metadata": { "ExecuteTime": { "end_time": "2018-02-25T23:20:27.143499Z", "start_time": "2018-02-25T23:20:27.133992Z" } }, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
CoordinateXYZ
Time
0.0002419.06949.2881349.02
0.0072417.79947.7841349.55
0.0132416.51946.1741350.06
0.0202415.18944.4351350.53
0.0272414.32942.7171351.65
\n", "
" ], "text/plain": [ "Coordinate X Y Z\n", "Time \n", "0.000 2419.06 949.288 1349.02\n", "0.007 2417.79 947.784 1349.55\n", "0.013 2416.51 946.174 1350.06\n", "0.020 2415.18 944.435 1350.53\n", "0.027 2414.32 942.717 1351.65" ] }, "execution_count": 9, "metadata": {}, "output_type": "execute_result" } ], "source": [ "df['RASIS'].head()\n", "# df.RASIS.head()" ] }, { "cell_type": "code", "execution_count": 10, "metadata": { "ExecuteTime": { "end_time": "2018-02-25T23:20:32.282050Z", "start_time": "2018-02-25T23:20:32.276562Z" } }, "outputs": [ { "data": { "text/plain": [ "Time\n", "0.000 2419.06\n", "0.007 2417.79\n", "0.013 2416.51\n", "0.020 2415.18\n", "0.027 2414.32\n", "Name: X, dtype: float64" ] }, "execution_count": 10, "metadata": {}, "output_type": "execute_result" } ], "source": [ "df.RASIS.X.head()\n", "# df['RASIS']['X'].head()" ] }, { "cell_type": "code", "execution_count": 12, "metadata": { "ExecuteTime": { "end_time": "2018-02-26T00:17:59.985884Z", "start_time": "2018-02-26T00:17:59.961868Z" } }, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
MarkerRASISLASISRPSISLPSISLIliacCrestRIliacCrestRGTRRKneeRHFRTT...RMT1RMT5LGTRLKneeLHFLTTLAnkleLHeelLMT1LMT5
Time
0.0002419.062413.352230.662227.302330.162352.052308.832289.092266.172323.79...2363.952319.022342.702507.212482.492544.882334.252281.752462.402419.52
0.0072417.792413.242229.802226.672329.082350.012306.842282.282259.052317.03...2354.672309.532343.632509.942485.802549.452351.292299.442483.662440.26
0.0132416.512413.192229.022226.062327.982347.962304.892275.642251.492309.97...2345.342300.092343.942512.042489.292553.492368.832317.232505.022460.97
0.0202415.182413.172228.222225.532327.192345.792303.022269.242244.682302.86...2335.902290.632344.082513.752492.542557.222386.562335.722526.542482.40
0.0272414.322413.072227.372225.082327.502343.832301.132263.202237.902295.31...2326.702281.252344.292514.842495.312560.202404.932354.612547.992503.69
\n", "

5 rows × 22 columns

\n", "
" ], "text/plain": [ "Marker RASIS LASIS RPSIS LPSIS LIliacCrest RIliacCrest RGTR \\\n", "Time \n", "0.000 2419.06 2413.35 2230.66 2227.30 2330.16 2352.05 2308.83 \n", "0.007 2417.79 2413.24 2229.80 2226.67 2329.08 2350.01 2306.84 \n", "0.013 2416.51 2413.19 2229.02 2226.06 2327.98 2347.96 2304.89 \n", "0.020 2415.18 2413.17 2228.22 2225.53 2327.19 2345.79 2303.02 \n", "0.027 2414.32 2413.07 2227.37 2225.08 2327.50 2343.83 2301.13 \n", "\n", "Marker RKnee RHF RTT ... RMT1 RMT5 LGTR \\\n", "Time ... \n", "0.000 2289.09 2266.17 2323.79 ... 2363.95 2319.02 2342.70 \n", "0.007 2282.28 2259.05 2317.03 ... 2354.67 2309.53 2343.63 \n", "0.013 2275.64 2251.49 2309.97 ... 2345.34 2300.09 2343.94 \n", "0.020 2269.24 2244.68 2302.86 ... 2335.90 2290.63 2344.08 \n", "0.027 2263.20 2237.90 2295.31 ... 2326.70 2281.25 2344.29 \n", "\n", "Marker LKnee LHF LTT LAnkle LHeel LMT1 LMT5 \n", "Time \n", "0.000 2507.21 2482.49 2544.88 2334.25 2281.75 2462.40 2419.52 \n", "0.007 2509.94 2485.80 2549.45 2351.29 2299.44 2483.66 2440.26 \n", "0.013 2512.04 2489.29 2553.49 2368.83 2317.23 2505.02 2460.97 \n", "0.020 2513.75 2492.54 2557.22 2386.56 2335.72 2526.54 2482.40 \n", "0.027 2514.84 2495.31 2560.20 2404.93 2354.61 2547.99 2503.69 \n", "\n", "[5 rows x 22 columns]" ] }, "execution_count": 12, "metadata": {}, "output_type": "execute_result" } ], "source": [ "df.xs('X', level='Coordinate', axis=1).head()" ] }, { "cell_type": "code", "execution_count": 13, "metadata": { "ExecuteTime": { "end_time": "2018-02-26T00:18:34.351464Z", "start_time": "2018-02-26T00:18:34.322944Z" } }, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
MarkerRASISLASISRPSISLPSISLIliacCrestRIliacCrestRGTRRKneeRHFRTT...RMT1RMT5LGTRLKneeLHFLTTLAnkleLHeelLMT1LMT5
CoordinateXXXXXXXXXX...XXXXXXXXXX
Time
0.0002419.062413.352230.662227.302330.162352.052308.832289.092266.172323.79...2363.952319.022342.702507.212482.492544.882334.252281.752462.402419.52
0.0072417.792413.242229.802226.672329.082350.012306.842282.282259.052317.03...2354.672309.532343.632509.942485.802549.452351.292299.442483.662440.26
0.0132416.512413.192229.022226.062327.982347.962304.892275.642251.492309.97...2345.342300.092343.942512.042489.292553.492368.832317.232505.022460.97
0.0202415.182413.172228.222225.532327.192345.792303.022269.242244.682302.86...2335.902290.632344.082513.752492.542557.222386.562335.722526.542482.40
0.0272414.322413.072227.372225.082327.502343.832301.132263.202237.902295.31...2326.702281.252344.292514.842495.312560.202404.932354.612547.992503.69
\n", "

5 rows × 22 columns

\n", "
" ], "text/plain": [ "Marker RASIS LASIS RPSIS LPSIS LIliacCrest RIliacCrest \\\n", "Coordinate X X X X X X \n", "Time \n", "0.000 2419.06 2413.35 2230.66 2227.30 2330.16 2352.05 \n", "0.007 2417.79 2413.24 2229.80 2226.67 2329.08 2350.01 \n", "0.013 2416.51 2413.19 2229.02 2226.06 2327.98 2347.96 \n", "0.020 2415.18 2413.17 2228.22 2225.53 2327.19 2345.79 \n", "0.027 2414.32 2413.07 2227.37 2225.08 2327.50 2343.83 \n", "\n", "Marker RGTR RKnee RHF RTT ... RMT1 RMT5 \\\n", "Coordinate X X X X ... X X \n", "Time ... \n", "0.000 2308.83 2289.09 2266.17 2323.79 ... 2363.95 2319.02 \n", "0.007 2306.84 2282.28 2259.05 2317.03 ... 2354.67 2309.53 \n", "0.013 2304.89 2275.64 2251.49 2309.97 ... 2345.34 2300.09 \n", "0.020 2303.02 2269.24 2244.68 2302.86 ... 2335.90 2290.63 \n", "0.027 2301.13 2263.20 2237.90 2295.31 ... 2326.70 2281.25 \n", "\n", "Marker LGTR LKnee LHF LTT LAnkle LHeel LMT1 \\\n", "Coordinate X X X X X X X \n", "Time \n", "0.000 2342.70 2507.21 2482.49 2544.88 2334.25 2281.75 2462.40 \n", "0.007 2343.63 2509.94 2485.80 2549.45 2351.29 2299.44 2483.66 \n", "0.013 2343.94 2512.04 2489.29 2553.49 2368.83 2317.23 2505.02 \n", "0.020 2344.08 2513.75 2492.54 2557.22 2386.56 2335.72 2526.54 \n", "0.027 2344.29 2514.84 2495.31 2560.20 2404.93 2354.61 2547.99 \n", "\n", "Marker LMT5 \n", "Coordinate X \n", "Time \n", "0.000 2419.52 \n", "0.007 2440.26 \n", "0.013 2460.97 \n", "0.020 2482.40 \n", "0.027 2503.69 \n", "\n", "[5 rows x 22 columns]" ] }, "execution_count": 13, "metadata": {}, "output_type": "execute_result" } ], "source": [ "df.loc[:, (slice(None), 'X')].head()" ] }, { "cell_type": "code", "execution_count": 14, "metadata": { "ExecuteTime": { "end_time": "2018-02-26T00:18:58.773455Z", "start_time": "2018-02-26T00:18:58.745940Z" } }, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
CoordinateXYZXYZXYZX...ZXYZXYZXYZ
MarkerRASISRASISRASISLASISLASISLASISRPSISRPSISRPSISLPSIS...LAnkleLHeelLHeelLHeelLMT1LMT1LMT1LMT5LMT5LMT5
Time
0.0002419.06949.2881349.022413.35961.6551082.062230.66998.1311253.992227.30...1091.202281.75151.2461147.082462.4064.53441127.752419.5266.68521062.12
0.0072417.79947.7841349.552413.24960.3751081.542229.80997.3351253.152226.67...1090.612299.44140.8371146.932483.6662.56061126.092440.2663.18071060.86
0.0132416.51946.1741350.062413.19959.1791081.022229.02996.4481252.322226.06...1089.892317.23130.6181146.532505.0260.91741124.332460.9760.02451058.92
0.0202415.18944.4351350.532413.17957.7981080.532228.22995.5621251.442225.53...1089.182335.72120.5291145.942526.5459.75171122.402482.4057.40571057.61
0.0272414.32942.7171351.652413.07956.2491079.872227.37994.9801249.852225.08...1088.232354.61110.9701145.112547.9958.97031120.412503.6955.21941055.80
\n", "

5 rows × 66 columns

\n", "
" ], "text/plain": [ "Coordinate X Y Z X Y Z X \\\n", "Marker RASIS RASIS RASIS LASIS LASIS LASIS RPSIS \n", "Time \n", "0.000 2419.06 949.288 1349.02 2413.35 961.655 1082.06 2230.66 \n", "0.007 2417.79 947.784 1349.55 2413.24 960.375 1081.54 2229.80 \n", "0.013 2416.51 946.174 1350.06 2413.19 959.179 1081.02 2229.02 \n", "0.020 2415.18 944.435 1350.53 2413.17 957.798 1080.53 2228.22 \n", "0.027 2414.32 942.717 1351.65 2413.07 956.249 1079.87 2227.37 \n", "\n", "Coordinate Y Z X ... Z X Y \\\n", "Marker RPSIS RPSIS LPSIS ... LAnkle LHeel LHeel \n", "Time ... \n", "0.000 998.131 1253.99 2227.30 ... 1091.20 2281.75 151.246 \n", "0.007 997.335 1253.15 2226.67 ... 1090.61 2299.44 140.837 \n", "0.013 996.448 1252.32 2226.06 ... 1089.89 2317.23 130.618 \n", "0.020 995.562 1251.44 2225.53 ... 1089.18 2335.72 120.529 \n", "0.027 994.980 1249.85 2225.08 ... 1088.23 2354.61 110.970 \n", "\n", "Coordinate Z X Y Z X Y Z \n", "Marker LHeel LMT1 LMT1 LMT1 LMT5 LMT5 LMT5 \n", "Time \n", "0.000 1147.08 2462.40 64.5344 1127.75 2419.52 66.6852 1062.12 \n", "0.007 1146.93 2483.66 62.5606 1126.09 2440.26 63.1807 1060.86 \n", "0.013 1146.53 2505.02 60.9174 1124.33 2460.97 60.0245 1058.92 \n", "0.020 1145.94 2526.54 59.7517 1122.40 2482.40 57.4057 1057.61 \n", "0.027 1145.11 2547.99 58.9703 1120.41 2503.69 55.2194 1055.80 \n", "\n", "[5 rows x 66 columns]" ] }, "execution_count": 14, "metadata": {}, "output_type": "execute_result" } ], "source": [ "df.swaplevel(0, 1, axis=1).head() # for 'Coordinate' to go first" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] }, { "cell_type": "code", "execution_count": 11, "metadata": { "ExecuteTime": { "end_time": "2018-02-25T23:20:40.027581Z", "start_time": "2018-02-25T23:20:39.932485Z" } }, "outputs": [ { "data": { "application/javascript": [ "/* Put everything inside the global mpl namespace */\n", "window.mpl = {};\n", "\n", "\n", "mpl.get_websocket_type = function() {\n", " if (typeof(WebSocket) !== 'undefined') {\n", " return WebSocket;\n", " } else if (typeof(MozWebSocket) !== 'undefined') {\n", " return MozWebSocket;\n", " } else {\n", " alert('Your browser does not have WebSocket support.' +\n", " 'Please try Chrome, Safari or Firefox ≥ 6. ' +\n", " 'Firefox 4 and 5 are also supported but you ' +\n", " 'have to enable WebSockets in about:config.');\n", " };\n", "}\n", "\n", "mpl.figure = function(figure_id, websocket, ondownload, parent_element) {\n", " this.id = figure_id;\n", "\n", " this.ws = websocket;\n", "\n", " this.supports_binary = (this.ws.binaryType != undefined);\n", "\n", " if (!this.supports_binary) {\n", " var warnings = document.getElementById(\"mpl-warnings\");\n", " if (warnings) {\n", " warnings.style.display = 'block';\n", " warnings.textContent = (\n", " \"This browser does not support binary websocket messages. \" +\n", " \"Performance may be slow.\");\n", " }\n", " }\n", "\n", " this.imageObj = new Image();\n", "\n", " this.context = undefined;\n", " this.message = undefined;\n", " this.canvas = undefined;\n", " this.rubberband_canvas = undefined;\n", " this.rubberband_context = undefined;\n", " this.format_dropdown = undefined;\n", "\n", " this.image_mode = 'full';\n", "\n", " this.root = $('
');\n", " this._root_extra_style(this.root)\n", " this.root.attr('style', 'display: inline-block');\n", "\n", " $(parent_element).append(this.root);\n", "\n", " this._init_header(this);\n", " this._init_canvas(this);\n", " this._init_toolbar(this);\n", "\n", " var fig = this;\n", "\n", " this.waiting = false;\n", "\n", " this.ws.onopen = function () {\n", " fig.send_message(\"supports_binary\", {value: fig.supports_binary});\n", " fig.send_message(\"send_image_mode\", {});\n", " if (mpl.ratio != 1) {\n", " fig.send_message(\"set_dpi_ratio\", {'dpi_ratio': mpl.ratio});\n", " }\n", " fig.send_message(\"refresh\", {});\n", " }\n", "\n", " this.imageObj.onload = function() {\n", " if (fig.image_mode == 'full') {\n", " // Full images could contain transparency (where diff images\n", " // almost always do), so we need to clear the canvas so that\n", " // there is no ghosting.\n", " fig.context.clearRect(0, 0, fig.canvas.width, fig.canvas.height);\n", " }\n", " fig.context.drawImage(fig.imageObj, 0, 0);\n", " };\n", "\n", " this.imageObj.onunload = function() {\n", " fig.ws.close();\n", " }\n", "\n", " this.ws.onmessage = this._make_on_message_function(this);\n", "\n", " this.ondownload = ondownload;\n", "}\n", "\n", "mpl.figure.prototype._init_header = function() {\n", " var titlebar = $(\n", " '
');\n", " var titletext = $(\n", " '
');\n", " titlebar.append(titletext)\n", " this.root.append(titlebar);\n", " this.header = titletext[0];\n", "}\n", "\n", "\n", "\n", "mpl.figure.prototype._canvas_extra_style = function(canvas_div) {\n", "\n", "}\n", "\n", "\n", "mpl.figure.prototype._root_extra_style = function(canvas_div) {\n", "\n", "}\n", "\n", "mpl.figure.prototype._init_canvas = function() {\n", " var fig = this;\n", "\n", " var canvas_div = $('
');\n", "\n", " canvas_div.attr('style', 'position: relative; clear: both; outline: 0');\n", "\n", " function canvas_keyboard_event(event) {\n", " return fig.key_event(event, event['data']);\n", " }\n", "\n", " canvas_div.keydown('key_press', canvas_keyboard_event);\n", " canvas_div.keyup('key_release', canvas_keyboard_event);\n", " this.canvas_div = canvas_div\n", " this._canvas_extra_style(canvas_div)\n", " this.root.append(canvas_div);\n", "\n", " var canvas = $('');\n", " canvas.addClass('mpl-canvas');\n", " canvas.attr('style', \"left: 0; top: 0; z-index: 0; outline: 0\")\n", "\n", " this.canvas = canvas[0];\n", " this.context = canvas[0].getContext(\"2d\");\n", "\n", " var backingStore = this.context.backingStorePixelRatio ||\n", "\tthis.context.webkitBackingStorePixelRatio ||\n", "\tthis.context.mozBackingStorePixelRatio ||\n", "\tthis.context.msBackingStorePixelRatio ||\n", "\tthis.context.oBackingStorePixelRatio ||\n", "\tthis.context.backingStorePixelRatio || 1;\n", "\n", " mpl.ratio = (window.devicePixelRatio || 1) / backingStore;\n", "\n", " var rubberband = $('');\n", " rubberband.attr('style', \"position: absolute; left: 0; top: 0; z-index: 1;\")\n", "\n", " var pass_mouse_events = true;\n", "\n", " canvas_div.resizable({\n", " start: function(event, ui) {\n", " pass_mouse_events = false;\n", " },\n", " resize: function(event, ui) {\n", " fig.request_resize(ui.size.width, ui.size.height);\n", " },\n", " stop: function(event, ui) {\n", " pass_mouse_events = true;\n", " fig.request_resize(ui.size.width, ui.size.height);\n", " },\n", " });\n", "\n", " function mouse_event_fn(event) {\n", " if (pass_mouse_events)\n", " return fig.mouse_event(event, event['data']);\n", " }\n", "\n", " rubberband.mousedown('button_press', mouse_event_fn);\n", " rubberband.mouseup('button_release', mouse_event_fn);\n", " // Throttle sequential mouse events to 1 every 20ms.\n", " rubberband.mousemove('motion_notify', mouse_event_fn);\n", "\n", " rubberband.mouseenter('figure_enter', mouse_event_fn);\n", " rubberband.mouseleave('figure_leave', mouse_event_fn);\n", "\n", " canvas_div.on(\"wheel\", function (event) {\n", " event = event.originalEvent;\n", " event['data'] = 'scroll'\n", " if (event.deltaY < 0) {\n", " event.step = 1;\n", " } else {\n", " event.step = -1;\n", " }\n", " mouse_event_fn(event);\n", " });\n", "\n", " canvas_div.append(canvas);\n", " canvas_div.append(rubberband);\n", "\n", " this.rubberband = rubberband;\n", " this.rubberband_canvas = rubberband[0];\n", " this.rubberband_context = rubberband[0].getContext(\"2d\");\n", " this.rubberband_context.strokeStyle = \"#000000\";\n", "\n", " this._resize_canvas = function(width, height) {\n", " // Keep the size of the canvas, canvas container, and rubber band\n", " // canvas in synch.\n", " canvas_div.css('width', width)\n", " canvas_div.css('height', height)\n", "\n", " canvas.attr('width', width * mpl.ratio);\n", " canvas.attr('height', height * mpl.ratio);\n", " canvas.attr('style', 'width: ' + width + 'px; height: ' + height + 'px;');\n", "\n", " rubberband.attr('width', width);\n", " rubberband.attr('height', height);\n", " }\n", "\n", " // Set the figure to an initial 600x600px, this will subsequently be updated\n", " // upon first draw.\n", " this._resize_canvas(600, 600);\n", "\n", " // Disable right mouse context menu.\n", " $(this.rubberband_canvas).bind(\"contextmenu\",function(e){\n", " return false;\n", " });\n", "\n", " function set_focus () {\n", " canvas.focus();\n", " canvas_div.focus();\n", " }\n", "\n", " window.setTimeout(set_focus, 100);\n", "}\n", "\n", "mpl.figure.prototype._init_toolbar = function() {\n", " var fig = this;\n", "\n", " var nav_element = $('
')\n", " nav_element.attr('style', 'width: 100%');\n", " this.root.append(nav_element);\n", "\n", " // Define a callback function for later on.\n", " function toolbar_event(event) {\n", " return fig.toolbar_button_onclick(event['data']);\n", " }\n", " function toolbar_mouse_event(event) {\n", " return fig.toolbar_button_onmouseover(event['data']);\n", " }\n", "\n", " for(var toolbar_ind in mpl.toolbar_items) {\n", " var name = mpl.toolbar_items[toolbar_ind][0];\n", " var tooltip = mpl.toolbar_items[toolbar_ind][1];\n", " var image = mpl.toolbar_items[toolbar_ind][2];\n", " var method_name = mpl.toolbar_items[toolbar_ind][3];\n", "\n", " if (!name) {\n", " // put a spacer in here.\n", " continue;\n", " }\n", " var button = $('