From 79065c6cc4afe73b3bad9e242cca61b100a69f9f Mon Sep 17 00:00:00 2001 From: "Ricardo M. Ferraz Leal" Date: Fri, 6 Apr 2018 16:48:23 -0400 Subject: [PATCH] Deleted extra NB --- ...on to File Manipulation and Plotting.ipynb | 12063 ---------------- 1 file changed, 12063 deletions(-) delete mode 100644 notebooks/2 - Introduction to File Manipulation and Plotting.ipynb diff --git a/notebooks/2 - Introduction to File Manipulation and Plotting.ipynb b/notebooks/2 - Introduction to File Manipulation and Plotting.ipynb deleted file mode 100644 index 6e01003..0000000 --- a/notebooks/2 - Introduction to File Manipulation and Plotting.ipynb +++ /dev/null @@ -1,12063 +0,0 @@ -{ - "cells": [ - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "# Introduction to File Manipulation and Plotting\n", - "\n", - "- Operating system interaction: `os`\n", - "- File manipulation: `os.path`\n", - "- Arrays, record arrays and basic statistics: `numpy`\n", - "- Simple and Advanced Plotting: `matplotlib`\n" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "## Shell commands" - ] - }, - { - "cell_type": "code", - "execution_count": 1, - "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "/SNS/users/rhf/git/IPythonNotebookTutorial\r\n" - ] - } - ], - "source": [ - "# to call shell from a Notebook is to prepend an exclamation point to a shell command\n", - "# This is not python standard! Just Jupyter notebooks!\n", - "!pwd" - ] - }, - { - "cell_type": "code", - "execution_count": 2, - "metadata": {}, - "outputs": [], - "source": [ - "# For this tutorial we want to run it in: /EXAMPLES/IPythonNotebookTutorial\n", - "!cd /EXAMPLES/IPythonNotebookTutorial" - ] - }, - { - "cell_type": "code", - "execution_count": 3, - "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "/SNS/users/rhf/git/IPythonNotebookTutorial\r\n" - ] - } - ], - "source": [ - "!pwd" - ] - }, - { - "cell_type": "code", - "execution_count": 4, - "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "0.0 - introduction.ipynb\r\n", - "1.0 - jupyter dashboard.ipynb\r\n", - "1.1 - jupyter not a book.ipynb\r\n", - "1.2 - markdown syntax.ipynb\r\n", - "1.3 - introduction to python (CLASS).ipynb\r\n", - "1.3 - introduction to python (FULL).ipynb\r\n", - "2 - Introduction to File Manipulation and Plotting.ipynb\r\n", - "3 - Multiple plots - Glob - advanced.ipynb\r\n", - "3 - Multiple plots - Glob.ipynb\r\n", - "4 - 2D Imaging - FITS.ipynb\r\n", - "4 - 2D Imaging - TIFF (CLASS).ipynb\r\n", - "4 - 2D Imaging - TIFF (FULL).ipynb\r\n", - "5 - Gaussian Fitting.ipynb\r\n", - "6 - HDF files.ipynb\r\n", - "7 - widgets.ipynb\r\n", - "Data\r\n", - "README.md\r\n", - "environment.yml\r\n", - "hdfview.png\r\n" - ] - } - ], - "source": [ - "!ls" - ] - }, - { - "cell_type": "code", - "execution_count": 5, - "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "a1.dat\ta3.dat\tb2.dat\tb4.dat\tf2.txt\tf4.txt\tf6.txt\tf8.txt\tsubdir1\r\n", - "a2.dat\tb1.dat\tb3.dat\tf1.txt\tf3.txt\tf5.txt\tf7.txt\tf9.txt\tsubdir2\r\n" - ] - } - ], - "source": [ - "# Data files\n", - "!ls Data/Glob" - ] - }, - { - "cell_type": "code", - "execution_count": 13, - "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "['total 231', '-rw-r--r-- 1 rhf users 7375 Apr 2 15:29 f1.txt', '-rw-r--r-- 1 rhf users 7164 Apr 2 15:29 f2.txt', '-rw-r--r-- 1 rhf users 7014 Apr 2 15:29 f3.txt', '-rw-r--r-- 1 rhf users 6853 Apr 2 15:29 f4.txt', '-rw-r--r-- 1 rhf users 6743 Apr 2 15:29 f5.txt', '-rw-r--r-- 1 rhf users 6599 Apr 2 15:29 f6.txt', '-rw-r--r-- 1 rhf users 6503 Apr 2 15:29 f7.txt', '-rw-r--r-- 1 rhf users 6402 Apr 2 15:29 f8.txt', '-rw-r--r-- 1 rhf users 6323 Apr 2 15:29 f9.txt', '-rw-r--r-- 1 rhf users 0 Apr 5 14:12 a1.dat', '-rw-r--r-- 1 rhf users 0 Apr 5 14:12 a2.dat', '-rw-r--r-- 1 rhf users 0 Apr 5 14:12 a3.dat', '-rw-r--r-- 1 rhf users 0 Apr 5 14:12 b1.dat', '-rw-r--r-- 1 rhf users 0 Apr 5 14:12 b2.dat', '-rw-r--r-- 1 rhf users 0 Apr 5 14:12 b3.dat', '-rw-r--r-- 1 rhf users 0 Apr 5 14:12 b4.dat', 'drwxr-xr-x 2 rhf users 5 Apr 5 14:12 subdir1', 'drwxr-xr-x 4 rhf users 20 Apr 5 14:12 .', 'drwxr-xr-x 2 rhf users 5 Apr 5 14:12 subdir2', 'drwxr-xr-x 7 rhf users 7 Apr 5 14:12 ..']\n" - ] - } - ], - "source": [ - "# Something interesting: Mixing shell commands with python\n", - "shell_out = !ls -lart Data/Glob\n", - "# Every line in the output is a list element\n", - "print(shell_out)" - ] - }, - { - "cell_type": "code", - "execution_count": 15, - "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "['total 231',\n", - " '-rw-r--r-- 1 rhf users 7375 Apr 2 15:29 f1.txt',\n", - " '-rw-r--r-- 1 rhf users 7164 Apr 2 15:29 f2.txt',\n", - " '-rw-r--r-- 1 rhf users 7014 Apr 2 15:29 f3.txt',\n", - " '-rw-r--r-- 1 rhf users 6853 Apr 2 15:29 f4.txt',\n", - " '-rw-r--r-- 1 rhf users 6743 Apr 2 15:29 f5.txt',\n", - " '-rw-r--r-- 1 rhf users 6599 Apr 2 15:29 f6.txt',\n", - " '-rw-r--r-- 1 rhf users 6503 Apr 2 15:29 f7.txt',\n", - " '-rw-r--r-- 1 rhf users 6402 Apr 2 15:29 f8.txt',\n", - " '-rw-r--r-- 1 rhf users 6323 Apr 2 15:29 f9.txt',\n", - " '-rw-r--r-- 1 rhf users 0 Apr 5 14:12 a1.dat',\n", - " '-rw-r--r-- 1 rhf users 0 Apr 5 14:12 a2.dat',\n", - " '-rw-r--r-- 1 rhf users 0 Apr 5 14:12 a3.dat',\n", - " '-rw-r--r-- 1 rhf users 0 Apr 5 14:12 b1.dat',\n", - " '-rw-r--r-- 1 rhf users 0 Apr 5 14:12 b2.dat',\n", - " '-rw-r--r-- 1 rhf users 0 Apr 5 14:12 b3.dat',\n", - " '-rw-r--r-- 1 rhf users 0 Apr 5 14:12 b4.dat',\n", - " 'drwxr-xr-x 2 rhf users 5 Apr 5 14:12 subdir1',\n", - " 'drwxr-xr-x 4 rhf users 20 Apr 5 14:12 .',\n", - " 'drwxr-xr-x 2 rhf users 5 Apr 5 14:12 subdir2',\n", - " 'drwxr-xr-x 7 rhf users 7 Apr 5 14:12 ..']\n" - ] - } - ], - "source": [ - "# Let's make a pretty print\n", - "# https://docs.python.org/3/library/pprint.html\n", - "from pprint import pprint\n", - "pprint(shell_out)" - ] - }, - { - "cell_type": "code", - "execution_count": 16, - "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "['Filesystem Size Used Avail Use% '\n", - " 'Mounted on',\n", - " '/dev/mapper/vg01-lv_root 36G 7.9G 28G 23% /',\n", - " 'devtmpfs 3.9G 0 3.9G 0% '\n", - " '/dev',\n", - " 'tmpfs 3.9G 0 3.9G 0% '\n", - " '/dev/shm',\n", - " 'tmpfs 3.9G 186M 3.8G 5% '\n", - " '/run',\n", - " 'tmpfs 3.9G 0 3.9G 0% '\n", - " '/sys/fs/cgroup',\n", - " '/dev/sda1 597M 182M 416M 31% '\n", - " '/boot',\n", - " '128.219.164.43:/volumes/datapool/sfw-rhel7-prod 100G 57G 44G 57% '\n", - " '/SNS/software',\n", - " '128.219.249.33@tcp:/snsfs 1.1P 853T 176T 83% '\n", - " '/SNS/lustre',\n", - " '128.219.164.43:/volumes/datapool/users/m2c 78T 36T 43T 46% '\n", - " '/SNS/users/m2c']\n" - ] - } - ], - "source": [ - "# Mixing shell commands with python cont.\n", - "shell_out = !df -h | head\n", - "pprint(shell_out)" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "## Python `OS` module" - ] - }, - { - "cell_type": "code", - "execution_count": 3, - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "'/SNS/users/rhf/git/IPythonNotebookTutorial'" - ] - }, - "execution_count": 3, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "# The same is possible with python (useful when working with scripts!)\n", - "import os\n", - "\n", - "os.getcwd()" - ] - }, - { - "cell_type": "code", - "execution_count": 4, - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "['Data',\n", - " '4 - 2D Imaging - TIFF (CLASS).ipynb',\n", - " 'environment.yml',\n", - " '5 - Gaussian Fitting.ipynb',\n", - " '.ipynb_checkpoints',\n", - " '2 - Introduction to File Manipulation and Plotting.ipynb',\n", - " '4 - 2D Imaging - TIFF (FULL).ipynb',\n", - " '0.0 - introduction.ipynb',\n", - " '3 - Multiple plots - Glob - advanced.ipynb',\n", - " 'hdfview.png',\n", - " '6 - HDF files.ipynb',\n", - " '1.3 - introduction to python (CLASS).ipynb',\n", - " '.gitignore',\n", - " '.git',\n", - " '4 - 2D Imaging - FITS.ipynb',\n", - " '3 - Multiple plots - Glob.ipynb',\n", - " '1.3 - introduction to python (FULL).ipynb',\n", - " 'README.md',\n", - " '7 - widgets.ipynb',\n", - " '1.1 - jupyter not a book.ipynb',\n", - " '1.2 - markdown syntax.ipynb',\n", - " '1.0 - jupyter dashboard.ipynb']" - ] - }, - "execution_count": 4, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "# Note the output is always list!\n", - "os.listdir()" - ] - }, - { - "cell_type": "code", - "execution_count": 5, - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "['subdir2',\n", - " 'f2.txt',\n", - " 'f5.txt',\n", - " 'a2.dat',\n", - " 'subdir1',\n", - " 'f4.txt',\n", - " 'a3.dat',\n", - " 'f3.txt',\n", - " 'b1.dat',\n", - " 'f9.txt',\n", - " 'f7.txt',\n", - " 'b2.dat',\n", - " 'b3.dat',\n", - " 'b4.dat',\n", - " 'f6.txt',\n", - " 'a1.dat',\n", - " 'f1.txt',\n", - " 'f8.txt']" - ] - }, - "execution_count": 5, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "os.listdir(\"Data/Glob\")" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "## File Manipulation: `os.path` module" - ] - }, - { - "cell_type": "code", - "execution_count": 6, - "metadata": {}, - "outputs": [], - "source": [ - "# Let's pick one file\n", - "file_path = \"Data/Glob/f1.txt\"" - ] - }, - { - "cell_type": "code", - "execution_count": 7, - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "True" - ] - }, - "execution_count": 7, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "import os.path\n", - "os.path.exists(file_path)" - ] - }, - { - "cell_type": "code", - "execution_count": 8, - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "['__all__',\n", - " '__builtins__',\n", - " '__cached__',\n", - " '__doc__',\n", - " '__file__',\n", - " '__loader__',\n", - " '__name__',\n", - " '__package__',\n", - " '__spec__',\n", - " '_get_sep',\n", - " '_joinrealpath',\n", - " '_varprog',\n", - " '_varprogb',\n", - " 'abspath',\n", - " 'altsep',\n", - " 'basename',\n", - " 'commonpath',\n", - " 'commonprefix',\n", - " 'curdir',\n", - " 'defpath',\n", - " 'devnull',\n", - " 'dirname',\n", - " 'exists',\n", - " 'expanduser',\n", - " 'expandvars',\n", - " 'extsep',\n", - " 'genericpath',\n", - " 'getatime',\n", - " 'getctime',\n", - " 'getmtime',\n", - " 'getsize',\n", - " 'isabs',\n", - " 'isdir',\n", - " 'isfile',\n", - " 'islink',\n", - " 'ismount',\n", - " 'join',\n", - " 'lexists',\n", - " 'normcase',\n", - " 'normpath',\n", - " 'os',\n", - " 'pardir',\n", - " 'pathsep',\n", - " 'realpath',\n", - " 'relpath',\n", - " 'samefile',\n", - " 'sameopenfile',\n", - " 'samestat',\n", - " 'sep',\n", - " 'split',\n", - " 'splitdrive',\n", - " 'splitext',\n", - " 'stat',\n", - " 'supports_unicode_filenames',\n", - " 'sys']" - ] - }, - "execution_count": 8, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "# show what is available in os.path: or dir(...)\n", - "dir(os.path)" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "### Exercise\n", - "\n", - "```\n", - "/SNS/users/rhf/git/IPythonNotebookTutorial/Data/Glob/f1.txt\n", - " ------ 1\n", - "----------------------------------------------------------- 2\n", - " ----------- 3\n", - "----------------------------------------------------- 4 \n", - "```\n", - "\n", - "1. Get only the file name of file_path\n", - "2. Get the full path of file_path\n", - "3. Get the directory where the file_path is\n", - "4. Absolute directory where file_path is" - ] - }, - { - "cell_type": "code", - "execution_count": 13, - "metadata": { - "scrolled": true - }, - "outputs": [ - { - "data": { - "text/plain": [ - "'f1.txt'" - ] - }, - "execution_count": 13, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "# 1. File name\n", - "os.path.basename(file_path)" - ] - }, - { - "cell_type": "code", - "execution_count": 14, - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "'/SNS/users/rhf/git/IPythonNotebookTutorial/Data/Glob/f1.txt'" - ] - }, - "execution_count": 14, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "# 2. Full path\n", - "os.path.abspath(file_path)" - ] - }, - { - "cell_type": "code", - "execution_count": 15, - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "'Data/Glob'" - ] - }, - "execution_count": 15, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "# 3. Directory where the file is\n", - "os.path.dirname(file_path)" - ] - }, - { - "cell_type": "code", - "execution_count": 16, - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "'/SNS/users/rhf/git/IPythonNotebookTutorial/Data/Glob'" - ] - }, - "execution_count": 16, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "# 4. Absolute directory where the file is\n", - "os.path.dirname(\n", - " os.path.abspath(file_path)\n", - ")" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "How to get the **file extension**:" - ] - }, - { - "cell_type": "code", - "execution_count": 17, - "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "prefix = Data/Glob/f1; suffix = .txt; suffix without '.' = txt.\n" - ] - } - ], - "source": [ - "prefix, suffix = os.path.splitext(file_path)\n", - "print(\"prefix = {}; suffix = {}; suffix without '.' = {}.\".format(prefix, suffix, suffix[1:]))" - ] - }, - { - "cell_type": "code", - "execution_count": 18, - "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "f1.txt\n", - "['f1', 'txt']\n", - "txt\n" - ] - } - ], - "source": [ - "# Extension\n", - "filename_only = os.path.basename(file_path)\n", - "print(filename_only)\n", - "print(filename_only.split(\".\"))\n", - "print(filename_only.split(\".\")[-1])\n" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "# Numpy Arrays" - ] - }, - { - "cell_type": "code", - "execution_count": 19, - "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "# X , Y , E , DX\r\n", - "1\r\n", - "0.00232478,8.22832,0.677097,0.0020133\r\n", - "0.00458718,5.8915,0.193922,0.00192328\r\n", - "0.00684958,12.573,0.413909,0.00189569\r\n", - "0.00911198,37.3161,0.768022,0.00199785\r\n", - "0.0113744,156.672,2.59008,0.00205609\r\n", - "0.0136368,567.555,11.7842,0.00217489\r\n", - "0.0158992,1401.89,16.1017,0.00229348\r\n", - "0.0181616,1334.2,13.4719,0.00239931\r\n" - ] - } - ], - "source": [ - "# Let's get back to our file\n", - "!head Data/Glob/f1.txt" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "**The file has:**\n", - "- header: `x`, `y`, `Err(y)`, `Err(x)`\n", - " - This a 1D SANS I(Q) curve output by Mantid.\n", - "- Two rows header\n" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "### Reading `csv` files as `numpy` arrays\n", - "\n", - "For the function `np.genfromtxt` see https://docs.scipy.org/doc/numpy-1.14.0/reference/generated/numpy.genfromtxt.html" - ] - }, - { - "cell_type": "code", - "execution_count": 20, - "metadata": {}, - "outputs": [], - "source": [ - "import numpy as np" - ] - }, - { - "cell_type": "code", - "execution_count": 21, - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "array([ 1., nan, nan, nan, nan, nan, nan, nan, nan, nan, nan,\n", - " nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan,\n", - " nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan,\n", - " nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan,\n", - " nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan,\n", - " nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan,\n", - " nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan,\n", - " nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan,\n", - " nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan,\n", - " nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan,\n", - " nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan,\n", - " nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan,\n", - " nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan,\n", - " nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan,\n", - " nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan,\n", - " nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan,\n", - " nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan,\n", - " nan, nan, nan, nan, nan, nan, nan, nan, nan, nan, nan,\n", - " nan, nan, nan])" - ] - }, - "execution_count": 21, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "data = np.genfromtxt(\n", - " file_path,\n", - ")\n", - "# Data is meanlingless!\n", - "data" - ] - }, - { - "cell_type": "code", - "execution_count": 22, - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "array([[ 2.32478000e-03, 8.22832000e+00, 6.77097000e-01,\n", - " 2.01330000e-03],\n", - " [ 4.58718000e-03, 5.89150000e+00, 1.93922000e-01,\n", - " 1.92328000e-03],\n", - " [ 6.84958000e-03, 1.25730000e+01, 4.13909000e-01,\n", - " 1.89569000e-03],\n", - " [ 9.11198000e-03, 3.73161000e+01, 7.68022000e-01,\n", - " 1.99785000e-03],\n", - " [ 1.13744000e-02, 1.56672000e+02, 2.59008000e+00,\n", - " 2.05609000e-03],\n", - " [ 1.36368000e-02, 5.67555000e+02, 1.17842000e+01,\n", - " 2.17489000e-03],\n", - " [ 1.58992000e-02, 1.40189000e+03, 1.61017000e+01,\n", - " 2.29348000e-03],\n", - " [ 1.81616000e-02, 1.33420000e+03, 1.34719000e+01,\n", - " 2.39931000e-03],\n", - " [ 2.04240000e-02, 1.62173000e+03, 2.00042000e+01,\n", - " 2.47893000e-03],\n", - " [ 2.26864000e-02, 1.40312000e+03, 1.01434000e+01,\n", - " 2.56543000e-03],\n", - " [ 2.49488000e-02, 1.30591000e+03, 1.03458000e+01,\n", - " 2.60186000e-03],\n", - " [ 2.72112000e-02, 7.52002000e+02, 6.22791000e+00,\n", - " 2.63457000e-03],\n", - " [ 2.94736000e-02, 5.86367000e+02, 3.34320000e+00,\n", - " 2.69503000e-03],\n", - " [ 3.17360000e-02, 4.63746000e+02, 2.83678000e+00,\n", - " 2.73969000e-03],\n", - " [ 3.39984000e-02, 2.82236000e+02, 1.72425000e+00,\n", - " 2.78730000e-03],\n", - " [ 3.62608000e-02, 2.52291000e+02, 1.15568000e+00,\n", - " 2.85656000e-03],\n", - " [ 3.85232000e-02, 1.94139000e+02, 1.03233000e+00,\n", - " 2.90755000e-03],\n", - " [ 4.07856000e-02, 1.32505000e+02, 6.23850000e-01,\n", - " 2.96543000e-03],\n", - " [ 4.30480000e-02, 1.25275000e+02, 5.16059000e-01,\n", - " 3.04760000e-03],\n", - " [ 4.53104000e-02, 1.03933000e+02, 5.11167000e-01,\n", - " 3.10267000e-03],\n", - " [ 4.75728000e-02, 7.45236000e+01, 2.99432000e-01,\n", - " 3.17061000e-03],\n", - " [ 4.98352000e-02, 7.13951000e+01, 2.37603000e-01,\n", - " 3.25667000e-03],\n", - " [ 5.20976000e-02, 5.80103000e+01, 2.38909000e-01,\n", - " 3.32773000e-03],\n", - " [ 5.43600000e-02, 4.54162000e+01, 1.42499000e-01,\n", - " 3.39323000e-03],\n", - " [ 5.66224000e-02, 4.26769000e+01, 1.37849000e-01,\n", - " 3.48751000e-03],\n", - " [ 5.88848000e-02, 3.39084000e+01, 1.14000000e-01,\n", - " 3.55319000e-03],\n", - " [ 6.11472000e-02, 3.04780000e+01, 8.58282000e-02,\n", - " 3.64613000e-03],\n", - " [ 6.34096000e-02, 2.78833000e+01, 8.75005000e-02,\n", - " 3.73615000e-03],\n", - " [ 6.56720000e-02, 2.29170000e+01, 6.68278000e-02,\n", - " 3.81589000e-03],\n", - " [ 6.79344000e-02, 2.06575000e+01, 5.15695000e-02,\n", - " 3.90849000e-03],\n", - " [ 7.01968000e-02, 1.89313000e+01, 5.42510000e-02,\n", - " 3.99867000e-03],\n", - " [ 7.24592000e-02, 1.59109000e+01, 4.22886000e-02,\n", - " 4.06174000e-03],\n", - " [ 7.47216000e-02, 1.45817000e+01, 3.29170000e-02,\n", - " 4.15516000e-03],\n", - " [ 7.69840000e-02, 1.33736000e+01, 3.52660000e-02,\n", - " 4.23386000e-03],\n", - " [ 7.92464000e-02, 1.14957000e+01, 2.76601000e-02,\n", - " 4.30617000e-03],\n", - " [ 8.15088000e-02, 1.12811000e+01, 2.36873000e-02,\n", - " 4.43354000e-03],\n", - " [ 8.37712000e-02, 9.91017000e+00, 2.43837000e-02,\n", - " 4.45424000e-03],\n", - " [ 8.60336000e-02, 8.96414000e+00, 1.80221000e-02,\n", - " 4.59522000e-03],\n", - " [ 8.82960000e-02, 8.29776000e+00, 1.74276000e-02,\n", - " 4.66863000e-03],\n", - " [ 9.05584000e-02, 7.84076000e+00, 1.70118000e-02,\n", - " 4.74494000e-03],\n", - " [ 9.28208000e-02, 7.19617000e+00, 1.37185000e-02,\n", - " 4.85222000e-03],\n", - " [ 9.50832000e-02, 6.71241000e+00, 1.31788000e-02,\n", - " 4.93926000e-03],\n", - " [ 9.73456000e-02, 6.32092000e+00, 1.20530000e-02,\n", - " 5.01939000e-03],\n", - " [ 9.96080000e-02, 5.84345000e+00, 1.04203000e-02,\n", - " 5.12144000e-03],\n", - " [ 1.01870000e-01, 5.58809000e+00, 1.05965000e-02,\n", - " 5.19627000e-03],\n", - " [ 1.04133000e-01, 5.20974000e+00, 1.01126000e-02,\n", - " 5.32484000e-03],\n", - " [ 1.06395000e-01, 4.70643000e+00, 8.30563000e-03,\n", - " 5.37297000e-03],\n", - " [ 1.08658000e-01, 4.60372000e+00, 8.73295000e-03,\n", - " 5.48339000e-03],\n", - " [ 1.10920000e-01, 4.33336000e+00, 7.33537000e-03,\n", - " 5.59051000e-03],\n", - " [ 1.13182000e-01, 4.25171000e+00, 6.74788000e-03,\n", - " 5.69599000e-03],\n", - " [ 1.15445000e-01, 3.75440000e+00, 6.66471000e-03,\n", - " 5.75616000e-03],\n", - " [ 1.17707000e-01, 3.57895000e+00, 5.60087000e-03,\n", - " 5.87507000e-03],\n", - " [ 1.19970000e-01, 3.59152000e+00, 5.24790000e-03,\n", - " 5.99054000e-03],\n", - " [ 1.22232000e-01, 3.43869000e+00, 6.13958000e-03,\n", - " 6.06209000e-03],\n", - " [ 1.24494000e-01, 3.30020000e+00, 5.02378000e-03,\n", - " 6.16088000e-03],\n", - " [ 1.26757000e-01, 3.15643000e+00, 5.34797000e-03,\n", - " 6.25433000e-03],\n", - " [ 1.29019000e-01, 3.06221000e+00, 4.91215000e-03,\n", - " 6.35325000e-03],\n", - " [ 1.31282000e-01, 2.95474000e+00, 4.41837000e-03,\n", - " 6.47504000e-03],\n", - " [ 1.33544000e-01, 2.75973000e+00, 4.36462000e-03,\n", - " 6.56997000e-03],\n", - " [ 1.35806000e-01, 2.75132000e+00, 4.13429000e-03,\n", - " 6.70515000e-03],\n", - " [ 1.38069000e-01, 2.59006000e+00, 3.84002000e-03,\n", - " 6.81656000e-03],\n", - " [ 1.40331000e-01, 2.70392000e+00, 4.15889000e-03,\n", - " 6.95484000e-03],\n", - " [ 1.42594000e-01, 2.40971000e+00, 3.67286000e-03,\n", - " 7.04784000e-03],\n", - " [ 1.44856000e-01, 2.41678000e+00, 3.35878000e-03,\n", - " 7.22162000e-03],\n", - " [ 1.47118000e-01, 2.41169000e+00, 3.61040000e-03,\n", - " 7.33503000e-03],\n", - " [ 1.49381000e-01, 2.31052000e+00, 3.21215000e-03,\n", - " 7.46144000e-03],\n", - " [ 1.51643000e-01, 2.30365000e+00, 2.88732000e-03,\n", - " 7.62406000e-03],\n", - " [ 1.53906000e-01, 2.28111000e+00, 3.14603000e-03,\n", - " 7.73543000e-03],\n", - " [ 1.56168000e-01, 2.16173000e+00, 2.64020000e-03,\n", - " 7.93215000e-03],\n", - " [ 1.58430000e-01, 2.24121000e+00, 2.79995000e-03,\n", - " 8.09307000e-03],\n", - " [ 1.60693000e-01, 2.00375000e+00, 2.61229000e-03,\n", - " 8.23530000e-03],\n", - " [ 1.62955000e-01, 2.04535000e+00, 2.29611000e-03,\n", - " 8.38376000e-03],\n", - " [ 1.65218000e-01, 1.97023000e+00, 2.42616000e-03,\n", - " 8.57472000e-03],\n", - " [ 1.67480000e-01, 1.92842000e+00, 2.28993000e-03,\n", - " 8.68331000e-03],\n", - " [ 1.69742000e-01, 2.00759000e+00, 2.19525000e-03,\n", - " 8.92482000e-03],\n", - " [ 1.72005000e-01, 1.90848000e+00, 2.35142000e-03,\n", - " 9.04882000e-03],\n", - " [ 1.74267000e-01, 1.93957000e+00, 2.17204000e-03,\n", - " 9.24326000e-03],\n", - " [ 1.76530000e-01, 1.84568000e+00, 1.91813000e-03,\n", - " 9.43445000e-03],\n", - " [ 1.78792000e-01, 1.84602000e+00, 2.14060000e-03,\n", - " 9.56254000e-03],\n", - " [ 1.81054000e-01, 1.76200000e+00, 1.90354000e-03,\n", - " 9.80488000e-03],\n", - " [ 1.83317000e-01, 1.75111000e+00, 1.74428000e-03,\n", - " 9.95011000e-03],\n", - " [ 1.85579000e-01, 1.87683000e+00, 2.09675000e-03,\n", - " 1.01434000e-02],\n", - " [ 1.87842000e-01, 1.73987000e+00, 1.77651000e-03,\n", - " 1.03764000e-02],\n", - " [ 1.90104000e-01, 1.80290000e+00, 1.75987000e-03,\n", - " 1.05471000e-02],\n", - " [ 1.92366000e-01, 1.67046000e+00, 1.73862000e-03,\n", - " 1.07355000e-02],\n", - " [ 1.94629000e-01, 1.69074000e+00, 1.61779000e-03,\n", - " 1.09622000e-02],\n", - " [ 1.96891000e-01, 1.66550000e+00, 1.64625000e-03,\n", - " 1.11471000e-02],\n", - " [ 1.99154000e-01, 1.63165000e+00, 1.59898000e-03,\n", - " 1.13915000e-02],\n", - " [ 2.01416000e-01, 1.58160000e+00, 1.46371000e-03,\n", - " 1.15784000e-02],\n", - " [ 2.03678000e-01, 1.63511000e+00, 1.60772000e-03,\n", - " 1.17673000e-02],\n", - " [ 2.05941000e-01, 1.63747000e+00, 1.54188000e-03,\n", - " 1.20110000e-02],\n", - " [ 2.08203000e-01, 1.55044000e+00, 1.38552000e-03,\n", - " 1.22274000e-02],\n", - " [ 2.10466000e-01, 1.56580000e+00, 1.50506000e-03,\n", - " 1.24266000e-02],\n", - " [ 2.12728000e-01, 1.45895000e+00, 1.30108000e-03,\n", - " 1.26529000e-02],\n", - " [ 2.14990000e-01, 1.54536000e+00, 1.32162000e-03,\n", - " 1.29049000e-02],\n", - " [ 2.17253000e-01, 1.51461000e+00, 1.42400000e-03,\n", - " 1.30589000e-02],\n", - " [ 2.19515000e-01, 1.49411000e+00, 1.28816000e-03,\n", - " 1.33043000e-02],\n", - " [ 2.21778000e-01, 1.50372000e+00, 1.25136000e-03,\n", - " 1.34998000e-02],\n", - " [ 2.24040000e-01, 1.56236000e+00, 1.42167000e-03,\n", - " 1.37487000e-02],\n", - " [ 2.26302000e-01, 1.44359000e+00, 1.15841000e-03,\n", - " 1.39386000e-02],\n", - " [ 2.28565000e-01, 1.43892000e+00, 1.20448000e-03,\n", - " 1.41531000e-02],\n", - " [ 2.30827000e-01, 1.46005000e+00, 1.21956000e-03,\n", - " 1.43515000e-02],\n", - " [ 2.33090000e-01, 1.46053000e+00, 1.17015000e-03,\n", - " 1.46494000e-02],\n", - " [ 2.35352000e-01, 1.45386000e+00, 1.21480000e-03,\n", - " 1.48436000e-02],\n", - " [ 2.37614000e-01, 1.43670000e+00, 1.16289000e-03,\n", - " 1.50335000e-02],\n", - " [ 2.39877000e-01, 1.46604000e+00, 1.11884000e-03,\n", - " 1.53295000e-02],\n", - " [ 2.42139000e-01, 1.41836000e+00, 1.15156000e-03,\n", - " 1.54842000e-02],\n", - " [ 2.44402000e-01, 1.43869000e+00, 1.14041000e-03,\n", - " 1.56994000e-02],\n", - " [ 2.46664000e-01, 1.44536000e+00, 1.07685000e-03,\n", - " 1.60131000e-02],\n", - " [ 2.48926000e-01, 1.52036000e+00, 1.24142000e-03,\n", - " 1.61667000e-02],\n", - " [ 2.51189000e-01, 1.40447000e+00, 1.04701000e-03,\n", - " 1.64298000e-02],\n", - " [ 2.53451000e-01, 1.45618000e+00, 1.04613000e-03,\n", - " 1.66609000e-02],\n", - " [ 2.55714000e-01, 1.31826000e+00, 1.06160000e-03,\n", - " 1.67973000e-02],\n", - " [ 2.57976000e-01, 1.35123000e+00, 9.29192000e-04,\n", - " 1.71077000e-02],\n", - " [ 2.60238000e-01, 1.36036000e+00, 1.01070000e-03,\n", - " 1.72913000e-02],\n", - " [ 2.62501000e-01, 1.33275000e+00, 1.00183000e-03,\n", - " 1.75239000e-02],\n", - " [ 2.64763000e-01, 1.40282000e+00, 9.87916000e-04,\n", - " 1.78241000e-02],\n", - " [ 2.67026000e-01, 1.33950000e+00, 1.01891000e-03,\n", - " 1.79383000e-02],\n", - " [ 2.69288000e-01, 1.33759000e+00, 9.71319000e-04,\n", - " 1.82463000e-02],\n", - " [ 2.71550000e-01, 1.37715000e+00, 1.03639000e-03,\n", - " 1.84218000e-02],\n", - " [ 2.73813000e-01, 1.29646000e+00, 1.01499000e-03,\n", - " 1.86265000e-02],\n", - " [ 2.76075000e-01, 1.35901000e+00, 9.89784000e-04,\n", - " 1.89069000e-02],\n", - " [ 2.78338000e-01, 1.27646000e+00, 9.79190000e-04,\n", - " 1.90349000e-02],\n", - " [ 2.80600000e-01, 1.29041000e+00, 1.01598000e-03,\n", - " 1.92846000e-02],\n", - " [ 2.82862000e-01, 1.34233000e+00, 9.72415000e-04,\n", - " 1.95668000e-02],\n", - " [ 2.85125000e-01, 1.30539000e+00, 1.04033000e-03,\n", - " 1.96904000e-02],\n", - " [ 2.87387000e-01, 1.32256000e+00, 1.10708000e-03,\n", - " 1.99250000e-02],\n", - " [ 2.89650000e-01, 1.28919000e+00, 1.00851000e-03,\n", - " 2.01828000e-02],\n", - " [ 2.91912000e-01, 1.29895000e+00, 1.08788000e-03,\n", - " 2.03732000e-02],\n", - " [ 2.94174000e-01, 1.31408000e+00, 1.11481000e-03,\n", - " 2.06176000e-02],\n", - " [ 2.96437000e-01, 1.30226000e+00, 1.06193000e-03,\n", - " 2.08095000e-02],\n", - " [ 2.98699000e-01, 1.30589000e+00, 1.17047000e-03,\n", - " 2.09943000e-02],\n", - " [ 3.00962000e-01, 1.29786000e+00, 1.08535000e-03,\n", - " 2.13227000e-02],\n", - " [ 3.03224000e-01, 1.23239000e+00, 1.09345000e-03,\n", - " 2.14380000e-02],\n", - " [ 3.05486000e-01, 1.28156000e+00, 1.27915000e-03,\n", - " 2.15954000e-02],\n", - " [ 3.07749000e-01, 1.32796000e+00, 1.20706000e-03,\n", - " 2.19260000e-02],\n", - " [ 3.10011000e-01, 1.30217000e+00, 1.29243000e-03,\n", - " 2.21265000e-02],\n", - " [ 3.12274000e-01, 1.22154000e+00, 1.31353000e-03,\n", - " 2.22615000e-02],\n", - " [ 3.14536000e-01, 1.23972000e+00, 1.18866000e-03,\n", - " 2.25737000e-02],\n", - " [ 3.16798000e-01, 1.25601000e+00, 1.34261000e-03,\n", - " 2.27181000e-02],\n", - " [ 3.19061000e-01, 1.30090000e+00, 1.48065000e-03,\n", - " 2.29153000e-02],\n", - " [ 3.21323000e-01, 1.23908000e+00, 1.47062000e-03,\n", - " 2.31034000e-02],\n", - " [ 3.23586000e-01, 1.28162000e+00, 1.58856000e-03,\n", - " 2.34010000e-02],\n", - " [ 3.25848000e-01, 1.24657000e+00, 1.61703000e-03,\n", - " 2.34885000e-02],\n", - " [ 3.28110000e-01, 1.29387000e+00, 1.80401000e-03,\n", - " 2.37336000e-02],\n", - " [ 3.30373000e-01, 1.25754000e+00, 1.76106000e-03,\n", - " 2.39429000e-02],\n", - " [ 3.32635000e-01, 1.19356000e+00, 1.73731000e-03,\n", - " 2.41586000e-02],\n", - " [ 3.34898000e-01, 1.26474000e+00, 1.88188000e-03,\n", - " 2.44496000e-02],\n", - " [ 3.37160000e-01, 1.33097000e+00, 2.12157000e-03,\n", - " 2.45576000e-02],\n", - " [ 3.39422000e-01, 1.29467000e+00, 2.12446000e-03,\n", - " 2.47861000e-02],\n", - " [ 3.41685000e-01, 1.23477000e+00, 2.14140000e-03,\n", - " 2.50466000e-02],\n", - " [ 3.43947000e-01, 1.28147000e+00, 2.29357000e-03,\n", - " 2.53031000e-02],\n", - " [ 3.46210000e-01, 1.23232000e+00, 2.23000000e-03,\n", - " 2.54372000e-02],\n", - " [ 3.48472000e-01, 1.25183000e+00, 2.46401000e-03,\n", - " 2.56826000e-02],\n", - " [ 3.50734000e-01, 1.17120000e+00, 2.33285000e-03,\n", - " 2.58787000e-02],\n", - " [ 3.52997000e-01, 1.27463000e+00, 2.69883000e-03,\n", - " 2.61788000e-02],\n", - " [ 3.55259000e-01, 1.25092000e+00, 2.78934000e-03,\n", - " 2.63301000e-02],\n", - " [ 3.57522000e-01, 1.17056000e+00, 2.68148000e-03,\n", - " 2.65042000e-02],\n", - " [ 3.59784000e-01, 1.25435000e+00, 3.12805000e-03,\n", - " 2.68127000e-02],\n", - " [ 3.62046000e-01, 1.18626000e+00, 3.02630000e-03,\n", - " 2.69865000e-02],\n", - " [ 3.64309000e-01, 1.32139000e+00, 3.42370000e-03,\n", - " 2.72790000e-02],\n", - " [ 3.66571000e-01, 1.14499000e+00, 3.21330000e-03,\n", - " 2.74250000e-02],\n", - " [ 3.68834000e-01, 1.24132000e+00, 3.94092000e-03,\n", - " 2.77147000e-02],\n", - " [ 3.71096000e-01, 1.34991000e+00, 4.20847000e-03,\n", - " 2.79620000e-02],\n", - " [ 3.73358000e-01, 1.21190000e+00, 4.16068000e-03,\n", - " 2.80234000e-02],\n", - " [ 3.75621000e-01, 1.28882000e+00, 4.61407000e-03,\n", - " 2.83759000e-02],\n", - " [ 3.77883000e-01, 1.17028000e+00, 4.37559000e-03,\n", - " 2.85256000e-02],\n", - " [ 3.80146000e-01, 1.21848000e+00, 5.11970000e-03,\n", - " 2.86588000e-02],\n", - " [ 3.82408000e-01, 1.16478000e+00, 5.21820000e-03,\n", - " 2.89052000e-02],\n", - " [ 3.84670000e-01, 1.26369000e+00, 6.23799000e-03,\n", - " 2.90982000e-02],\n", - " [ 3.86933000e-01, 1.16811000e+00, 6.31712000e-03,\n", - " 2.92588000e-02],\n", - " [ 3.89195000e-01, 1.19013000e+00, 6.64985000e-03,\n", - " 2.95441000e-02],\n", - " [ 3.91458000e-01, 1.27868000e+00, 7.78585000e-03,\n", - " 2.96640000e-02],\n", - " [ 3.93720000e-01, 1.14789000e+00, 7.52957000e-03,\n", - " 3.00074000e-02],\n", - " [ 3.95982000e-01, 1.19087000e+00, 8.64753000e-03,\n", - " 3.02353000e-02],\n", - " [ 3.98245000e-01, 1.23422000e+00, 1.08036000e-02,\n", - " 3.03397000e-02],\n", - " [ 4.00507000e-01, 1.45145000e+00, 1.23926000e-02,\n", - " 3.07376000e-02],\n", - " [ 4.02770000e-01, 1.29427000e+00, 1.34012000e-02,\n", - " 3.07170000e-02],\n", - " [ 4.05032000e-01, 1.23035000e+00, 1.40164000e-02,\n", - " 3.11565000e-02],\n", - " [ 4.07294000e-01, 1.21974000e+00, 1.39044000e-02,\n", - " 3.13112000e-02],\n", - " [ 4.09557000e-01, 1.00004000e+00, 1.31590000e-02,\n", - " 3.15002000e-02],\n", - " [ 4.11819000e-01, 1.08915000e+00, 1.69467000e-02,\n", - " 3.16693000e-02],\n", - " [ 4.14082000e-01, 1.22531000e+00, 2.20794000e-02,\n", - " 3.18296000e-02],\n", - " [ 4.16344000e-01, 1.31332000e+00, 2.49976000e-02,\n", - " 3.19910000e-02],\n", - " [ 4.18606000e-01, 1.00532000e+00, 2.29697000e-02,\n", - " 3.21780000e-02],\n", - " [ 4.20869000e-01, 1.17157000e+00, 3.34778000e-02,\n", - " 3.23646000e-02],\n", - " [ 4.23131000e-01, 1.54398000e+00, 6.62195000e-02,\n", - " 3.25359000e-02],\n", - " [ 4.25394000e-01, 1.02969000e+00, 5.04892000e-02,\n", - " 3.26751000e-02],\n", - " [ 4.27656000e-01, 8.58565000e-01, 4.91425000e-02,\n", - " 3.28817000e-02],\n", - " [ 4.29918000e-01, 8.01629000e-01, 9.18017000e-02,\n", - " 3.30360000e-02],\n", - " [ 4.32181000e-01, 1.48946000e+00, 1.70656000e-01,\n", - " 3.32177000e-02],\n", - " [ 4.34443000e-01, 6.87675000e-01, 2.36449000e-01,\n", - " 3.33237000e-02],\n", - " [ 4.36706000e-01, 0.00000000e+00, 0.00000000e+00,\n", - " 0.00000000e+00],\n", - " [ 4.38968000e-01, 0.00000000e+00, 0.00000000e+00,\n", - " 0.00000000e+00],\n", - " [ 4.41230000e-01, 0.00000000e+00, 0.00000000e+00,\n", - " 0.00000000e+00],\n", - " [ 4.43493000e-01, 0.00000000e+00, 0.00000000e+00,\n", - " 0.00000000e+00],\n", - " [ 4.45755000e-01, 0.00000000e+00, 0.00000000e+00,\n", - " 0.00000000e+00],\n", - " [ 4.48018000e-01, 0.00000000e+00, 0.00000000e+00,\n", - " 0.00000000e+00],\n", - " [ 4.50280000e-01, 0.00000000e+00, 0.00000000e+00,\n", - " 0.00000000e+00],\n", - " [ 4.52542000e-01, 0.00000000e+00, 0.00000000e+00,\n", - " 0.00000000e+00]])" - ] - }, - "execution_count": 22, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "import numpy as np\n", - "data = np.genfromtxt(\n", - " file_path,\n", - " delimiter=\",\",\n", - " skip_header=2,\n", - ")\n", - "# Data is 2D numpy array: 200 rows, 4 columns\n", - "data" - ] - }, - { - "cell_type": "code", - "execution_count": 23, - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "(200, 4)" - ] - }, - "execution_count": 23, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "data.shape" - ] - }, - { - "cell_type": "code", - "execution_count": 24, - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "array([( 0.00232478, 8.22832000e+00, 6.77097000e-01, 0.0020133 ),\n", - " ( 0.00458718, 5.89150000e+00, 1.93922000e-01, 0.00192328),\n", - " ( 0.00684958, 1.25730000e+01, 4.13909000e-01, 0.00189569),\n", - " ( 0.00911198, 3.73161000e+01, 7.68022000e-01, 0.00199785),\n", - " ( 0.0113744 , 1.56672000e+02, 2.59008000e+00, 0.00205609),\n", - " ( 0.0136368 , 5.67555000e+02, 1.17842000e+01, 0.00217489),\n", - " ( 0.0158992 , 1.40189000e+03, 1.61017000e+01, 0.00229348),\n", - " ( 0.0181616 , 1.33420000e+03, 1.34719000e+01, 0.00239931),\n", - " ( 0.020424 , 1.62173000e+03, 2.00042000e+01, 0.00247893),\n", - " ( 0.0226864 , 1.40312000e+03, 1.01434000e+01, 0.00256543),\n", - " ( 0.0249488 , 1.30591000e+03, 1.03458000e+01, 0.00260186),\n", - " ( 0.0272112 , 7.52002000e+02, 6.22791000e+00, 0.00263457),\n", - " ( 0.0294736 , 5.86367000e+02, 3.34320000e+00, 0.00269503),\n", - " ( 0.031736 , 4.63746000e+02, 2.83678000e+00, 0.00273969),\n", - " ( 0.0339984 , 2.82236000e+02, 1.72425000e+00, 0.0027873 ),\n", - " ( 0.0362608 , 2.52291000e+02, 1.15568000e+00, 0.00285656),\n", - " ( 0.0385232 , 1.94139000e+02, 1.03233000e+00, 0.00290755),\n", - " ( 0.0407856 , 1.32505000e+02, 6.23850000e-01, 0.00296543),\n", - " ( 0.043048 , 1.25275000e+02, 5.16059000e-01, 0.0030476 ),\n", - " ( 0.0453104 , 1.03933000e+02, 5.11167000e-01, 0.00310267),\n", - " ( 0.0475728 , 7.45236000e+01, 2.99432000e-01, 0.00317061),\n", - " ( 0.0498352 , 7.13951000e+01, 2.37603000e-01, 0.00325667),\n", - " ( 0.0520976 , 5.80103000e+01, 2.38909000e-01, 0.00332773),\n", - " ( 0.05436 , 4.54162000e+01, 1.42499000e-01, 0.00339323),\n", - " ( 0.0566224 , 4.26769000e+01, 1.37849000e-01, 0.00348751),\n", - " ( 0.0588848 , 3.39084000e+01, 1.14000000e-01, 0.00355319),\n", - " ( 0.0611472 , 3.04780000e+01, 8.58282000e-02, 0.00364613),\n", - " ( 0.0634096 , 2.78833000e+01, 8.75005000e-02, 0.00373615),\n", - " ( 0.065672 , 2.29170000e+01, 6.68278000e-02, 0.00381589),\n", - " ( 0.0679344 , 2.06575000e+01, 5.15695000e-02, 0.00390849),\n", - " ( 0.0701968 , 1.89313000e+01, 5.42510000e-02, 0.00399867),\n", - " ( 0.0724592 , 1.59109000e+01, 4.22886000e-02, 0.00406174),\n", - " ( 0.0747216 , 1.45817000e+01, 3.29170000e-02, 0.00415516),\n", - " ( 0.076984 , 1.33736000e+01, 3.52660000e-02, 0.00423386),\n", - " ( 0.0792464 , 1.14957000e+01, 2.76601000e-02, 0.00430617),\n", - " ( 0.0815088 , 1.12811000e+01, 2.36873000e-02, 0.00443354),\n", - " ( 0.0837712 , 9.91017000e+00, 2.43837000e-02, 0.00445424),\n", - " ( 0.0860336 , 8.96414000e+00, 1.80221000e-02, 0.00459522),\n", - " ( 0.088296 , 8.29776000e+00, 1.74276000e-02, 0.00466863),\n", - " ( 0.0905584 , 7.84076000e+00, 1.70118000e-02, 0.00474494),\n", - " ( 0.0928208 , 7.19617000e+00, 1.37185000e-02, 0.00485222),\n", - " ( 0.0950832 , 6.71241000e+00, 1.31788000e-02, 0.00493926),\n", - " ( 0.0973456 , 6.32092000e+00, 1.20530000e-02, 0.00501939),\n", - " ( 0.099608 , 5.84345000e+00, 1.04203000e-02, 0.00512144),\n", - " ( 0.10187 , 5.58809000e+00, 1.05965000e-02, 0.00519627),\n", - " ( 0.104133 , 5.20974000e+00, 1.01126000e-02, 0.00532484),\n", - " ( 0.106395 , 4.70643000e+00, 8.30563000e-03, 0.00537297),\n", - " ( 0.108658 , 4.60372000e+00, 8.73295000e-03, 0.00548339),\n", - " ( 0.11092 , 4.33336000e+00, 7.33537000e-03, 0.00559051),\n", - " ( 0.113182 , 4.25171000e+00, 6.74788000e-03, 0.00569599),\n", - " ( 0.115445 , 3.75440000e+00, 6.66471000e-03, 0.00575616),\n", - " ( 0.117707 , 3.57895000e+00, 5.60087000e-03, 0.00587507),\n", - " ( 0.11997 , 3.59152000e+00, 5.24790000e-03, 0.00599054),\n", - " ( 0.122232 , 3.43869000e+00, 6.13958000e-03, 0.00606209),\n", - " ( 0.124494 , 3.30020000e+00, 5.02378000e-03, 0.00616088),\n", - " ( 0.126757 , 3.15643000e+00, 5.34797000e-03, 0.00625433),\n", - " ( 0.129019 , 3.06221000e+00, 4.91215000e-03, 0.00635325),\n", - " ( 0.131282 , 2.95474000e+00, 4.41837000e-03, 0.00647504),\n", - " ( 0.133544 , 2.75973000e+00, 4.36462000e-03, 0.00656997),\n", - " ( 0.135806 , 2.75132000e+00, 4.13429000e-03, 0.00670515),\n", - " ( 0.138069 , 2.59006000e+00, 3.84002000e-03, 0.00681656),\n", - " ( 0.140331 , 2.70392000e+00, 4.15889000e-03, 0.00695484),\n", - " ( 0.142594 , 2.40971000e+00, 3.67286000e-03, 0.00704784),\n", - " ( 0.144856 , 2.41678000e+00, 3.35878000e-03, 0.00722162),\n", - " ( 0.147118 , 2.41169000e+00, 3.61040000e-03, 0.00733503),\n", - " ( 0.149381 , 2.31052000e+00, 3.21215000e-03, 0.00746144),\n", - " ( 0.151643 , 2.30365000e+00, 2.88732000e-03, 0.00762406),\n", - " ( 0.153906 , 2.28111000e+00, 3.14603000e-03, 0.00773543),\n", - " ( 0.156168 , 2.16173000e+00, 2.64020000e-03, 0.00793215),\n", - " ( 0.15843 , 2.24121000e+00, 2.79995000e-03, 0.00809307),\n", - " ( 0.160693 , 2.00375000e+00, 2.61229000e-03, 0.0082353 ),\n", - " ( 0.162955 , 2.04535000e+00, 2.29611000e-03, 0.00838376),\n", - " ( 0.165218 , 1.97023000e+00, 2.42616000e-03, 0.00857472),\n", - " ( 0.16748 , 1.92842000e+00, 2.28993000e-03, 0.00868331),\n", - " ( 0.169742 , 2.00759000e+00, 2.19525000e-03, 0.00892482),\n", - " ( 0.172005 , 1.90848000e+00, 2.35142000e-03, 0.00904882),\n", - " ( 0.174267 , 1.93957000e+00, 2.17204000e-03, 0.00924326),\n", - " ( 0.17653 , 1.84568000e+00, 1.91813000e-03, 0.00943445),\n", - " ( 0.178792 , 1.84602000e+00, 2.14060000e-03, 0.00956254),\n", - " ( 0.181054 , 1.76200000e+00, 1.90354000e-03, 0.00980488),\n", - " ( 0.183317 , 1.75111000e+00, 1.74428000e-03, 0.00995011),\n", - " ( 0.185579 , 1.87683000e+00, 2.09675000e-03, 0.0101434 ),\n", - " ( 0.187842 , 1.73987000e+00, 1.77651000e-03, 0.0103764 ),\n", - " ( 0.190104 , 1.80290000e+00, 1.75987000e-03, 0.0105471 ),\n", - " ( 0.192366 , 1.67046000e+00, 1.73862000e-03, 0.0107355 ),\n", - " ( 0.194629 , 1.69074000e+00, 1.61779000e-03, 0.0109622 ),\n", - " ( 0.196891 , 1.66550000e+00, 1.64625000e-03, 0.0111471 ),\n", - " ( 0.199154 , 1.63165000e+00, 1.59898000e-03, 0.0113915 ),\n", - " ( 0.201416 , 1.58160000e+00, 1.46371000e-03, 0.0115784 ),\n", - " ( 0.203678 , 1.63511000e+00, 1.60772000e-03, 0.0117673 ),\n", - " ( 0.205941 , 1.63747000e+00, 1.54188000e-03, 0.012011 ),\n", - " ( 0.208203 , 1.55044000e+00, 1.38552000e-03, 0.0122274 ),\n", - " ( 0.210466 , 1.56580000e+00, 1.50506000e-03, 0.0124266 ),\n", - " ( 0.212728 , 1.45895000e+00, 1.30108000e-03, 0.0126529 ),\n", - " ( 0.21499 , 1.54536000e+00, 1.32162000e-03, 0.0129049 ),\n", - " ( 0.217253 , 1.51461000e+00, 1.42400000e-03, 0.0130589 ),\n", - " ( 0.219515 , 1.49411000e+00, 1.28816000e-03, 0.0133043 ),\n", - " ( 0.221778 , 1.50372000e+00, 1.25136000e-03, 0.0134998 ),\n", - " ( 0.22404 , 1.56236000e+00, 1.42167000e-03, 0.0137487 ),\n", - " ( 0.226302 , 1.44359000e+00, 1.15841000e-03, 0.0139386 ),\n", - " ( 0.228565 , 1.43892000e+00, 1.20448000e-03, 0.0141531 ),\n", - " ( 0.230827 , 1.46005000e+00, 1.21956000e-03, 0.0143515 ),\n", - " ( 0.23309 , 1.46053000e+00, 1.17015000e-03, 0.0146494 ),\n", - " ( 0.235352 , 1.45386000e+00, 1.21480000e-03, 0.0148436 ),\n", - " ( 0.237614 , 1.43670000e+00, 1.16289000e-03, 0.0150335 ),\n", - " ( 0.239877 , 1.46604000e+00, 1.11884000e-03, 0.0153295 ),\n", - " ( 0.242139 , 1.41836000e+00, 1.15156000e-03, 0.0154842 ),\n", - " ( 0.244402 , 1.43869000e+00, 1.14041000e-03, 0.0156994 ),\n", - " ( 0.246664 , 1.44536000e+00, 1.07685000e-03, 0.0160131 ),\n", - " ( 0.248926 , 1.52036000e+00, 1.24142000e-03, 0.0161667 ),\n", - " ( 0.251189 , 1.40447000e+00, 1.04701000e-03, 0.0164298 ),\n", - " ( 0.253451 , 1.45618000e+00, 1.04613000e-03, 0.0166609 ),\n", - " ( 0.255714 , 1.31826000e+00, 1.06160000e-03, 0.0167973 ),\n", - " ( 0.257976 , 1.35123000e+00, 9.29192000e-04, 0.0171077 ),\n", - " ( 0.260238 , 1.36036000e+00, 1.01070000e-03, 0.0172913 ),\n", - " ( 0.262501 , 1.33275000e+00, 1.00183000e-03, 0.0175239 ),\n", - " ( 0.264763 , 1.40282000e+00, 9.87916000e-04, 0.0178241 ),\n", - " ( 0.267026 , 1.33950000e+00, 1.01891000e-03, 0.0179383 ),\n", - " ( 0.269288 , 1.33759000e+00, 9.71319000e-04, 0.0182463 ),\n", - " ( 0.27155 , 1.37715000e+00, 1.03639000e-03, 0.0184218 ),\n", - " ( 0.273813 , 1.29646000e+00, 1.01499000e-03, 0.0186265 ),\n", - " ( 0.276075 , 1.35901000e+00, 9.89784000e-04, 0.0189069 ),\n", - " ( 0.278338 , 1.27646000e+00, 9.79190000e-04, 0.0190349 ),\n", - " ( 0.2806 , 1.29041000e+00, 1.01598000e-03, 0.0192846 ),\n", - " ( 0.282862 , 1.34233000e+00, 9.72415000e-04, 0.0195668 ),\n", - " ( 0.285125 , 1.30539000e+00, 1.04033000e-03, 0.0196904 ),\n", - " ( 0.287387 , 1.32256000e+00, 1.10708000e-03, 0.019925 ),\n", - " ( 0.28965 , 1.28919000e+00, 1.00851000e-03, 0.0201828 ),\n", - " ( 0.291912 , 1.29895000e+00, 1.08788000e-03, 0.0203732 ),\n", - " ( 0.294174 , 1.31408000e+00, 1.11481000e-03, 0.0206176 ),\n", - " ( 0.296437 , 1.30226000e+00, 1.06193000e-03, 0.0208095 ),\n", - " ( 0.298699 , 1.30589000e+00, 1.17047000e-03, 0.0209943 ),\n", - " ( 0.300962 , 1.29786000e+00, 1.08535000e-03, 0.0213227 ),\n", - " ( 0.303224 , 1.23239000e+00, 1.09345000e-03, 0.021438 ),\n", - " ( 0.305486 , 1.28156000e+00, 1.27915000e-03, 0.0215954 ),\n", - " ( 0.307749 , 1.32796000e+00, 1.20706000e-03, 0.021926 ),\n", - " ( 0.310011 , 1.30217000e+00, 1.29243000e-03, 0.0221265 ),\n", - " ( 0.312274 , 1.22154000e+00, 1.31353000e-03, 0.0222615 ),\n", - " ( 0.314536 , 1.23972000e+00, 1.18866000e-03, 0.0225737 ),\n", - " ( 0.316798 , 1.25601000e+00, 1.34261000e-03, 0.0227181 ),\n", - " ( 0.319061 , 1.30090000e+00, 1.48065000e-03, 0.0229153 ),\n", - " ( 0.321323 , 1.23908000e+00, 1.47062000e-03, 0.0231034 ),\n", - " ( 0.323586 , 1.28162000e+00, 1.58856000e-03, 0.023401 ),\n", - " ( 0.325848 , 1.24657000e+00, 1.61703000e-03, 0.0234885 ),\n", - " ( 0.32811 , 1.29387000e+00, 1.80401000e-03, 0.0237336 ),\n", - " ( 0.330373 , 1.25754000e+00, 1.76106000e-03, 0.0239429 ),\n", - " ( 0.332635 , 1.19356000e+00, 1.73731000e-03, 0.0241586 ),\n", - " ( 0.334898 , 1.26474000e+00, 1.88188000e-03, 0.0244496 ),\n", - " ( 0.33716 , 1.33097000e+00, 2.12157000e-03, 0.0245576 ),\n", - " ( 0.339422 , 1.29467000e+00, 2.12446000e-03, 0.0247861 ),\n", - " ( 0.341685 , 1.23477000e+00, 2.14140000e-03, 0.0250466 ),\n", - " ( 0.343947 , 1.28147000e+00, 2.29357000e-03, 0.0253031 ),\n", - " ( 0.34621 , 1.23232000e+00, 2.23000000e-03, 0.0254372 ),\n", - " ( 0.348472 , 1.25183000e+00, 2.46401000e-03, 0.0256826 ),\n", - " ( 0.350734 , 1.17120000e+00, 2.33285000e-03, 0.0258787 ),\n", - " ( 0.352997 , 1.27463000e+00, 2.69883000e-03, 0.0261788 ),\n", - " ( 0.355259 , 1.25092000e+00, 2.78934000e-03, 0.0263301 ),\n", - " ( 0.357522 , 1.17056000e+00, 2.68148000e-03, 0.0265042 ),\n", - " ( 0.359784 , 1.25435000e+00, 3.12805000e-03, 0.0268127 ),\n", - " ( 0.362046 , 1.18626000e+00, 3.02630000e-03, 0.0269865 ),\n", - " ( 0.364309 , 1.32139000e+00, 3.42370000e-03, 0.027279 ),\n", - " ( 0.366571 , 1.14499000e+00, 3.21330000e-03, 0.027425 ),\n", - " ( 0.368834 , 1.24132000e+00, 3.94092000e-03, 0.0277147 ),\n", - " ( 0.371096 , 1.34991000e+00, 4.20847000e-03, 0.027962 ),\n", - " ( 0.373358 , 1.21190000e+00, 4.16068000e-03, 0.0280234 ),\n", - " ( 0.375621 , 1.28882000e+00, 4.61407000e-03, 0.0283759 ),\n", - " ( 0.377883 , 1.17028000e+00, 4.37559000e-03, 0.0285256 ),\n", - " ( 0.380146 , 1.21848000e+00, 5.11970000e-03, 0.0286588 ),\n", - " ( 0.382408 , 1.16478000e+00, 5.21820000e-03, 0.0289052 ),\n", - " ( 0.38467 , 1.26369000e+00, 6.23799000e-03, 0.0290982 ),\n", - " ( 0.386933 , 1.16811000e+00, 6.31712000e-03, 0.0292588 ),\n", - " ( 0.389195 , 1.19013000e+00, 6.64985000e-03, 0.0295441 ),\n", - " ( 0.391458 , 1.27868000e+00, 7.78585000e-03, 0.029664 ),\n", - " ( 0.39372 , 1.14789000e+00, 7.52957000e-03, 0.0300074 ),\n", - " ( 0.395982 , 1.19087000e+00, 8.64753000e-03, 0.0302353 ),\n", - " ( 0.398245 , 1.23422000e+00, 1.08036000e-02, 0.0303397 ),\n", - " ( 0.400507 , 1.45145000e+00, 1.23926000e-02, 0.0307376 ),\n", - " ( 0.40277 , 1.29427000e+00, 1.34012000e-02, 0.030717 ),\n", - " ( 0.405032 , 1.23035000e+00, 1.40164000e-02, 0.0311565 ),\n", - " ( 0.407294 , 1.21974000e+00, 1.39044000e-02, 0.0313112 ),\n", - " ( 0.409557 , 1.00004000e+00, 1.31590000e-02, 0.0315002 ),\n", - " ( 0.411819 , 1.08915000e+00, 1.69467000e-02, 0.0316693 ),\n", - " ( 0.414082 , 1.22531000e+00, 2.20794000e-02, 0.0318296 ),\n", - " ( 0.416344 , 1.31332000e+00, 2.49976000e-02, 0.031991 ),\n", - " ( 0.418606 , 1.00532000e+00, 2.29697000e-02, 0.032178 ),\n", - " ( 0.420869 , 1.17157000e+00, 3.34778000e-02, 0.0323646 ),\n", - " ( 0.423131 , 1.54398000e+00, 6.62195000e-02, 0.0325359 ),\n", - " ( 0.425394 , 1.02969000e+00, 5.04892000e-02, 0.0326751 ),\n", - " ( 0.427656 , 8.58565000e-01, 4.91425000e-02, 0.0328817 ),\n", - " ( 0.429918 , 8.01629000e-01, 9.18017000e-02, 0.033036 ),\n", - " ( 0.432181 , 1.48946000e+00, 1.70656000e-01, 0.0332177 ),\n", - " ( 0.434443 , 6.87675000e-01, 2.36449000e-01, 0.0333237 ),\n", - " ( 0.436706 , 0.00000000e+00, 0.00000000e+00, 0. ),\n", - " ( 0.438968 , 0.00000000e+00, 0.00000000e+00, 0. ),\n", - " ( 0.44123 , 0.00000000e+00, 0.00000000e+00, 0. ),\n", - " ( 0.443493 , 0.00000000e+00, 0.00000000e+00, 0. ),\n", - " ( 0.445755 , 0.00000000e+00, 0.00000000e+00, 0. ),\n", - " ( 0.448018 , 0.00000000e+00, 0.00000000e+00, 0. ),\n", - " ( 0.45028 , 0.00000000e+00, 0.00000000e+00, 0. ),\n", - " ( 0.452542 , 0.00000000e+00, 0.00000000e+00, 0. )],\n", - " dtype=[('X', '');\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" - }, - { - "data": { - "text/plain": [ - "[]" - ] - }, - "execution_count": 39, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "# Let's label some stuff\n", - "# Simple Labels. Part 3 introduces axes manipulation\n", - "fig, ax = plt.subplots()\n", - "ax.set_title(\"$y = f(x)$\")\n", - "ax.set_xlabel(\"Axis X\")\n", - "ax.set_ylabel(\"Axis y\")\n", - "# Marker symbols: https://matplotlib.org/api/markers_api.html\n", - "ax.plot(data['X'], data['Y'], marker='x', color='red', linestyle='')\n" - ] - }, - { - "cell_type": "code", - "execution_count": 40, - "metadata": {}, - "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" - }, - { - "data": { - "text/plain": [ - "[]" - ] - }, - "execution_count": 41, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "# Log y\n", - "fig, ax = plt.subplots()\n", - "ax.semilogy(data['X'], data['Y'])" - ] - }, - { - "cell_type": "code", - "execution_count": 42, - "metadata": {}, - "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" - }, - { - "data": { - "text/plain": [ - "" - ] - }, - "execution_count": 43, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "## Error bars linear\n", - "fig, ax = plt.subplots()\n", - "ax.errorbar(data['X'], data['Y'], xerr=data['DX'], yerr=data['E'])" - ] - }, - { - "cell_type": "code", - "execution_count": 44, - "metadata": {}, - "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": [ - "# Same plot but let's prone some sata\n", - "fig, ax = plt.subplots()\n", - "ax.errorbar(\n", - " data['X'][2:-10],\n", - " data['Y'][2:-10],\n", - " xerr=data['DX'][2:-10],\n", - " yerr=data['E'][2:-10],\n", - " # fmt = plot format string: '[color][marker][line]'\n", - " # See Notes here: https://matplotlib.org/api/_as_gen/matplotlib.pyplot.plot.html\n", - " fmt='rx',\n", - " ecolor='green',\n", - " capthick=2,\n", - ")\n", - "ax.set_xscale(\"log\", nonposx='clip')\n", - "ax.set_yscale(\"log\", nonposy='clip')\n" - ] - }, - { - "cell_type": "code", - "execution_count": 46, - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "array([False, False, False, False, False, False, False, False, True,\n", - " True, True, True, True, True, True, True, True, True,\n", - " True, True, True, True, True, True, True, True, True,\n", - " True, True, True, True, True, True, True, True, True,\n", - " True, True, True, True, True, True, True, True, True,\n", - " True, True, True, True, True, True, True, True, True,\n", - " True, True, True, True, True, True, True, True, True,\n", - " True, True, True, True, True, True, True, True, True,\n", - " True, True, True, True, True, True, True, True, True,\n", - " True, True, True, True, True, True, True, True, True,\n", - " True, True, True, True, True, True, True, True, True,\n", - " True, True, True, True, True, True, True, True, True,\n", - " True, True, True, True, True, True, True, True, True,\n", - " True, True, True, True, True, True, True, True, True,\n", - " True, True, True, True, True, True, True, True, True,\n", - " True, True, True, True, True, True, True, True, True,\n", - " True, True, True, True, True, True, True, True, True,\n", - " True, True, True, True, True, True, True, True, True,\n", - " True, True, True, True, True, True, True, True, True,\n", - " True, True, True, True, True, True, True, True, True,\n", - " True, True, True, True, True, True, True, True, True,\n", - " True, True, True, True, True, True, True, True, True,\n", - " True, True], dtype=bool)" - ] - }, - "execution_count": 46, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "#let's suppose we want data for Q>0.02\n", - "data_x_subset_bool = data['X']>0.02\n", - "data_x_subset_bool" - ] - }, - { - "cell_type": "code", - "execution_count": 47, - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "array([ 0.020424 , 0.0226864, 0.0249488, 0.0272112, 0.0294736,\n", - " 0.031736 , 0.0339984, 0.0362608, 0.0385232, 0.0407856,\n", - " 0.043048 , 0.0453104, 0.0475728, 0.0498352, 0.0520976,\n", - " 0.05436 , 0.0566224, 0.0588848, 0.0611472, 0.0634096,\n", - " 0.065672 , 0.0679344, 0.0701968, 0.0724592, 0.0747216,\n", - " 0.076984 , 0.0792464, 0.0815088, 0.0837712, 0.0860336,\n", - " 0.088296 , 0.0905584, 0.0928208, 0.0950832, 0.0973456,\n", - " 0.099608 , 0.10187 , 0.104133 , 0.106395 , 0.108658 ,\n", - " 0.11092 , 0.113182 , 0.115445 , 0.117707 , 0.11997 ,\n", - " 0.122232 , 0.124494 , 0.126757 , 0.129019 , 0.131282 ,\n", - " 0.133544 , 0.135806 , 0.138069 , 0.140331 , 0.142594 ,\n", - " 0.144856 , 0.147118 , 0.149381 , 0.151643 , 0.153906 ,\n", - " 0.156168 , 0.15843 , 0.160693 , 0.162955 , 0.165218 ,\n", - " 0.16748 , 0.169742 , 0.172005 , 0.174267 , 0.17653 ,\n", - " 0.178792 , 0.181054 , 0.183317 , 0.185579 , 0.187842 ,\n", - " 0.190104 , 0.192366 , 0.194629 , 0.196891 , 0.199154 ,\n", - " 0.201416 , 0.203678 , 0.205941 , 0.208203 , 0.210466 ,\n", - " 0.212728 , 0.21499 , 0.217253 , 0.219515 , 0.221778 ,\n", - " 0.22404 , 0.226302 , 0.228565 , 0.230827 , 0.23309 ,\n", - " 0.235352 , 0.237614 , 0.239877 , 0.242139 , 0.244402 ,\n", - " 0.246664 , 0.248926 , 0.251189 , 0.253451 , 0.255714 ,\n", - " 0.257976 , 0.260238 , 0.262501 , 0.264763 , 0.267026 ,\n", - " 0.269288 , 0.27155 , 0.273813 , 0.276075 , 0.278338 ,\n", - " 0.2806 , 0.282862 , 0.285125 , 0.287387 , 0.28965 ,\n", - " 0.291912 , 0.294174 , 0.296437 , 0.298699 , 0.300962 ,\n", - " 0.303224 , 0.305486 , 0.307749 , 0.310011 , 0.312274 ,\n", - " 0.314536 , 0.316798 , 0.319061 , 0.321323 , 0.323586 ,\n", - " 0.325848 , 0.32811 , 0.330373 , 0.332635 , 0.334898 ,\n", - " 0.33716 , 0.339422 , 0.341685 , 0.343947 , 0.34621 ,\n", - " 0.348472 , 0.350734 , 0.352997 , 0.355259 , 0.357522 ,\n", - " 0.359784 , 0.362046 , 0.364309 , 0.366571 , 0.368834 ,\n", - " 0.371096 , 0.373358 , 0.375621 , 0.377883 , 0.380146 ,\n", - " 0.382408 , 0.38467 , 0.386933 , 0.389195 , 0.391458 ,\n", - " 0.39372 , 0.395982 , 0.398245 , 0.400507 , 0.40277 ,\n", - " 0.405032 , 0.407294 , 0.409557 , 0.411819 , 0.414082 ,\n", - " 0.416344 , 0.418606 , 0.420869 , 0.423131 , 0.425394 ,\n", - " 0.427656 , 0.429918 , 0.432181 , 0.434443 , 0.436706 ,\n", - " 0.438968 , 0.44123 , 0.443493 , 0.445755 , 0.448018 ,\n", - " 0.45028 , 0.452542 ])" - ] - }, - "execution_count": 47, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "data['X'][data_x_subset_bool]" - ] - }, - { - "cell_type": "code", - "execution_count": 48, - "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "Original length = 200 :: Subset length = 192.\n" - ] - } - ], - "source": [ - "# Note the print statetement order of values!\n", - "print(\"Original length = {1} :: Subset length = {0}.\".format(\n", - " len(data['X'][data_x_subset_bool]),\n", - " len(data['X']),\n", - "))" - ] - }, - { - "cell_type": "code", - "execution_count": 49, - "metadata": {}, - "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" - }, - { - "data": { - "text/plain": [ - "[]" - ] - }, - "execution_count": 52, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "fig, ax = plt.subplots()\n", - "ax.plot(data['X'], y_new)" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "### Adding the new array to the dataset" - ] - }, - { - "cell_type": "code", - "execution_count": 53, - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "('X', 'Y', 'E', 'DX', 'new')" - ] - }, - "execution_count": 53, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "# Adding y_new to the file??\n", - "from numpy.lib import recfunctions\n", - "data_new = recfunctions.append_fields(data, 'new', y_new)\n", - "data_new.dtype.names" - ] - }, - { - "cell_type": "code", - "execution_count": 54, - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "'X , Y , E , DX , new'" - ] - }, - "execution_count": 54, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "'''\n", - "Remember the original file header:\n", - "\n", - "# X , Y , E , DX\n", - "1\n", - "\n", - "'''\n", - "\n", - "header = data_new.dtype.names\n", - "# join: joins a list into string\n", - "header_str = \" , \".join(header)\n", - "header_str" - ] - }, - { - "cell_type": "code", - "execution_count": 55, - "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "# X , Y , E , DX , new\n", - "1\n" - ] - } - ], - "source": [ - "header_str = \"# \" + header_str + \"\\n1\"\n", - "print(header_str)" - ] - }, - { - "cell_type": "code", - "execution_count": 56, - "metadata": {}, - "outputs": [], - "source": [ - "# Note that Jupyter hub only allows writing files to our home directory!\n", - "out_filepath = '/SNS/users/rhf/tmp/foo.txt'\n", - "\n", - "np.savetxt(\n", - " out_filepath,\n", - " data_new,\n", - " delimiter=\",\",\n", - " fmt='%.2f',\n", - " header=header_str,\n", - " comments='',\n", - ")" - ] - }, - { - "cell_type": "code", - "execution_count": 57, - "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "# X , Y , E , DX , new\r\n", - "1\r\n", - "0.00,8.23,0.68,0.00,1.02\r\n", - "0.00,5.89,0.19,0.00,1.05\r\n", - "0.01,12.57,0.41,0.00,1.07\r\n", - "0.01,37.32,0.77,0.00,1.10\r\n", - "0.01,156.67,2.59,0.00,1.12\r\n", - "0.01,567.55,11.78,0.00,1.15\r\n", - "0.02,1401.89,16.10,0.00,1.17\r\n", - "0.02,1334.20,13.47,0.00,1.20\r\n" - ] - } - ], - "source": [ - "!head /SNS/users/rhf/tmp/foo.txt" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "# Advanced Plotting" - ] - }, - { - "cell_type": "code", - "execution_count": 58, - "metadata": {}, - "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" - }, - { - "data": { - "text/plain": [ - "Text(0.5,0.98,'Annotated Plot')" - ] - }, - "execution_count": 59, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "fig, ax = plt.subplots() # create figure and axes\n", - "ax.plot(data_new['X'], data_new['Y'], color='red')\n", - "ax.set_xticks([0.001, 0.2, 0.4])\n", - "ax.set_xticklabels(['low', 'med', 'high'])\n", - "# https://matplotlib.org/users/annotations.html\n", - "ax.annotate(\n", - " 'This is the maximum!', \n", - " xy=(0.025, 1620), # Coordinate where the head is \n", - " xytext=(0.1, 1000), # Coordinate where the text starts\n", - " arrowprops={}, # This is an empty dictionary! More details in the Fitting Notebook\n", - ")\n", - "fig.suptitle('Annotated Plot', fontsize=20, color='red')" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [] - } - ], - "metadata": { - "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.2" - } - }, - "nbformat": 4, - "nbformat_minor": 2 -}