├── Figure.PNG ├── Links.txt ├── Project Figure.PNG ├── .gitattributes ├── README.md ├── loan application.csv ├── total loans.csv └── Assignment3_A.ipynb /Figure.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ashwinpn/Applied-Data-Science-with-Python-Specialization-University-of-Michigan/HEAD/Figure.PNG -------------------------------------------------------------------------------- /Links.txt: -------------------------------------------------------------------------------- 1 | Link 1: https://data.gov.sg/dataset/application-with-bank-loan 2 | Link 2: https://data.gov.sg/dataset/total-loans-to-non-bank-customers -------------------------------------------------------------------------------- /Project Figure.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ashwinpn/Applied-Data-Science-with-Python-Specialization-University-of-Michigan/HEAD/Project Figure.PNG -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | # Auto detect text files and perform LF normalization 2 | * text=auto 3 | 4 | # Custom for Visual Studio 5 | *.cs diff=csharp 6 | 7 | # Standard to msysgit 8 | *.doc diff=astextplain 9 | *.DOC diff=astextplain 10 | *.docx diff=astextplain 11 | *.DOCX diff=astextplain 12 | *.dot diff=astextplain 13 | *.DOT diff=astextplain 14 | *.pdf diff=astextplain 15 | *.PDF diff=astextplain 16 | *.rtf diff=astextplain 17 | *.RTF diff=astextplain 18 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Applied-Data-Science-with-Python-Specialization 2 | 3 | This repository will contain assignments and other self study material pertaining to the University of Michigan's Applied Data Science with Python Specialiation, which consists of the following courses: 4 | 5 | - [ ] Introduction to Data Science in Python. 6 | - [x] Applied Plotting, Charting & Data Representation in Python. 7 | - [ ] Applied Machine Learning in Python. 8 | - [ ] Applied Text Mining in Python. 9 | - [ ] Applied Social Network Analysis in Python 10 | 11 | 12 | Currently consists of the second course, namely Applied Plotting, Charting & Data Representation in Python. 13 | 14 | 15 | The official page: [https://www.coursera.org/specializations/data-science-python](https://www.coursera.org/specializations/data-science-python). 16 | -------------------------------------------------------------------------------- /loan application.csv: -------------------------------------------------------------------------------- 1 | financial_year,category,no_of_applications 2 | 2006,Resale Flat Buyers,11266 3 | 2006,Flats Sold,1216 4 | 2006,Existing Flat Owners (Refinance),16 5 | 2006,DBSS Flat Buyers,0 6 | 2007,Resale Flat Buyers,14759 7 | 2007,Flats Sold,1622 8 | 2007,Existing Flat Owners (Refinance),8 9 | 2007,DBSS Flat Buyers,0 10 | 2008,Resale Flat Buyers,14913 11 | 2008,Flats Sold,936 12 | 2008,Existing Flat Owners (Refinance),42 13 | 2008,DBSS Flat Buyers,0 14 | 2009,Resale Flat Buyers,22345 15 | 2009,Flats Sold,948 16 | 2009,Existing Flat Owners (Refinance),101 17 | 2009,DBSS Flat Buyers,0 18 | 2010,Resale Flat Buyers,17990 19 | 2010,Flats Sold,868 20 | 2010,Existing Flat Owners (Refinance),329 21 | 2010,DBSS Flat Buyers,0 22 | 2011,Resale Flat Buyers,15039 23 | 2011,Flats Sold,2402 24 | 2011,Existing Flat Owners (Refinance),548 25 | 2011,DBSS Flat Buyers,0 26 | 2012,Resale Flat Buyers,15529 27 | 2012,Flats Sold,2219 28 | 2012,Existing Flat Owners (Refinance),611 29 | 2012,DBSS Flat Buyers,1017 30 | 2013,Resale Flat Buyers,9213 31 | 2013,Flats Sold,2474 32 | 2013,Existing Flat Owners (Refinance),1399 33 | 2013,DBSS Flat Buyers,244 34 | 2014,Resale Flat Buyers,9318 35 | 2014,Flats Sold,2122 36 | 2014,Existing Flat Owners (Refinance),578 37 | 2014,DBSS Flat Buyers,121 38 | 2015,Resale Flat Buyers,8211 39 | 2015,Flats Sold,1730 40 | 2015,Existing Flat Owners (Refinance),156 41 | 2015,DBSS Flat Buyers,44 42 | -------------------------------------------------------------------------------- /total loans.csv: -------------------------------------------------------------------------------- 1 | month,total_loans,total_loans_business,total_loans_consumer 2 | 2004-03,293816.4,195720,98096.1 3 | 2004-04,295409,196774.5,98634.3 4 | 2004-05,298744.2,199022.1,99722.4 5 | 2004-06,300945.9,199974.2,100971.5 6 | 2004-07,303484,202125,101358.6 7 | 2004-08,307157.9,204586.1,102571.8 8 | 2004-09,305887.8,202489.4,103398.2 9 | 2004-10,308808.8,205231.8,103577.1 10 | 2004-11,311607.4,207817.9,103789.6 11 | 2004-12,312821.9,208589.1,104232.8 12 | 2005-01,313487.2,208137.4,105349.9 13 | 2005-02,312352.8,207506,104846.7 14 | 2005-03,311647.6,205819.6,105828.1 15 | 2005-04,316242.6,209585.5,106657 16 | 2005-05,319081,211696,107385 17 | 2005-06,323291,215594.7,107696.4 18 | 2005-07,322161.7,215423.5,106738.2 19 | 2005-08,328967.1,221537.8,107429.1 20 | 2005-09,331973.8,223982.7,107991 21 | 2005-10,332386.9,223918.6,108468.2 22 | 2005-11,352971.7,243345.3,109626.5 23 | 2005-12,357149.1,247525.9,109623.5 24 | 2006-01,353612.1,244419.8,109192.3 25 | 2006-02,355705.5,246357.8,109347.8 26 | 2006-03,346493.4,237418.3,109075.3 27 | 2006-04,358706.8,249677,109029.5 28 | 2006-05,366617.3,256704.2,109913 29 | 2006-06,369857.7,259972.3,109885.5 30 | 2006-07,372792.4,262997,109795.4 31 | 2006-08,373181.7,263348.3,109833.3 32 | 2006-09,377293.6,267117.8,110175.8 33 | 2006-10,380367,270489.1,109878.1 34 | 2006-11,387622.7,276615.7,111007.1 35 | 2006-12,380221,269162.2,111058.8 36 | 2007-01,383810.4,272562.5,111247.8 37 | 2007-02,390473.1,278520.6,111952.6 38 | 2007-03,398472.9,285493.8,112979 39 | 2007-04,403733.7,289187.8,114546 40 | 2007-05,418024.2,302907.2,115116.9 41 | 2007-06,429800,312017.3,117783 42 | 2007-07,434019.2,314869.4,119149.9 43 | 2007-08,447157.4,326150.9,121006.3 44 | 2007-09,458090.4,333633.1,124457.3 45 | 2007-10,461573.6,335093.8,126479.6 46 | 2007-11,473609.6,344694.2,128915.5 47 | 2007-12,489865.9,361621.7,128244.5 48 | 2008-01,497961.4,368501.6,129459.8 49 | 2008-02,512545.7,374175.4,138370.3 50 | 2008-03,530995.1,390848.9,140146.3 51 | 2008-04,535024.2,395918.2,139105.8 52 | 2008-05,545436.5,403428.9,142007.6 53 | 2008-06,561313,415641.9,145671.2 54 | 2008-07,573916.1,426964.3,146951.6 55 | 2008-08,585966.7,437023.6,148943 56 | 2008-09,593357.5,443103.9,150253.5 57 | 2008-10,590038.3,444033.1,146005.2 58 | 2008-11,577670.2,433297.3,144373 59 | 2008-12,558268.7,414789.3,143479.2 60 | 2009-01,566982.4,422762,144220.6 61 | 2009-02,566541.5,422731.6,143810.1 62 | 2009-03,558623.1,415291.5,143331.9 63 | 2009-04,550122.9,407855.9,142267.4 64 | 2009-05,550318.3,407063.7,143254.7 65 | 2009-06,553555,407560,145994.9 66 | 2009-07,551385,404113.7,147271.3 67 | 2009-08,555609.7,406852.8,148757 68 | 2009-09,553900.2,403610.4,150289.5 69 | 2009-10,550049.6,397629,152420.4 70 | 2009-11,559165.4,404675.7,154489.4 71 | 2009-12,564960.7,409450.2,155510.6 72 | 2010-01,569667.6,412698.1,156969.6 73 | 2010-02,573793.7,415480.9,158312.8 74 | 2010-03,580768.4,421627.4,159141.1 75 | 2010-04,585243.1,425165.3,160077.7 76 | 2010-05,597600.9,434218.2,163382.9 77 | 2010-06,616059.6,449302.3,166757.3 78 | 2010-07,614488.9,444880.9,169608 79 | 2010-08,617646.7,445670.9,171976 80 | 2010-09,619893.3,445330.5,174563 81 | 2010-10,625538,447792.6,177745.4 82 | 2010-11,637828.7,457140.4,180688.3 83 | 2010-12,641055.8,458534.6,182521.2 84 | 2011-01,656548.8,473620.7,182928.2 85 | 2011-02,663660.4,479025,184635.5 86 | 2011-03,674217.6,487363.3,186854.1 87 | 2011-04,680163.1,491646.5,188516.6 88 | 2011-05,695729.5,503863.7,191865.5 89 | 2011-06,707152.9,512462,194690.8 90 | 2011-07,719221.5,522428.2,196793.3 91 | 2011-08,737629.7,538272.5,199357.1 92 | 2011-09,777712.1,573923.1,203789 93 | 2011-10,763796.1,560967.8,202828.1 94 | 2011-11,788361.1,581718.7,206642.6 95 | 2011-12,796447.2,584824.4,211622.7 96 | 2012-01,787313.5,574823.4,212489.9 97 | 2012-02,796810.5,583184.7,213625.8 98 | 2012-03,809866.4,593294.9,216571.5 99 | 2012-04,807458.1,589328.7,218129.5 100 | 2012-05,829376,607821.3,221554.9 101 | 2012-06,837481.5,613382.5,224099.1 102 | 2012-07,836723.3,609453.2,227270 103 | 2012-08,852322,621959.3,230362.7 104 | 2012-09,852968.4,619908.4,233059.9 105 | 2012-10,860873.6,624248,236625.5 106 | 2012-11,866807,626906.3,239900.7 107 | 2012-12,879193.3,637176.4,242016.9 108 | 2013-01,905815.5,660368.3,245447.3 109 | 2013-02,916896.9,669980.9,246915.9 110 | 2013-03,933822.2,684507.4,249315 111 | 2013-04,940124.2,689650.3,250473.8 112 | 2013-05,960483.9,707055,253428.7 113 | 2013-06,963923.1,708444.4,255478.7 114 | 2013-07,972573.2,715625.8,256947.2 115 | 2013-08,979777.4,721030.2,258747.1 116 | 2013-09,992822.8,730989.6,261833.2 117 | 2013-10,1002791.5,736474.5,266316.9 118 | 2013-11,1034642.1,763001.6,271640.5 119 | 2013-12,1052149.7,779096.8,273053 120 | 2014-01,1070639.7,795370.9,275269 121 | 2014-02,1080737.2,804138.9,276598.4 122 | 2014-03,1095777.3,814049,281728.2 123 | 2014-04,1103553.3,820361.4,283192 124 | 2014-05,1113250.8,828846.1,284404.8 125 | 2014-06,1122718.7,836092.5,286626.3 126 | 2014-07,1121789.2,833971.4,287817.8 127 | 2014-08,1125901.4,836880,289021.3 128 | 2014-09,1131843.6,840663.7,291179.7 129 | 2014-10,1132664.3,840755.8,291908.7 130 | 2014-11,1148017.7,854424.3,293593.2 131 | 2014-12,1148900.8,853695,295205.7 132 | 2015-01,1161121.2,863537.1,297584.2 133 | 2015-02,1161637.4,863255.1,298382.4 134 | 2015-03,1169159.1,869670.5,299488.3 135 | 2015-04,1143509.7,847142,296367.8 136 | 2015-05,1152705.7,855213.4,297492.1 137 | 2015-06,1161327.6,860843.1,300484.6 138 | 2015-07,1171788.1,869535.7,302252.6 139 | 2015-08,1188388,884782.4,303605.8 -------------------------------------------------------------------------------- /Assignment3_A.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "# Assignment 3 - Building a Custom Visualization\n", 8 | "\n", 9 | "---\n", 10 | "\n", 11 | "In this assignment you must choose one of the options presented below and submit a visual as well as your source code for peer grading. The details of how you solve the assignment are up to you, although your assignment must use matplotlib so that your peers can evaluate your work. The options differ in challenge level, but there are no grades associated with the challenge level you chose. However, your peers will be asked to ensure you at least met a minimum quality for a given technique in order to pass. Implement the technique fully (or exceed it!) and you should be able to earn full grades for the assignment.\n", 12 | "\n", 13 | "\n", 14 | "      Ferreira, N., Fisher, D., & Konig, A. C. (2014, April). [Sample-oriented task-driven visualizations: allowing users to make better, more confident decisions.](https://www.microsoft.com/en-us/research/wp-content/uploads/2016/02/Ferreira_Fisher_Sample_Oriented_Tasks.pdf) \n", 15 | "      In Proceedings of the SIGCHI Conference on Human Factors in Computing Systems (pp. 571-580). ACM. ([video](https://www.youtube.com/watch?v=BI7GAs-va-Q))\n", 16 | "\n", 17 | "\n", 18 | "In this [paper](https://www.microsoft.com/en-us/research/wp-content/uploads/2016/02/Ferreira_Fisher_Sample_Oriented_Tasks.pdf) the authors describe the challenges users face when trying to make judgements about probabilistic data generated through samples. As an example, they look at a bar chart of four years of data (replicated below in Figure 1). Each year has a y-axis value, which is derived from a sample of a larger dataset. For instance, the first value might be the number votes in a given district or riding for 1992, with the average being around 33,000. On top of this is plotted the confidence interval -- the range of the number of votes which encapsulates 95% of the data (see the boxplot lectures for more information, and the yerr parameter of barcharts).\n", 19 | "\n", 20 | "
\n", 21 | "\"Figure\n", 22 | "

        Figure 1 from (Ferreira et al, 2014).

\n", 23 | "\n", 24 | "
\n", 25 | "\n", 26 | "A challenge that users face is that, for a given y-axis value (e.g. 42,000), it is difficult to know which x-axis values are most likely to be representative, because the confidence levels overlap and their distributions are different (the lengths of the confidence interval bars are unequal). One of the solutions the authors propose for this problem (Figure 2c) is to allow users to indicate the y-axis value of interest (e.g. 42,000) and then draw a horizontal line and color bars based on this value. So bars might be colored red if they are definitely above this value (given the confidence interval), blue if they are definitely below this value, or white if they contain this value.\n", 27 | "\n", 28 | "\n", 29 | "
\n", 30 | "\"Figure\n", 31 | "

Figure 2c from (Ferreira et al. 2014). Note that the colorbar legend at the bottom as well as the arrows are not required in the assignment descriptions below.

\n", 32 | "\n", 33 | "
\n", 34 | "
\n", 35 | "\n", 36 | "**Easiest option:** Implement the bar coloring as described above - a color scale with only three colors, (e.g. blue, white, and red). Assume the user provides the y axis value of interest as a parameter or variable.\n", 37 | "\n", 38 | "\n", 39 | "**Harder option:** Implement the bar coloring as described in the paper, where the color of the bar is actually based on the amount of data covered (e.g. a gradient ranging from dark blue for the distribution being certainly below this y-axis, to white if the value is certainly contained, to dark red if the value is certainly not contained as the distribution is above the axis).\n", 40 | "\n", 41 | "**Even Harder option:** Add interactivity to the above, which allows the user to click on the y axis to set the value of interest. The bar colors should change with respect to what value the user has selected.\n", 42 | "\n", 43 | "**Hardest option:** Allow the user to interactively set a range of y values they are interested in, and recolor based on this (e.g. a y-axis band, see the paper for more details).\n", 44 | "\n", 45 | "---" 46 | ] 47 | }, 48 | { 49 | "cell_type": "code", 50 | "execution_count": 1, 51 | "metadata": { 52 | "collapsed": false 53 | }, 54 | "outputs": [], 55 | "source": [ 56 | "# Use the following data for this assignment:\n", 57 | "\n", 58 | "import pandas as pd\n", 59 | "import numpy as np\n", 60 | "\n", 61 | "np.random.seed(12345)\n", 62 | "\n", 63 | "df = pd.DataFrame([np.random.normal(33500,150000,3650), \n", 64 | " np.random.normal(41000,90000,3650), \n", 65 | " np.random.normal(41000,120000,3650), \n", 66 | " np.random.normal(48000,55000,3650)], \n", 67 | " index=[1992,1993,1994,1995])\n" 68 | ] 69 | }, 70 | { 71 | "cell_type": "code", 72 | "execution_count": 2, 73 | "metadata": { 74 | "collapsed": false 75 | }, 76 | "outputs": [ 77 | { 78 | "data": { 79 | "text/html": [ 80 | "
\n", 81 | "\n", 82 | " \n", 83 | " \n", 84 | " \n", 85 | " \n", 86 | " \n", 87 | " \n", 88 | " \n", 89 | " \n", 90 | " \n", 91 | " \n", 92 | " \n", 93 | " \n", 94 | " \n", 95 | " \n", 96 | " \n", 97 | " \n", 98 | " \n", 99 | " \n", 100 | " \n", 101 | " \n", 102 | " \n", 103 | " \n", 104 | " \n", 105 | " \n", 106 | " \n", 107 | " \n", 108 | " \n", 109 | " \n", 110 | " \n", 111 | " \n", 112 | " \n", 113 | " \n", 114 | " \n", 115 | " \n", 116 | " \n", 117 | " \n", 118 | " \n", 119 | " \n", 120 | " \n", 121 | " \n", 122 | " \n", 123 | " \n", 124 | " \n", 125 | " \n", 126 | " \n", 127 | " \n", 128 | " \n", 129 | " \n", 130 | " \n", 131 | " \n", 132 | " \n", 133 | " \n", 134 | " \n", 135 | " \n", 136 | " \n", 137 | " \n", 138 | " \n", 139 | " \n", 140 | " \n", 141 | " \n", 142 | " \n", 143 | " \n", 144 | " \n", 145 | " \n", 146 | " \n", 147 | " \n", 148 | " \n", 149 | " \n", 150 | " \n", 151 | " \n", 152 | " \n", 153 | " \n", 154 | " \n", 155 | " \n", 156 | "
1992199319941995
count3650.0000003650.0000003650.0000003650.000000
mean34484.08060739975.67358737565.68995047798.504333
std150473.17616488558.520583120317.07877754828.074297
min-528303.381600-287127.421315-382709.382654-138894.685422
25%-67555.298773-21665.471992-45516.91205111680.007981
50%31756.19828741001.77899239197.24117349103.396625
75%135081.37902199766.920131121367.18324484271.976610
max622629.206119358327.854561423792.855746262363.983464
yerr4881.6734772873.0288823903.3448181778.740656
\n", 157 | "
" 158 | ], 159 | "text/plain": [ 160 | " 1992 1993 1994 1995\n", 161 | "count 3650.000000 3650.000000 3650.000000 3650.000000\n", 162 | "mean 34484.080607 39975.673587 37565.689950 47798.504333\n", 163 | "std 150473.176164 88558.520583 120317.078777 54828.074297\n", 164 | "min -528303.381600 -287127.421315 -382709.382654 -138894.685422\n", 165 | "25% -67555.298773 -21665.471992 -45516.912051 11680.007981\n", 166 | "50% 31756.198287 41001.778992 39197.241173 49103.396625\n", 167 | "75% 135081.379021 99766.920131 121367.183244 84271.976610\n", 168 | "max 622629.206119 358327.854561 423792.855746 262363.983464\n", 169 | "yerr 4881.673477 2873.028882 3903.344818 1778.740656" 170 | ] 171 | }, 172 | "execution_count": 2, 173 | "metadata": {}, 174 | "output_type": "execute_result" 175 | } 176 | ], 177 | "source": [ 178 | "dfT =df.T\n", 179 | "dfStats = dfT.describe()\n", 180 | "dfStats\n", 181 | "dfStatsT = dfStats.T\n", 182 | "dfStatsT['yerr'] = 1.96 * dfStatsT['std'] / np.sqrt(dfStatsT['count'])\n", 183 | "dfStats = dfStatsT.T\n", 184 | "dfStats" 185 | ] 186 | }, 187 | { 188 | "cell_type": "code", 189 | "execution_count": 3, 190 | "metadata": { 191 | "collapsed": true 192 | }, 193 | "outputs": [], 194 | "source": [ 195 | "import matplotlib.pyplot as plt\n", 196 | "import pandas as pd\n", 197 | "import numpy as np\n", 198 | "import matplotlib.dates as mdates\n", 199 | "%matplotlib notebook\n", 200 | "\n" 201 | ] 202 | }, 203 | { 204 | "cell_type": "code", 205 | "execution_count": 4, 206 | "metadata": { 207 | "collapsed": false 208 | }, 209 | "outputs": [ 210 | { 211 | "data": { 212 | "text/html": [ 213 | "
\n", 214 | "\n", 215 | " \n", 216 | " \n", 217 | " \n", 218 | " \n", 219 | " \n", 220 | " \n", 221 | " \n", 222 | " \n", 223 | " \n", 224 | " \n", 225 | " \n", 226 | " \n", 227 | " \n", 228 | " \n", 229 | " \n", 230 | " \n", 231 | " \n", 232 | " \n", 233 | " \n", 234 | " \n", 235 | " \n", 236 | " \n", 237 | " \n", 238 | " \n", 239 | " \n", 240 | " \n", 241 | " \n", 242 | " \n", 243 | " \n", 244 | " \n", 245 | " \n", 246 | " \n", 247 | " \n", 248 | " \n", 249 | " \n", 250 | " \n", 251 | " \n", 252 | " \n", 253 | " \n", 254 | " \n", 255 | " \n", 256 | " \n", 257 | " \n", 258 | " \n", 259 | " \n", 260 | " \n", 261 | " \n", 262 | " \n", 263 | " \n", 264 | " \n", 265 | " \n", 266 | " \n", 267 | " \n", 268 | " \n", 269 | " \n", 270 | " \n", 271 | " \n", 272 | " \n", 273 | " \n", 274 | " \n", 275 | " \n", 276 | " \n", 277 | " \n", 278 | " \n", 279 | " \n", 280 | " \n", 281 | " \n", 282 | " \n", 283 | " \n", 284 | " \n", 285 | " \n", 286 | " \n", 287 | " \n", 288 | " \n", 289 | " \n", 290 | " \n", 291 | " \n", 292 | " \n", 293 | " \n", 294 | " \n", 295 | " \n", 296 | " \n", 297 | " \n", 298 | " \n", 299 | " \n", 300 | " \n", 301 | " \n", 302 | " \n", 303 | " \n", 304 | " \n", 305 | " \n", 306 | " \n", 307 | " \n", 308 | " \n", 309 | " \n", 310 | " \n", 311 | " \n", 312 | " \n", 313 | " \n", 314 | " \n", 315 | " \n", 316 | " \n", 317 | " \n", 318 | " \n", 319 | " \n", 320 | " \n", 321 | " \n", 322 | " \n", 323 | " \n", 324 | " \n", 325 | " \n", 326 | " \n", 327 | " \n", 328 | " \n", 329 | " \n", 330 | " \n", 331 | " \n", 332 | " \n", 333 | " \n", 334 | " \n", 335 | " \n", 336 | " \n", 337 | " \n", 338 | " \n", 339 | "
0123456789...3640364136423643364436453646364736483649
19922793.851077105341.500709-44415.807259-49859.545652328367.085875242510.87494647436.18151275761.922925148853.385142220465.210458...138454.070217122488.069943162247.982356-273907.868554-138410.57039627638.756441-33120.047151-40989.82486694532.9745076128.841097
1993-44406.485331180815.466879-108866.427539-114625.083717196807.23258247161.295355136522.08365458826.90490123329.019613-96417.638483...-37809.86806493228.910228108183.379950146728.060346-10083.899508-31300.14421595017.857057164071.51466314409.94459133298.608969
1994134288.798913169097.538334337957.368420-76005.27316490130.2079118453.626320-24562.317561195665.400438-53475.64077044708.230667...145216.40545167773.00636395711.194465174500.629277-27821.888075-57881.58314026321.525617-21424.06718660164.652898-74750.286614
1995-44485.202120-156.410517-13425.87863653540.999558130408.55987420445.65622460336.07723260688.099156-12748.49672257150.175074...-636.80495049707.89667252687.56413513529.92085067016.32475241664.942829119870.94694456946.28929767927.46610632839.707999
\n", 340 | "

4 rows × 3650 columns

\n", 341 | "
" 342 | ], 343 | "text/plain": [ 344 | " 0 1 2 3 \\\n", 345 | "1992 2793.851077 105341.500709 -44415.807259 -49859.545652 \n", 346 | "1993 -44406.485331 180815.466879 -108866.427539 -114625.083717 \n", 347 | "1994 134288.798913 169097.538334 337957.368420 -76005.273164 \n", 348 | "1995 -44485.202120 -156.410517 -13425.878636 53540.999558 \n", 349 | "\n", 350 | " 4 5 6 7 \\\n", 351 | "1992 328367.085875 242510.874946 47436.181512 75761.922925 \n", 352 | "1993 196807.232582 47161.295355 136522.083654 58826.904901 \n", 353 | "1994 90130.207911 8453.626320 -24562.317561 195665.400438 \n", 354 | "1995 130408.559874 20445.656224 60336.077232 60688.099156 \n", 355 | "\n", 356 | " 8 9 ... 3640 \\\n", 357 | "1992 148853.385142 220465.210458 ... 138454.070217 \n", 358 | "1993 23329.019613 -96417.638483 ... -37809.868064 \n", 359 | "1994 -53475.640770 44708.230667 ... 145216.405451 \n", 360 | "1995 -12748.496722 57150.175074 ... -636.804950 \n", 361 | "\n", 362 | " 3641 3642 3643 3644 \\\n", 363 | "1992 122488.069943 162247.982356 -273907.868554 -138410.570396 \n", 364 | "1993 93228.910228 108183.379950 146728.060346 -10083.899508 \n", 365 | "1994 67773.006363 95711.194465 174500.629277 -27821.888075 \n", 366 | "1995 49707.896672 52687.564135 13529.920850 67016.324752 \n", 367 | "\n", 368 | " 3645 3646 3647 3648 3649 \n", 369 | "1992 27638.756441 -33120.047151 -40989.824866 94532.974507 6128.841097 \n", 370 | "1993 -31300.144215 95017.857057 164071.514663 14409.944591 33298.608969 \n", 371 | "1994 -57881.583140 26321.525617 -21424.067186 60164.652898 -74750.286614 \n", 372 | "1995 41664.942829 119870.946944 56946.289297 67927.466106 32839.707999 \n", 373 | "\n", 374 | "[4 rows x 3650 columns]" 375 | ] 376 | }, 377 | "execution_count": 4, 378 | "metadata": {}, 379 | "output_type": "execute_result" 380 | } 381 | ], 382 | "source": [ 383 | "df.head()" 384 | ] 385 | }, 386 | { 387 | "cell_type": "code", 388 | "execution_count": 5, 389 | "metadata": { 390 | "collapsed": false 391 | }, 392 | "outputs": [ 393 | { 394 | "data": { 395 | "application/javascript": [ 396 | "/* Put everything inside the global mpl namespace */\n", 397 | "window.mpl = {};\n", 398 | "\n", 399 | "\n", 400 | "mpl.get_websocket_type = function() {\n", 401 | " if (typeof(WebSocket) !== 'undefined') {\n", 402 | " return WebSocket;\n", 403 | " } else if (typeof(MozWebSocket) !== 'undefined') {\n", 404 | " return MozWebSocket;\n", 405 | " } else {\n", 406 | " alert('Your browser does not have WebSocket support.' +\n", 407 | " 'Please try Chrome, Safari or Firefox ≥ 6. ' +\n", 408 | " 'Firefox 4 and 5 are also supported but you ' +\n", 409 | " 'have to enable WebSockets in about:config.');\n", 410 | " };\n", 411 | "}\n", 412 | "\n", 413 | "mpl.figure = function(figure_id, websocket, ondownload, parent_element) {\n", 414 | " this.id = figure_id;\n", 415 | "\n", 416 | " this.ws = websocket;\n", 417 | "\n", 418 | " this.supports_binary = (this.ws.binaryType != undefined);\n", 419 | "\n", 420 | " if (!this.supports_binary) {\n", 421 | " var warnings = document.getElementById(\"mpl-warnings\");\n", 422 | " if (warnings) {\n", 423 | " warnings.style.display = 'block';\n", 424 | " warnings.textContent = (\n", 425 | " \"This browser does not support binary websocket messages. \" +\n", 426 | " \"Performance may be slow.\");\n", 427 | " }\n", 428 | " }\n", 429 | "\n", 430 | " this.imageObj = new Image();\n", 431 | "\n", 432 | " this.context = undefined;\n", 433 | " this.message = undefined;\n", 434 | " this.canvas = undefined;\n", 435 | " this.rubberband_canvas = undefined;\n", 436 | " this.rubberband_context = undefined;\n", 437 | " this.format_dropdown = undefined;\n", 438 | "\n", 439 | " this.image_mode = 'full';\n", 440 | "\n", 441 | " this.root = $('
');\n", 442 | " this._root_extra_style(this.root)\n", 443 | " this.root.attr('style', 'display: inline-block');\n", 444 | "\n", 445 | " $(parent_element).append(this.root);\n", 446 | "\n", 447 | " this._init_header(this);\n", 448 | " this._init_canvas(this);\n", 449 | " this._init_toolbar(this);\n", 450 | "\n", 451 | " var fig = this;\n", 452 | "\n", 453 | " this.waiting = false;\n", 454 | "\n", 455 | " this.ws.onopen = function () {\n", 456 | " fig.send_message(\"supports_binary\", {value: fig.supports_binary});\n", 457 | " fig.send_message(\"send_image_mode\", {});\n", 458 | " if (mpl.ratio != 1) {\n", 459 | " fig.send_message(\"set_dpi_ratio\", {'dpi_ratio': mpl.ratio});\n", 460 | " }\n", 461 | " fig.send_message(\"refresh\", {});\n", 462 | " }\n", 463 | "\n", 464 | " this.imageObj.onload = function() {\n", 465 | " if (fig.image_mode == 'full') {\n", 466 | " // Full images could contain transparency (where diff images\n", 467 | " // almost always do), so we need to clear the canvas so that\n", 468 | " // there is no ghosting.\n", 469 | " fig.context.clearRect(0, 0, fig.canvas.width, fig.canvas.height);\n", 470 | " }\n", 471 | " fig.context.drawImage(fig.imageObj, 0, 0);\n", 472 | " };\n", 473 | "\n", 474 | " this.imageObj.onunload = function() {\n", 475 | " this.ws.close();\n", 476 | " }\n", 477 | "\n", 478 | " this.ws.onmessage = this._make_on_message_function(this);\n", 479 | "\n", 480 | " this.ondownload = ondownload;\n", 481 | "}\n", 482 | "\n", 483 | "mpl.figure.prototype._init_header = function() {\n", 484 | " var titlebar = $(\n", 485 | " '
');\n", 487 | " var titletext = $(\n", 488 | " '
');\n", 490 | " titlebar.append(titletext)\n", 491 | " this.root.append(titlebar);\n", 492 | " this.header = titletext[0];\n", 493 | "}\n", 494 | "\n", 495 | "\n", 496 | "\n", 497 | "mpl.figure.prototype._canvas_extra_style = function(canvas_div) {\n", 498 | "\n", 499 | "}\n", 500 | "\n", 501 | "\n", 502 | "mpl.figure.prototype._root_extra_style = function(canvas_div) {\n", 503 | "\n", 504 | "}\n", 505 | "\n", 506 | "mpl.figure.prototype._init_canvas = function() {\n", 507 | " var fig = this;\n", 508 | "\n", 509 | " var canvas_div = $('
');\n", 510 | "\n", 511 | " canvas_div.attr('style', 'position: relative; clear: both; outline: 0');\n", 512 | "\n", 513 | " function canvas_keyboard_event(event) {\n", 514 | " return fig.key_event(event, event['data']);\n", 515 | " }\n", 516 | "\n", 517 | " canvas_div.keydown('key_press', canvas_keyboard_event);\n", 518 | " canvas_div.keyup('key_release', canvas_keyboard_event);\n", 519 | " this.canvas_div = canvas_div\n", 520 | " this._canvas_extra_style(canvas_div)\n", 521 | " this.root.append(canvas_div);\n", 522 | "\n", 523 | " var canvas = $('');\n", 524 | " canvas.addClass('mpl-canvas');\n", 525 | " canvas.attr('style', \"left: 0; top: 0; z-index: 0; outline: 0\")\n", 526 | "\n", 527 | " this.canvas = canvas[0];\n", 528 | " this.context = canvas[0].getContext(\"2d\");\n", 529 | "\n", 530 | " var backingStore = this.context.backingStorePixelRatio ||\n", 531 | "\tthis.context.webkitBackingStorePixelRatio ||\n", 532 | "\tthis.context.mozBackingStorePixelRatio ||\n", 533 | "\tthis.context.msBackingStorePixelRatio ||\n", 534 | "\tthis.context.oBackingStorePixelRatio ||\n", 535 | "\tthis.context.backingStorePixelRatio || 1;\n", 536 | "\n", 537 | " mpl.ratio = (window.devicePixelRatio || 1) / backingStore;\n", 538 | "\n", 539 | " var rubberband = $('');\n", 540 | " rubberband.attr('style', \"position: absolute; left: 0; top: 0; z-index: 1;\")\n", 541 | "\n", 542 | " var pass_mouse_events = true;\n", 543 | "\n", 544 | " canvas_div.resizable({\n", 545 | " start: function(event, ui) {\n", 546 | " pass_mouse_events = false;\n", 547 | " },\n", 548 | " resize: function(event, ui) {\n", 549 | " fig.request_resize(ui.size.width, ui.size.height);\n", 550 | " },\n", 551 | " stop: function(event, ui) {\n", 552 | " pass_mouse_events = true;\n", 553 | " fig.request_resize(ui.size.width, ui.size.height);\n", 554 | " },\n", 555 | " });\n", 556 | "\n", 557 | " function mouse_event_fn(event) {\n", 558 | " if (pass_mouse_events)\n", 559 | " return fig.mouse_event(event, event['data']);\n", 560 | " }\n", 561 | "\n", 562 | " rubberband.mousedown('button_press', mouse_event_fn);\n", 563 | " rubberband.mouseup('button_release', mouse_event_fn);\n", 564 | " // Throttle sequential mouse events to 1 every 20ms.\n", 565 | " rubberband.mousemove('motion_notify', mouse_event_fn);\n", 566 | "\n", 567 | " rubberband.mouseenter('figure_enter', mouse_event_fn);\n", 568 | " rubberband.mouseleave('figure_leave', mouse_event_fn);\n", 569 | "\n", 570 | " canvas_div.on(\"wheel\", function (event) {\n", 571 | " event = event.originalEvent;\n", 572 | " event['data'] = 'scroll'\n", 573 | " if (event.deltaY < 0) {\n", 574 | " event.step = 1;\n", 575 | " } else {\n", 576 | " event.step = -1;\n", 577 | " }\n", 578 | " mouse_event_fn(event);\n", 579 | " });\n", 580 | "\n", 581 | " canvas_div.append(canvas);\n", 582 | " canvas_div.append(rubberband);\n", 583 | "\n", 584 | " this.rubberband = rubberband;\n", 585 | " this.rubberband_canvas = rubberband[0];\n", 586 | " this.rubberband_context = rubberband[0].getContext(\"2d\");\n", 587 | " this.rubberband_context.strokeStyle = \"#000000\";\n", 588 | "\n", 589 | " this._resize_canvas = function(width, height) {\n", 590 | " // Keep the size of the canvas, canvas container, and rubber band\n", 591 | " // canvas in synch.\n", 592 | " canvas_div.css('width', width)\n", 593 | " canvas_div.css('height', height)\n", 594 | "\n", 595 | " canvas.attr('width', width * mpl.ratio);\n", 596 | " canvas.attr('height', height * mpl.ratio);\n", 597 | " canvas.attr('style', 'width: ' + width + 'px; height: ' + height + 'px;');\n", 598 | "\n", 599 | " rubberband.attr('width', width);\n", 600 | " rubberband.attr('height', height);\n", 601 | " }\n", 602 | "\n", 603 | " // Set the figure to an initial 600x600px, this will subsequently be updated\n", 604 | " // upon first draw.\n", 605 | " this._resize_canvas(600, 600);\n", 606 | "\n", 607 | " // Disable right mouse context menu.\n", 608 | " $(this.rubberband_canvas).bind(\"contextmenu\",function(e){\n", 609 | " return false;\n", 610 | " });\n", 611 | "\n", 612 | " function set_focus () {\n", 613 | " canvas.focus();\n", 614 | " canvas_div.focus();\n", 615 | " }\n", 616 | "\n", 617 | " window.setTimeout(set_focus, 100);\n", 618 | "}\n", 619 | "\n", 620 | "mpl.figure.prototype._init_toolbar = function() {\n", 621 | " var fig = this;\n", 622 | "\n", 623 | " var nav_element = $('
')\n", 624 | " nav_element.attr('style', 'width: 100%');\n", 625 | " this.root.append(nav_element);\n", 626 | "\n", 627 | " // Define a callback function for later on.\n", 628 | " function toolbar_event(event) {\n", 629 | " return fig.toolbar_button_onclick(event['data']);\n", 630 | " }\n", 631 | " function toolbar_mouse_event(event) {\n", 632 | " return fig.toolbar_button_onmouseover(event['data']);\n", 633 | " }\n", 634 | "\n", 635 | " for(var toolbar_ind in mpl.toolbar_items) {\n", 636 | " var name = mpl.toolbar_items[toolbar_ind][0];\n", 637 | " var tooltip = mpl.toolbar_items[toolbar_ind][1];\n", 638 | " var image = mpl.toolbar_items[toolbar_ind][2];\n", 639 | " var method_name = mpl.toolbar_items[toolbar_ind][3];\n", 640 | "\n", 641 | " if (!name) {\n", 642 | " // put a spacer in here.\n", 643 | " continue;\n", 644 | " }\n", 645 | " var button = $('');\n", 1873 | " button.click(method_name, toolbar_event);\n", 1874 | " button.mouseover(tooltip, toolbar_mouse_event);\n", 1875 | " nav_element.append(button);\n", 1876 | " }\n", 1877 | "\n", 1878 | " // Add the status bar.\n", 1879 | " var status_bar = $('');\n", 1880 | " nav_element.append(status_bar);\n", 1881 | " this.message = status_bar[0];\n", 1882 | "\n", 1883 | " // Add the close button to the window.\n", 1884 | " var buttongrp = $('
');\n", 1885 | " var button = $('');\n", 1886 | " button.click(function (evt) { fig.handle_close(fig, {}); } );\n", 1887 | " button.mouseover('Stop Interaction', toolbar_mouse_event);\n", 1888 | " buttongrp.append(button);\n", 1889 | " var titlebar = this.root.find($('.ui-dialog-titlebar'));\n", 1890 | " titlebar.prepend(buttongrp);\n", 1891 | "}\n", 1892 | "\n", 1893 | "mpl.figure.prototype._root_extra_style = function(el){\n", 1894 | " var fig = this\n", 1895 | " el.on(\"remove\", function(){\n", 1896 | "\tfig.close_ws(fig, {});\n", 1897 | " });\n", 1898 | "}\n", 1899 | "\n", 1900 | "mpl.figure.prototype._canvas_extra_style = function(el){\n", 1901 | " // this is important to make the div 'focusable\n", 1902 | " el.attr('tabindex', 0)\n", 1903 | " // reach out to IPython and tell the keyboard manager to turn it's self\n", 1904 | " // off when our div gets focus\n", 1905 | "\n", 1906 | " // location in version 3\n", 1907 | " if (IPython.notebook.keyboard_manager) {\n", 1908 | " IPython.notebook.keyboard_manager.register_events(el);\n", 1909 | " }\n", 1910 | " else {\n", 1911 | " // location in version 2\n", 1912 | " IPython.keyboard_manager.register_events(el);\n", 1913 | " }\n", 1914 | "\n", 1915 | "}\n", 1916 | "\n", 1917 | "mpl.figure.prototype._key_event_extra = function(event, name) {\n", 1918 | " var manager = IPython.notebook.keyboard_manager;\n", 1919 | " if (!manager)\n", 1920 | " manager = IPython.keyboard_manager;\n", 1921 | "\n", 1922 | " // Check for shift+enter\n", 1923 | " if (event.shiftKey && event.which == 13) {\n", 1924 | " this.canvas_div.blur();\n", 1925 | " // select the cell after this one\n", 1926 | " var index = IPython.notebook.find_cell_index(this.cell_info[0]);\n", 1927 | " IPython.notebook.select(index + 1);\n", 1928 | " }\n", 1929 | "}\n", 1930 | "\n", 1931 | "mpl.figure.prototype.handle_save = function(fig, msg) {\n", 1932 | " fig.ondownload(fig, null);\n", 1933 | "}\n", 1934 | "\n", 1935 | "\n", 1936 | "mpl.find_output_cell = function(html_output) {\n", 1937 | " // Return the cell and output element which can be found *uniquely* in the notebook.\n", 1938 | " // Note - this is a bit hacky, but it is done because the \"notebook_saving.Notebook\"\n", 1939 | " // IPython event is triggered only after the cells have been serialised, which for\n", 1940 | " // our purposes (turning an active figure into a static one), is too late.\n", 1941 | " var cells = IPython.notebook.get_cells();\n", 1942 | " var ncells = cells.length;\n", 1943 | " for (var i=0; i= 3 moved mimebundle to data attribute of output\n", 1950 | " data = data.data;\n", 1951 | " }\n", 1952 | " if (data['text/html'] == html_output) {\n", 1953 | " return [cell, data, j];\n", 1954 | " }\n", 1955 | " }\n", 1956 | " }\n", 1957 | " }\n", 1958 | "}\n", 1959 | "\n", 1960 | "// Register the function which deals with the matplotlib target/channel.\n", 1961 | "// The kernel may be null if the page has been refreshed.\n", 1962 | "if (IPython.notebook.kernel != null) {\n", 1963 | " IPython.notebook.kernel.comm_manager.register_target('matplotlib', mpl.mpl_figure_comm);\n", 1964 | "}\n" 1965 | ], 1966 | "text/plain": [ 1967 | "" 1968 | ] 1969 | }, 1970 | "metadata": {}, 1971 | "output_type": "display_data" 1972 | }, 1973 | { 1974 | "data": { 1975 | "text/html": [ 1976 | "" 1977 | ], 1978 | "text/plain": [ 1979 | "" 1980 | ] 1981 | }, 1982 | "metadata": {}, 1983 | "output_type": "display_data" 1984 | } 1985 | ], 1986 | "source": [ 1987 | "plt.figure()\n", 1988 | "_=plt.hist(dfT[1992], bins=100)" 1989 | ] 1990 | }, 1991 | { 1992 | "cell_type": "code", 1993 | "execution_count": 7, 1994 | "metadata": { 1995 | "collapsed": true 1996 | }, 1997 | "outputs": [], 1998 | "source": [ 1999 | "from matplotlib.artist import Artist\n", 2000 | "\n", 2001 | "def rec_gc(art, depth=0):\n", 2002 | " if isinstance(art, Artist):\n", 2003 | " # increase the depth for pretty printing\n", 2004 | " print(\" \" * depth + str(art))\n", 2005 | " for child in art.get_children():\n", 2006 | " rec_gc(child, depth+2)" 2007 | ] 2008 | }, 2009 | { 2010 | "cell_type": "code", 2011 | "execution_count": 9, 2012 | "metadata": { 2013 | "collapsed": false 2014 | }, 2015 | "outputs": [ 2016 | { 2017 | "name": "stdout", 2018 | "output_type": "stream", 2019 | "text": [ 2020 | "[1992, 1993, 1994, 1995]\n", 2021 | "[34484.080606658281, 39975.673586966062, 37565.689949770465, 47798.504332995559]\n" 2022 | ] 2023 | }, 2024 | { 2025 | "data": { 2026 | "application/javascript": [ 2027 | "/* Put everything inside the global mpl namespace */\n", 2028 | "window.mpl = {};\n", 2029 | "\n", 2030 | "\n", 2031 | "mpl.get_websocket_type = function() {\n", 2032 | " if (typeof(WebSocket) !== 'undefined') {\n", 2033 | " return WebSocket;\n", 2034 | " } else if (typeof(MozWebSocket) !== 'undefined') {\n", 2035 | " return MozWebSocket;\n", 2036 | " } else {\n", 2037 | " alert('Your browser does not have WebSocket support.' +\n", 2038 | " 'Please try Chrome, Safari or Firefox ≥ 6. ' +\n", 2039 | " 'Firefox 4 and 5 are also supported but you ' +\n", 2040 | " 'have to enable WebSockets in about:config.');\n", 2041 | " };\n", 2042 | "}\n", 2043 | "\n", 2044 | "mpl.figure = function(figure_id, websocket, ondownload, parent_element) {\n", 2045 | " this.id = figure_id;\n", 2046 | "\n", 2047 | " this.ws = websocket;\n", 2048 | "\n", 2049 | " this.supports_binary = (this.ws.binaryType != undefined);\n", 2050 | "\n", 2051 | " if (!this.supports_binary) {\n", 2052 | " var warnings = document.getElementById(\"mpl-warnings\");\n", 2053 | " if (warnings) {\n", 2054 | " warnings.style.display = 'block';\n", 2055 | " warnings.textContent = (\n", 2056 | " \"This browser does not support binary websocket messages. \" +\n", 2057 | " \"Performance may be slow.\");\n", 2058 | " }\n", 2059 | " }\n", 2060 | "\n", 2061 | " this.imageObj = new Image();\n", 2062 | "\n", 2063 | " this.context = undefined;\n", 2064 | " this.message = undefined;\n", 2065 | " this.canvas = undefined;\n", 2066 | " this.rubberband_canvas = undefined;\n", 2067 | " this.rubberband_context = undefined;\n", 2068 | " this.format_dropdown = undefined;\n", 2069 | "\n", 2070 | " this.image_mode = 'full';\n", 2071 | "\n", 2072 | " this.root = $('
');\n", 2073 | " this._root_extra_style(this.root)\n", 2074 | " this.root.attr('style', 'display: inline-block');\n", 2075 | "\n", 2076 | " $(parent_element).append(this.root);\n", 2077 | "\n", 2078 | " this._init_header(this);\n", 2079 | " this._init_canvas(this);\n", 2080 | " this._init_toolbar(this);\n", 2081 | "\n", 2082 | " var fig = this;\n", 2083 | "\n", 2084 | " this.waiting = false;\n", 2085 | "\n", 2086 | " this.ws.onopen = function () {\n", 2087 | " fig.send_message(\"supports_binary\", {value: fig.supports_binary});\n", 2088 | " fig.send_message(\"send_image_mode\", {});\n", 2089 | " if (mpl.ratio != 1) {\n", 2090 | " fig.send_message(\"set_dpi_ratio\", {'dpi_ratio': mpl.ratio});\n", 2091 | " }\n", 2092 | " fig.send_message(\"refresh\", {});\n", 2093 | " }\n", 2094 | "\n", 2095 | " this.imageObj.onload = function() {\n", 2096 | " if (fig.image_mode == 'full') {\n", 2097 | " // Full images could contain transparency (where diff images\n", 2098 | " // almost always do), so we need to clear the canvas so that\n", 2099 | " // there is no ghosting.\n", 2100 | " fig.context.clearRect(0, 0, fig.canvas.width, fig.canvas.height);\n", 2101 | " }\n", 2102 | " fig.context.drawImage(fig.imageObj, 0, 0);\n", 2103 | " };\n", 2104 | "\n", 2105 | " this.imageObj.onunload = function() {\n", 2106 | " this.ws.close();\n", 2107 | " }\n", 2108 | "\n", 2109 | " this.ws.onmessage = this._make_on_message_function(this);\n", 2110 | "\n", 2111 | " this.ondownload = ondownload;\n", 2112 | "}\n", 2113 | "\n", 2114 | "mpl.figure.prototype._init_header = function() {\n", 2115 | " var titlebar = $(\n", 2116 | " '
');\n", 2118 | " var titletext = $(\n", 2119 | " '
');\n", 2121 | " titlebar.append(titletext)\n", 2122 | " this.root.append(titlebar);\n", 2123 | " this.header = titletext[0];\n", 2124 | "}\n", 2125 | "\n", 2126 | "\n", 2127 | "\n", 2128 | "mpl.figure.prototype._canvas_extra_style = function(canvas_div) {\n", 2129 | "\n", 2130 | "}\n", 2131 | "\n", 2132 | "\n", 2133 | "mpl.figure.prototype._root_extra_style = function(canvas_div) {\n", 2134 | "\n", 2135 | "}\n", 2136 | "\n", 2137 | "mpl.figure.prototype._init_canvas = function() {\n", 2138 | " var fig = this;\n", 2139 | "\n", 2140 | " var canvas_div = $('
');\n", 2141 | "\n", 2142 | " canvas_div.attr('style', 'position: relative; clear: both; outline: 0');\n", 2143 | "\n", 2144 | " function canvas_keyboard_event(event) {\n", 2145 | " return fig.key_event(event, event['data']);\n", 2146 | " }\n", 2147 | "\n", 2148 | " canvas_div.keydown('key_press', canvas_keyboard_event);\n", 2149 | " canvas_div.keyup('key_release', canvas_keyboard_event);\n", 2150 | " this.canvas_div = canvas_div\n", 2151 | " this._canvas_extra_style(canvas_div)\n", 2152 | " this.root.append(canvas_div);\n", 2153 | "\n", 2154 | " var canvas = $('');\n", 2155 | " canvas.addClass('mpl-canvas');\n", 2156 | " canvas.attr('style', \"left: 0; top: 0; z-index: 0; outline: 0\")\n", 2157 | "\n", 2158 | " this.canvas = canvas[0];\n", 2159 | " this.context = canvas[0].getContext(\"2d\");\n", 2160 | "\n", 2161 | " var backingStore = this.context.backingStorePixelRatio ||\n", 2162 | "\tthis.context.webkitBackingStorePixelRatio ||\n", 2163 | "\tthis.context.mozBackingStorePixelRatio ||\n", 2164 | "\tthis.context.msBackingStorePixelRatio ||\n", 2165 | "\tthis.context.oBackingStorePixelRatio ||\n", 2166 | "\tthis.context.backingStorePixelRatio || 1;\n", 2167 | "\n", 2168 | " mpl.ratio = (window.devicePixelRatio || 1) / backingStore;\n", 2169 | "\n", 2170 | " var rubberband = $('');\n", 2171 | " rubberband.attr('style', \"position: absolute; left: 0; top: 0; z-index: 1;\")\n", 2172 | "\n", 2173 | " var pass_mouse_events = true;\n", 2174 | "\n", 2175 | " canvas_div.resizable({\n", 2176 | " start: function(event, ui) {\n", 2177 | " pass_mouse_events = false;\n", 2178 | " },\n", 2179 | " resize: function(event, ui) {\n", 2180 | " fig.request_resize(ui.size.width, ui.size.height);\n", 2181 | " },\n", 2182 | " stop: function(event, ui) {\n", 2183 | " pass_mouse_events = true;\n", 2184 | " fig.request_resize(ui.size.width, ui.size.height);\n", 2185 | " },\n", 2186 | " });\n", 2187 | "\n", 2188 | " function mouse_event_fn(event) {\n", 2189 | " if (pass_mouse_events)\n", 2190 | " return fig.mouse_event(event, event['data']);\n", 2191 | " }\n", 2192 | "\n", 2193 | " rubberband.mousedown('button_press', mouse_event_fn);\n", 2194 | " rubberband.mouseup('button_release', mouse_event_fn);\n", 2195 | " // Throttle sequential mouse events to 1 every 20ms.\n", 2196 | " rubberband.mousemove('motion_notify', mouse_event_fn);\n", 2197 | "\n", 2198 | " rubberband.mouseenter('figure_enter', mouse_event_fn);\n", 2199 | " rubberband.mouseleave('figure_leave', mouse_event_fn);\n", 2200 | "\n", 2201 | " canvas_div.on(\"wheel\", function (event) {\n", 2202 | " event = event.originalEvent;\n", 2203 | " event['data'] = 'scroll'\n", 2204 | " if (event.deltaY < 0) {\n", 2205 | " event.step = 1;\n", 2206 | " } else {\n", 2207 | " event.step = -1;\n", 2208 | " }\n", 2209 | " mouse_event_fn(event);\n", 2210 | " });\n", 2211 | "\n", 2212 | " canvas_div.append(canvas);\n", 2213 | " canvas_div.append(rubberband);\n", 2214 | "\n", 2215 | " this.rubberband = rubberband;\n", 2216 | " this.rubberband_canvas = rubberband[0];\n", 2217 | " this.rubberband_context = rubberband[0].getContext(\"2d\");\n", 2218 | " this.rubberband_context.strokeStyle = \"#000000\";\n", 2219 | "\n", 2220 | " this._resize_canvas = function(width, height) {\n", 2221 | " // Keep the size of the canvas, canvas container, and rubber band\n", 2222 | " // canvas in synch.\n", 2223 | " canvas_div.css('width', width)\n", 2224 | " canvas_div.css('height', height)\n", 2225 | "\n", 2226 | " canvas.attr('width', width * mpl.ratio);\n", 2227 | " canvas.attr('height', height * mpl.ratio);\n", 2228 | " canvas.attr('style', 'width: ' + width + 'px; height: ' + height + 'px;');\n", 2229 | "\n", 2230 | " rubberband.attr('width', width);\n", 2231 | " rubberband.attr('height', height);\n", 2232 | " }\n", 2233 | "\n", 2234 | " // Set the figure to an initial 600x600px, this will subsequently be updated\n", 2235 | " // upon first draw.\n", 2236 | " this._resize_canvas(600, 600);\n", 2237 | "\n", 2238 | " // Disable right mouse context menu.\n", 2239 | " $(this.rubberband_canvas).bind(\"contextmenu\",function(e){\n", 2240 | " return false;\n", 2241 | " });\n", 2242 | "\n", 2243 | " function set_focus () {\n", 2244 | " canvas.focus();\n", 2245 | " canvas_div.focus();\n", 2246 | " }\n", 2247 | "\n", 2248 | " window.setTimeout(set_focus, 100);\n", 2249 | "}\n", 2250 | "\n", 2251 | "mpl.figure.prototype._init_toolbar = function() {\n", 2252 | " var fig = this;\n", 2253 | "\n", 2254 | " var nav_element = $('
')\n", 2255 | " nav_element.attr('style', 'width: 100%');\n", 2256 | " this.root.append(nav_element);\n", 2257 | "\n", 2258 | " // Define a callback function for later on.\n", 2259 | " function toolbar_event(event) {\n", 2260 | " return fig.toolbar_button_onclick(event['data']);\n", 2261 | " }\n", 2262 | " function toolbar_mouse_event(event) {\n", 2263 | " return fig.toolbar_button_onmouseover(event['data']);\n", 2264 | " }\n", 2265 | "\n", 2266 | " for(var toolbar_ind in mpl.toolbar_items) {\n", 2267 | " var name = mpl.toolbar_items[toolbar_ind][0];\n", 2268 | " var tooltip = mpl.toolbar_items[toolbar_ind][1];\n", 2269 | " var image = mpl.toolbar_items[toolbar_ind][2];\n", 2270 | " var method_name = mpl.toolbar_items[toolbar_ind][3];\n", 2271 | "\n", 2272 | " if (!name) {\n", 2273 | " // put a spacer in here.\n", 2274 | " continue;\n", 2275 | " }\n", 2276 | " var button = $('