├── README.md ├── Figure.PNG ├── Links.txt ├── Project Figure.PNG ├── .gitattributes ├── loan application.csv ├── total loans.csv └── Assignment3_Aniket.ipynb /README.md: -------------------------------------------------------------------------------- 1 | # Applied-Plotting-Charting-and-Data-Representation-in-Python 2 | Coursera course by University of Michigan 3 | -------------------------------------------------------------------------------- /Figure.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bondeanikets/Applied-Plotting-Charting-and-Data-Representation-in-Python/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/bondeanikets/Applied-Plotting-Charting-and-Data-Representation-in-Python/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 | -------------------------------------------------------------------------------- /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_Aniket.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": 79, 51 | "metadata": { 52 | "collapsed": false 53 | }, 54 | "outputs": [ 55 | { 56 | "data": { 57 | "application/javascript": [ 58 | "/* Put everything inside the global mpl namespace */\n", 59 | "window.mpl = {};\n", 60 | "\n", 61 | "\n", 62 | "mpl.get_websocket_type = function() {\n", 63 | " if (typeof(WebSocket) !== 'undefined') {\n", 64 | " return WebSocket;\n", 65 | " } else if (typeof(MozWebSocket) !== 'undefined') {\n", 66 | " return MozWebSocket;\n", 67 | " } else {\n", 68 | " alert('Your browser does not have WebSocket support.' +\n", 69 | " 'Please try Chrome, Safari or Firefox ≥ 6. ' +\n", 70 | " 'Firefox 4 and 5 are also supported but you ' +\n", 71 | " 'have to enable WebSockets in about:config.');\n", 72 | " };\n", 73 | "}\n", 74 | "\n", 75 | "mpl.figure = function(figure_id, websocket, ondownload, parent_element) {\n", 76 | " this.id = figure_id;\n", 77 | "\n", 78 | " this.ws = websocket;\n", 79 | "\n", 80 | " this.supports_binary = (this.ws.binaryType != undefined);\n", 81 | "\n", 82 | " if (!this.supports_binary) {\n", 83 | " var warnings = document.getElementById(\"mpl-warnings\");\n", 84 | " if (warnings) {\n", 85 | " warnings.style.display = 'block';\n", 86 | " warnings.textContent = (\n", 87 | " \"This browser does not support binary websocket messages. \" +\n", 88 | " \"Performance may be slow.\");\n", 89 | " }\n", 90 | " }\n", 91 | "\n", 92 | " this.imageObj = new Image();\n", 93 | "\n", 94 | " this.context = undefined;\n", 95 | " this.message = undefined;\n", 96 | " this.canvas = undefined;\n", 97 | " this.rubberband_canvas = undefined;\n", 98 | " this.rubberband_context = undefined;\n", 99 | " this.format_dropdown = undefined;\n", 100 | "\n", 101 | " this.image_mode = 'full';\n", 102 | "\n", 103 | " this.root = $('
');\n", 104 | " this._root_extra_style(this.root)\n", 105 | " this.root.attr('style', 'display: inline-block');\n", 106 | "\n", 107 | " $(parent_element).append(this.root);\n", 108 | "\n", 109 | " this._init_header(this);\n", 110 | " this._init_canvas(this);\n", 111 | " this._init_toolbar(this);\n", 112 | "\n", 113 | " var fig = this;\n", 114 | "\n", 115 | " this.waiting = false;\n", 116 | "\n", 117 | " this.ws.onopen = function () {\n", 118 | " fig.send_message(\"supports_binary\", {value: fig.supports_binary});\n", 119 | " fig.send_message(\"send_image_mode\", {});\n", 120 | " if (mpl.ratio != 1) {\n", 121 | " fig.send_message(\"set_dpi_ratio\", {'dpi_ratio': mpl.ratio});\n", 122 | " }\n", 123 | " fig.send_message(\"refresh\", {});\n", 124 | " }\n", 125 | "\n", 126 | " this.imageObj.onload = function() {\n", 127 | " if (fig.image_mode == 'full') {\n", 128 | " // Full images could contain transparency (where diff images\n", 129 | " // almost always do), so we need to clear the canvas so that\n", 130 | " // there is no ghosting.\n", 131 | " fig.context.clearRect(0, 0, fig.canvas.width, fig.canvas.height);\n", 132 | " }\n", 133 | " fig.context.drawImage(fig.imageObj, 0, 0);\n", 134 | " };\n", 135 | "\n", 136 | " this.imageObj.onunload = function() {\n", 137 | " this.ws.close();\n", 138 | " }\n", 139 | "\n", 140 | " this.ws.onmessage = this._make_on_message_function(this);\n", 141 | "\n", 142 | " this.ondownload = ondownload;\n", 143 | "}\n", 144 | "\n", 145 | "mpl.figure.prototype._init_header = function() {\n", 146 | " var titlebar = $(\n", 147 | " '
');\n", 149 | " var titletext = $(\n", 150 | " '
');\n", 152 | " titlebar.append(titletext)\n", 153 | " this.root.append(titlebar);\n", 154 | " this.header = titletext[0];\n", 155 | "}\n", 156 | "\n", 157 | "\n", 158 | "\n", 159 | "mpl.figure.prototype._canvas_extra_style = function(canvas_div) {\n", 160 | "\n", 161 | "}\n", 162 | "\n", 163 | "\n", 164 | "mpl.figure.prototype._root_extra_style = function(canvas_div) {\n", 165 | "\n", 166 | "}\n", 167 | "\n", 168 | "mpl.figure.prototype._init_canvas = function() {\n", 169 | " var fig = this;\n", 170 | "\n", 171 | " var canvas_div = $('
');\n", 172 | "\n", 173 | " canvas_div.attr('style', 'position: relative; clear: both; outline: 0');\n", 174 | "\n", 175 | " function canvas_keyboard_event(event) {\n", 176 | " return fig.key_event(event, event['data']);\n", 177 | " }\n", 178 | "\n", 179 | " canvas_div.keydown('key_press', canvas_keyboard_event);\n", 180 | " canvas_div.keyup('key_release', canvas_keyboard_event);\n", 181 | " this.canvas_div = canvas_div\n", 182 | " this._canvas_extra_style(canvas_div)\n", 183 | " this.root.append(canvas_div);\n", 184 | "\n", 185 | " var canvas = $('');\n", 186 | " canvas.addClass('mpl-canvas');\n", 187 | " canvas.attr('style', \"left: 0; top: 0; z-index: 0; outline: 0\")\n", 188 | "\n", 189 | " this.canvas = canvas[0];\n", 190 | " this.context = canvas[0].getContext(\"2d\");\n", 191 | "\n", 192 | " var backingStore = this.context.backingStorePixelRatio ||\n", 193 | "\tthis.context.webkitBackingStorePixelRatio ||\n", 194 | "\tthis.context.mozBackingStorePixelRatio ||\n", 195 | "\tthis.context.msBackingStorePixelRatio ||\n", 196 | "\tthis.context.oBackingStorePixelRatio ||\n", 197 | "\tthis.context.backingStorePixelRatio || 1;\n", 198 | "\n", 199 | " mpl.ratio = (window.devicePixelRatio || 1) / backingStore;\n", 200 | "\n", 201 | " var rubberband = $('');\n", 202 | " rubberband.attr('style', \"position: absolute; left: 0; top: 0; z-index: 1;\")\n", 203 | "\n", 204 | " var pass_mouse_events = true;\n", 205 | "\n", 206 | " canvas_div.resizable({\n", 207 | " start: function(event, ui) {\n", 208 | " pass_mouse_events = false;\n", 209 | " },\n", 210 | " resize: function(event, ui) {\n", 211 | " fig.request_resize(ui.size.width, ui.size.height);\n", 212 | " },\n", 213 | " stop: function(event, ui) {\n", 214 | " pass_mouse_events = true;\n", 215 | " fig.request_resize(ui.size.width, ui.size.height);\n", 216 | " },\n", 217 | " });\n", 218 | "\n", 219 | " function mouse_event_fn(event) {\n", 220 | " if (pass_mouse_events)\n", 221 | " return fig.mouse_event(event, event['data']);\n", 222 | " }\n", 223 | "\n", 224 | " rubberband.mousedown('button_press', mouse_event_fn);\n", 225 | " rubberband.mouseup('button_release', mouse_event_fn);\n", 226 | " // Throttle sequential mouse events to 1 every 20ms.\n", 227 | " rubberband.mousemove('motion_notify', mouse_event_fn);\n", 228 | "\n", 229 | " rubberband.mouseenter('figure_enter', mouse_event_fn);\n", 230 | " rubberband.mouseleave('figure_leave', mouse_event_fn);\n", 231 | "\n", 232 | " canvas_div.on(\"wheel\", function (event) {\n", 233 | " event = event.originalEvent;\n", 234 | " event['data'] = 'scroll'\n", 235 | " if (event.deltaY < 0) {\n", 236 | " event.step = 1;\n", 237 | " } else {\n", 238 | " event.step = -1;\n", 239 | " }\n", 240 | " mouse_event_fn(event);\n", 241 | " });\n", 242 | "\n", 243 | " canvas_div.append(canvas);\n", 244 | " canvas_div.append(rubberband);\n", 245 | "\n", 246 | " this.rubberband = rubberband;\n", 247 | " this.rubberband_canvas = rubberband[0];\n", 248 | " this.rubberband_context = rubberband[0].getContext(\"2d\");\n", 249 | " this.rubberband_context.strokeStyle = \"#000000\";\n", 250 | "\n", 251 | " this._resize_canvas = function(width, height) {\n", 252 | " // Keep the size of the canvas, canvas container, and rubber band\n", 253 | " // canvas in synch.\n", 254 | " canvas_div.css('width', width)\n", 255 | " canvas_div.css('height', height)\n", 256 | "\n", 257 | " canvas.attr('width', width * mpl.ratio);\n", 258 | " canvas.attr('height', height * mpl.ratio);\n", 259 | " canvas.attr('style', 'width: ' + width + 'px; height: ' + height + 'px;');\n", 260 | "\n", 261 | " rubberband.attr('width', width);\n", 262 | " rubberband.attr('height', height);\n", 263 | " }\n", 264 | "\n", 265 | " // Set the figure to an initial 600x600px, this will subsequently be updated\n", 266 | " // upon first draw.\n", 267 | " this._resize_canvas(600, 600);\n", 268 | "\n", 269 | " // Disable right mouse context menu.\n", 270 | " $(this.rubberband_canvas).bind(\"contextmenu\",function(e){\n", 271 | " return false;\n", 272 | " });\n", 273 | "\n", 274 | " function set_focus () {\n", 275 | " canvas.focus();\n", 276 | " canvas_div.focus();\n", 277 | " }\n", 278 | "\n", 279 | " window.setTimeout(set_focus, 100);\n", 280 | "}\n", 281 | "\n", 282 | "mpl.figure.prototype._init_toolbar = function() {\n", 283 | " var fig = this;\n", 284 | "\n", 285 | " var nav_element = $('
')\n", 286 | " nav_element.attr('style', 'width: 100%');\n", 287 | " this.root.append(nav_element);\n", 288 | "\n", 289 | " // Define a callback function for later on.\n", 290 | " function toolbar_event(event) {\n", 291 | " return fig.toolbar_button_onclick(event['data']);\n", 292 | " }\n", 293 | " function toolbar_mouse_event(event) {\n", 294 | " return fig.toolbar_button_onmouseover(event['data']);\n", 295 | " }\n", 296 | "\n", 297 | " for(var toolbar_ind in mpl.toolbar_items) {\n", 298 | " var name = mpl.toolbar_items[toolbar_ind][0];\n", 299 | " var tooltip = mpl.toolbar_items[toolbar_ind][1];\n", 300 | " var image = mpl.toolbar_items[toolbar_ind][2];\n", 301 | " var method_name = mpl.toolbar_items[toolbar_ind][3];\n", 302 | "\n", 303 | " if (!name) {\n", 304 | " // put a spacer in here.\n", 305 | " continue;\n", 306 | " }\n", 307 | " var button = $('