NUNEZ Arturo committed Jul 19, 2018 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 ``````{ "cells": [ { "cell_type": "code", "execution_count": 1, "metadata": { "collapsed": false, "hide_input": false }, "outputs": [], "source": [ "%matplotlib notebook\n", "%load_ext autoreload\n", "%autoreload 2" ] }, { "cell_type": "code", "execution_count": 2, "metadata": { "collapsed": false, "hide_input": false }, "outputs": [], "source": [ "\n", "from scipy.stats import rv_continuous\n", "from scipy.interpolate import interp1d\n", "from matplotlib.patches import Circle\n", "from scipy.special import gamma\n", "import numpy as np\n", "import emcee\n", "from mpl_toolkits.axes_grid1 import make_axes_locatable\n", "from numpy import exp, sqrt\n", "from scipy.integrate import quad, dblquad, nquad\n", "import matplotlib.patches as patches\n", "from itertools import product\n", "from scipy.integrate import quad\n", "import scipy.optimize as optimize\n", "import matplotlib.pyplot as plt\n", "import matplotlib as mpl\n", "from sklearn.neighbors import KDTree\n", "import sys\n", "import lmfit\n", "from py_unsio import *\n", "import pymc\n", "import os\n", "from pymodelfit import FunctionModel1DAuto\n", "import wkbl\n", "from wkbl.astro.halo_info import *\n", "from mpl_toolkits.mplot3d import axes3d\n", "from matplotlib import cm\n", "import wkbl.astro.nbody_essentials as nbe\n", "import cfalcon\n", "CF =cfalcon.CFalcon()\n", "import iminuit\n", "from iminuit import Minuit, describe, Struct\n", "import probfit\n", "from matplotlib.colors import LogNorm\n", "from matplotlib.ticker import FormatStrFormatter\n", "import warnings\n", "warnings.filterwarnings('ignore')" ] }, { "cell_type": "code", `````` NUNEZ Arturo committed Aug 01, 2018 67 `````` "execution_count": 4, `````` NUNEZ Arturo committed Jul 19, 2018 68 69 70 71 72 73 74 75 76 77 78 79 `````` "metadata": { "collapsed": false, "hide_input": false, "scrolled": true }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "loading Dark matter..\n", "loading Stars..\n", `````` NUNEZ Arturo committed Aug 01, 2018 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 `````` "loading Gas..\n" ] }, { "ename": "LinAlgError", "evalue": "Array must not contain infs or NaNs", "output_type": "error", "traceback": [ "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", "\u001b[0;31mLinAlgError\u001b[0m Traceback (most recent call last)", "\u001b[0;32m\u001b[0m in \u001b[0;36m\u001b[0;34m()\u001b[0m\n\u001b[1;32m 2\u001b[0m \u001b[0mmyhydro\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mwkbl\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mGalaxy_Hound\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mhydro\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mpath\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 3\u001b[0m \u001b[0mmyhydro\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mcenter_shift\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mhydro\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mc_dm_com\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m----> 4\u001b[0;31m \u001b[0mmyhydro\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mr_virial\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;36m600\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0mn\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0;36m2.5\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m", "\u001b[0;32m/home/arturo/Documents/git/WKBL/wkbl/astro/galaxy_peeker.pyc\u001b[0m in \u001b[0;36mr_virial\u001b[0;34m(self, r_max, r_min, rotate, n, bins, quiet)\u001b[0m\n\u001b[1;32m 82\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 83\u001b[0m \u001b[0;32mif\u001b[0m \u001b[0;34m(\u001b[0m\u001b[0mrotate\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;32mand\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0m_sts\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m---> 84\u001b[0;31m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mrotate_galaxy\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 85\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mredefine\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mn\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 86\u001b[0m \u001b[0mD\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mnp\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mdot\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mmatrix_T\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0mnp\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mdot\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mmatrix_P\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0mnp\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mtranspose\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mmatrix_T\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", "\u001b[0;32m/home/arturo/Documents/git/WKBL/wkbl/astro/galaxy_peeker.pyc\u001b[0m in \u001b[0;36mrotate_galaxy\u001b[0;34m(self, rmin, rmax)\u001b[0m\n\u001b[1;32m 120\u001b[0m \u001b[0msecond\u001b[0m \u001b[0;34m=\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mnp\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0maverage\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mpos_ring\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0mi\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m*\u001b[0m\u001b[0mnp\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0maverage\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mpos_ring\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0mj\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 121\u001b[0m \u001b[0mP\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0mi\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0mj\u001b[0m\u001b[0;34m]\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mfirst\u001b[0m \u001b[0;34m-\u001b[0m \u001b[0msecond\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 122\u001b[0;31m \u001b[0meigen_values\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0mevecs\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mnp\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mlinalg\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0meig\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mP\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 123\u001b[0m \u001b[0morder\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mnp\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0margsort\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mabs\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0meigen_values\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 124\u001b[0m \u001b[0mT\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mnp\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mzeros\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;36m3\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;36m3\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", "\u001b[0;32m/usr/local/lib/python2.7/dist-packages/numpy/linalg/linalg.pyc\u001b[0m in \u001b[0;36meig\u001b[0;34m(a)\u001b[0m\n\u001b[1;32m 1141\u001b[0m \u001b[0m_assertRankAtLeast2\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0ma\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 1142\u001b[0m \u001b[0m_assertNdSquareness\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0ma\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m-> 1143\u001b[0;31m \u001b[0m_assertFinite\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0ma\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 1144\u001b[0m \u001b[0mt\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mresult_t\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0m_commonType\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0ma\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 1145\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n", "\u001b[0;32m/usr/local/lib/python2.7/dist-packages/numpy/linalg/linalg.pyc\u001b[0m in \u001b[0;36m_assertFinite\u001b[0;34m(*arrays)\u001b[0m\n\u001b[1;32m 214\u001b[0m \u001b[0;32mfor\u001b[0m \u001b[0ma\u001b[0m \u001b[0;32min\u001b[0m \u001b[0marrays\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 215\u001b[0m \u001b[0;32mif\u001b[0m \u001b[0;32mnot\u001b[0m \u001b[0;34m(\u001b[0m\u001b[0misfinite\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0ma\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mall\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 216\u001b[0;31m \u001b[0;32mraise\u001b[0m \u001b[0mLinAlgError\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m\"Array must not contain infs or NaNs\"\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 217\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 218\u001b[0m \u001b[0;32mdef\u001b[0m \u001b[0m_isEmpty2d\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0marr\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", "\u001b[0;31mLinAlgError\u001b[0m: Array must not contain infs or NaNs" `````` NUNEZ Arturo committed Jul 19, 2018 96 97 98 99 `````` ] } ], "source": [ `````` NUNEZ Arturo committed Jul 20, 2018 100 101 102 `````` "hydro = wkbl.astro.halo_info.AdicoraHydro() \n", "myhydro = wkbl.Galaxy_Hound(hydro.path)\n", "myhydro.center_shift(hydro.c_dm_com)\n", `````` NUNEZ Arturo committed Aug 01, 2018 103 `````` "myhydro.r_virial(600,n=2.5)\n" `````` NUNEZ Arturo committed Jul 19, 2018 104 105 106 107 `````` ] }, { "cell_type": "code", `````` NUNEZ Arturo committed Aug 01, 2018 108 `````` "execution_count": null, `````` NUNEZ Arturo committed Jul 20, 2018 109 110 111 `````` "metadata": { "collapsed": false }, `````` NUNEZ Arturo committed Aug 01, 2018 112 `````` "outputs": [], `````` NUNEZ Arturo committed Jul 20, 2018 113 114 115 116 117 118 119 `````` "source": [ "print hydro.path\n", "print hydro.c_dm_com" ] }, { "cell_type": "code", `````` NUNEZ Arturo committed Aug 01, 2018 120 `````` "execution_count": null, `````` NUNEZ Arturo committed Jul 19, 2018 121 122 123 124 125 `````` "metadata": { "collapsed": true }, "outputs": [], "source": [ `````` NUNEZ Arturo committed Jul 20, 2018 126 `````` "simname = hydro.name\n", `````` NUNEZ Arturo committed Jul 19, 2018 127 128 129 130 131 132 133 134 135 `````` "simname_nospace = list(simname)\n", "for i in range(len(simname)):\n", " if simname[i]==\" \":\n", " simname_nospace[i]=\"_\"\n", "simname_nospace = \"\".join(simname_nospace)\n" ] }, { "cell_type": "code", `````` NUNEZ Arturo committed Aug 01, 2018 136 `````` "execution_count": null, `````` NUNEZ Arturo committed Jul 19, 2018 137 138 139 140 `````` "metadata": { "collapsed": false, "scrolled": true }, `````` NUNEZ Arturo committed Aug 01, 2018 141 `````` "outputs": [], `````` NUNEZ Arturo committed Jul 19, 2018 142 143 144 145 146 147 148 149 `````` "source": [ "print \"{0:.3e}\".format(np.sum(myhydro.dm.mass[myhydro.dm.rmyhydro.r200))].max()\n", "#myneighbourg = myhydro.dm.pos3d[np.where(myhydro.dm.rho==neighbourg)][0]\n", "supershell = np.where((r2>(3*myhydro.r200)**2))\n", "neighbourg = Phy[supershell].min()\n", "possupershell = pos3d[supershell]\n", "myneighbourg = possupershell[np.where(Phy[supershell]==neighbourg)][0]\n", "# its radius squared\n", "r_nei2 = myneighbourg[0]**2 + myneighbourg[1]**2 + myneighbourg[2]**2\n", "phi_neigh = np.arctan2(myneighbourg[1],myneighbourg[0])\n", "print np.sqrt(r_nei2)\n", "the_neigh = np.arccos(myneighbourg[0]/np.sqrt(r_nei2))\n", "\n", "\n", "# distance to every point proyected to the line conecting center to neigblourg \n", "adyacent = (pos3d[:,0]*myneighbourg[0] + pos3d[:,1]*myneighbourg[1] + pos3d[:,2]*myneighbourg[2]) / np.sqrt(r_nei2)\n", "# distance to each point\n", "hipoteneuse = np.sqrt(pos3d[:,0]**2 + pos3d[:,1]**2 + pos3d[:,2]**2)\n", "# angle of cone\n", "alpha = np.radians(3)\n", "cos_alpha = np.cos(alpha)\n", "# cosine of all particles respective to their angle to the l.o.s\n", "cos_all = adyacent / hipoteneuse \n", "# final selection of cone\n", "my_cone = pos3d[np.where((cos_all)>cos_alpha)]" ] }, { "cell_type": "code", `````` NUNEZ Arturo committed Jul 20, 2018 271 `````` "execution_count": 12, `````` NUNEZ Arturo committed Jul 19, 2018 272 273 274 275 276 277 278 279 280 `````` "metadata": { "collapsed": false, "hide_input": false }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ `````` NUNEZ Arturo committed Jul 20, 2018 281 282 `````` "the biggest neighbourg has a mass of 1.0509e+11 Msun and a r200 of 101.6018 kpc\n", "and it is located at 3853.3405 kpc from de center of our halo \n" `````` NUNEZ Arturo committed Jul 19, 2018 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 `````` ] } ], "source": [ "# radii from center of neighbour\n", "r_neig = np.sqrt((pos3d[:,0] - myneighbourg[0])**2 +(pos3d[:,1] - myneighbourg[1])**2 +(pos3d[:,2] - myneighbourg[2])**2 )\n", "# calculating the R200 of neighbout\n", "mhist, rhist = np.histogram(r_neig,range=(0.0,np.sqrt(r_nei2)),bins=512, weights=mass )\n", "vol_bin = (4./3.)*np.pi*(rhist[:-1]**3)\n", "r_bin = rhist[:-1]+ 0.5*(rhist[2]-rhist[1])\n", "rho_s = np.cumsum(mhist) / vol_bin\n", "r200_neigh = r_bin[np.argmin(np.abs(rho_s - (200 * myhydro.p.rho_crit)))]\n", "# mass of neighbour\n", "mass_neigh = np.sum(mass[np.where(r_neigcos_alpha)\n", "cone_pos = my_cone\n", "cone_mass = mass[los_condition]\n", "cone_Phy = Phy[los_condition]\n", "cone_r2 = my_cone[:,0]**2 + my_cone[:,1]**2 + my_cone[:,2]**2\n", "# now the histogram\n", "bin_num = 1000\n", "pot_los, bins_pot_los = np.histogram(cone_r2,bins=bin_num,\n", " weights=cone_Phy)\n", "n_los, _ = np.histogram(cone_r2,bins=bin_num)\n" ] }, { "cell_type": "code", `````` NUNEZ Arturo committed Jul 20, 2018 324 `````` "execution_count": 14, `````` NUNEZ Arturo committed Jul 19, 2018 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 `````` "metadata": { "collapsed": false }, "outputs": [], "source": [ "#a proyection Story\n", "th,ph,ep = the_neigh, phi_neigh, -3*np.pi/4.\n", "Ct, Cp, Ce = np.cos(th),np.cos(ph), np.cos(ep)\n", "St, Sp, Se = np.sin(th),np.sin(ph), np.sin(ep)\n", "#the rotation matrix\n", "rot = np.array([[(Ce*Ct*Cp)+(Se*Sp),(Ce*Ct*Sp)-(Se*Cp),Ce*St],\\\n", " [(Se*Ct*Cp)-(Ce*Sp),(Se*Ct*Sp)+(Ce*Cp),Se*St],\\\n", " [-Cp*St,-St*Sp,Ct]])\n", "cone_prox = rot[0,0]*cone_pos[:,0]+rot[0,1]*cone_pos[:,1]+rot[0,2]*cone_pos[:,2]\n", "cone_proy = rot[1,0]*cone_pos[:,0]+rot[1,1]*cone_pos[:,1]+rot[1,2]*cone_pos[:,2]\n", "neig_prox = rot[0,0]*myneighbourg[0]+rot[0,1]*myneighbourg[1]+rot[0,2]*myneighbourg[2]\n", "neig_proy = rot[1,0]*myneighbourg[0]+rot[1,1]*myneighbourg[1]+rot[1,2]*myneighbourg[2]" ] }, { "cell_type": "code", `````` NUNEZ Arturo committed Jul 20, 2018 346 `````` "execution_count": 15, `````` NUNEZ Arturo committed Jul 19, 2018 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 `````` "metadata": { "collapsed": true, "hide_input": false }, "outputs": [], "source": [ "bins_pot_los = np.linspace(0.,myhydro.dm.r.max(),512)\n", "mean_phi_los = np.array([])\n", "std_phi_los = np.array([])\n", "r_phi_los = np.array([])\n", "for i in range(len(bins_pot_los)-1):\n", " contidion = (cone_r2>bins_pot_los[i]**2)&(cone_r2');\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", " 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", " this.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 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": [ `````` NUNEZ Arturo committed Jul 20, 2018 2252 `````` "" `````` NUNEZ Arturo committed Jul 19, 2018 2253 2254 2255 2256 2257 2258 2259 2260 2261 2262 2263 2264 `````` ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "name": "stdout", "output_type": "stream", "text": [ ``````