abalone.jpg abalone_cleaned.csv length,diameter,height,whole_weight,shucked_weight,viscera_weight,shell_weight,rings,sex_I,sex_M 0.455,0.365,0.095,0.514,0.2245,0.101,0.15,15,0,1...

1 answer below »
need python code for the attached assignment


abalone.jpg abalone_cleaned.csv length,diameter,height,whole_weight,shucked_weight,viscera_weight,shell_weight,rings,sex_I,sex_M 0.455,0.365,0.095,0.514,0.2245,0.101,0.15,15,0,1 0.35,0.265,0.09,0.2255,0.0995,0.0485,0.07,7,0,1 0.53,0.42,0.135,0.677,0.2565,0.1415,0.21,9,0,0 0.44,0.365,0.125,0.516,0.2155,0.114,0.155,10,0,1 0.33,0.255,0.08,0.205,0.0895,0.0395,0.055,7,1,0 0.425,0.3,0.095,0.3515,0.141,0.0775,0.12,8,1,0 0.53,0.415,0.15,0.7775,0.237,0.1415,0.33,20,0,0 0.545,0.425,0.125,0.768,0.294,0.1495,0.26,16,0,0 0.475,0.37,0.125,0.5095,0.2165,0.1125,0.165,9,0,1 0.55,0.44,0.15,0.8945,0.3145,0.151,0.32,19,0,0 0.525,0.38,0.14,0.6065,0.194,0.1475,0.21,14,0,0 0.43,0.35,0.11,0.406,0.1675,0.081,0.135,10,0,1 0.49,0.38,0.135,0.5415,0.2175,0.095,0.19,11,0,1 0.535,0.405,0.145,0.6845,0.2725,0.171,0.205,10,0,0 0.47,0.355,0.1,0.4755,0.1675,0.0805,0.185,10,0,0 0.5,0.4,0.13,0.6645,0.258,0.133,0.24,12,0,1 0.355,0.28,0.085,0.2905,0.095,0.0395,0.115,7,1,0 0.44,0.34,0.1,0.451,0.188,0.087,0.13,10,0,0 0.365,0.295,0.08,0.2555,0.097,0.043,0.1,7,0,1 0.45,0.32,0.1,0.381,0.1705,0.075,0.115,9,0,1 0.355,0.28,0.095,0.2455,0.0955,0.062,0.075,11,0,1 0.38,0.275,0.1,0.2255,0.08,0.049,0.085,10,1,0 0.565,0.44,0.155,0.9395,0.4275,0.214,0.27,12,0,0 0.55,0.415,0.135,0.7635,0.318,0.21,0.2,9,0,0 0.615,0.48,0.165,1.1615,0.513,0.301,0.305,10,0,0 0.56,0.44,0.14,0.9285,0.3825,0.188,0.3,11,0,0 0.58,0.45,0.185,0.9955,0.3945,0.272,0.285,11,0,0 0.59,0.445,0.14,0.931,0.35600000000000004,0.234,0.28,12,0,1 0.605,0.475,0.18,0.9365,0.394,0.219,0.295,15,0,1 0.575,0.425,0.14,0.8635,0.393,0.227,0.2,11,0,1 0.58,0.47,0.165,0.9975,0.3935,0.242,0.33,10,0,1 0.68,0.56,0.165,1.639,0.6055,0.2805,0.46,15,0,0 0.665,0.525,0.165,1.338,0.5515,0.3575,0.35,18,0,1 0.68,0.55,0.175,1.798,0.815,0.3925,0.455,19,0,0 0.705,0.55,0.2,1.7095,0.633,0.4115,0.49,13,0,0 0.465,0.355,0.105,0.4795,0.227,0.124,0.125,8,0,1 0.54,0.475,0.155,1.217,0.5305,0.3075,0.34,16,0,0 0.45,0.355,0.105,0.5225,0.237,0.1165,0.145,8,0,0 0.575,0.445,0.135,0.883,0.381,0.2035,0.26,11,0,0 0.355,0.29,0.09,0.3275,0.134,0.086,0.09,9,0,1 0.45,0.335,0.105,0.425,0.1865,0.091,0.115,9,0,0 0.55,0.425,0.135,0.8515,0.362,0.196,0.27,14,0,0 0.24,0.175,0.045,0.07,0.0315,0.0235,0.02,5,1,0 0.205,0.15,0.055,0.042,0.0255,0.015,0.012,5,1,0 0.21,0.15,0.05,0.042,0.0175,0.0125,0.015,4,1,0 0.39,0.295,0.095,0.203,0.0875,0.045,0.075,7,1,0 0.47,0.37,0.12,0.5795,0.293,0.227,0.14,9,0,1 0.46,0.375,0.12,0.4605,0.1775,0.11,0.15,7,0,0 0.325,0.245,0.07,0.161,0.0755,0.0255,0.045,6,1,0 0.525,0.425,0.16,0.8355,0.3545,0.2135,0.245,9,0,0 0.52,0.41,0.12,0.595,0.2385,0.111,0.19,8,1,0 0.4,0.32,0.095,0.303,0.1335,0.06,0.1,7,0,1 0.485,0.36,0.13,0.5415,0.2595,0.096,0.16,10,0,1 0.47,0.36,0.12,0.4775,0.2105,0.1055,0.15,10,0,0 0.405,0.31,0.1,0.385,0.173,0.0915,0.11,7,0,1 0.5,0.4,0.14,0.6615,0.2565,0.1755,0.22,8,0,0 0.445,0.35,0.12,0.4425,0.192,0.0955,0.135,8,0,1 0.47,0.385,0.135,0.5895,0.2765,0.12,0.17,8,0,1 0.245,0.19,0.06,0.086,0.042,0.014,0.025,4,1,0 0.505,0.4,0.125,0.583,0.246,0.13,0.175,7,0,0 0.45,0.345,0.105,0.4115,0.18,0.1125,0.135,7,0,1 0.505,0.405,0.11,0.625,0.305,0.16,0.175,9,0,1 0.53,0.41,0.13,0.6965,0.302,0.1935,0.2,10,0,0 0.425,0.325,0.095,0.3785,0.1705,0.08,0.1,7,0,1 0.52,0.4,0.12,0.58,0.234,0.1315,0.185,8,0,1 0.475,0.355,0.12,0.48,0.234,0.1015,0.135,8,0,1 0.565,0.44,0.16,0.915,0.354,0.1935,0.32,12,0,0 0.595,0.495,0.185,1.285,0.416,0.224,0.485,13,0,0 0.475,0.39,0.12,0.5305,0.2135,0.1155,0.17,10,0,0 0.31,0.235,0.07,0.151,0.063,0.0405,0.045,6,1,0 0.555,0.425,0.13,0.7665,0.264,0.168,0.275,13,0,1 0.4,0.32,0.11,0.353,0.1405,0.0985,0.1,8,0,0 0.595,0.475,0.17,1.247,0.48,0.225,0.425,20,0,0 0.57,0.48,0.175,1.185,0.474,0.261,0.38,11,0,1 0.605,0.45,0.195,1.098,0.481,0.2895,0.315,13,0,0 0.6,0.475,0.15,1.0075,0.4425,0.221,0.28,15,0,0 0.595,0.475,0.14,0.944,0.3625,0.189,0.315,9,0,1 0.6,0.47,0.15,0.922,0.363,0.194,0.305,10,0,0 0.555,0.425,0.14,0.7879999999999999,0.282,0.1595,0.285,11,0,0 0.615,0.475,0.17,1.1025,0.4695,0.2355,0.345,14,0,0 0.575,0.445,0.14,0.941,0.3845,0.252,0.285,9,0,0 0.62,0.51,0.175,1.615,0.5105,0.192,0.675,12,0,1 0.52,0.425,0.165,0.9885,0.396,0.225,0.32,16,0,0 0.595,0.475,0.16,1.3175,0.408,0.234,0.58,21,0,1 0.58,0.45,0.14,1.013,0.38,0.21600000000000005,0.36,14,0,1 0.57,0.465,0.18,1.295,0.339,0.2225,0.44,12,0,0 0.625,0.465,0.14,1.195,0.4825,0.205,0.4,13,0,1 0.56,0.44,0.16,0.8645,0.3305,0.2075,0.26,10,0,1 0.46,0.355,0.13,0.517,0.2205,0.114,0.165,9,0,0 0.575,0.45,0.16,0.9775,0.3135,0.231,0.33,12,0,0 0.565,0.425,0.135,0.8115,0.341,0.1675,0.255,15,0,1 0.555,0.44,0.15,0.755,0.307,0.1525,0.26,12,0,1 0.595,0.465,0.175,1.115,0.4015,0.254,0.39,13,0,1 0.625,0.495,0.165,1.262,0.507,0.318,0.39,10,0,0 0.695,0.56,0.19,1.494,0.588,0.3425,0.485,15,0,1 0.665,0.535,0.195,1.606,0.5755,0.388,0.48,14,0,1 0.535,0.435,0.15,0.725,0.269,0.1385,0.25,9,0,1 0.47,0.375,0.13,0.523,0.214,0.132,0.145,8,0,1 0.47,0.37,0.13,0.5225,0.201,0.133,0.165,7,0,1 0.475,0.375,0.125,0.5785,0.2775,0.085,0.155,10,0,0 0.36,0.265,0.095,0.2315,0.105,0.046,0.075,7,1,0 0.55,0.435,0.145,0.843,0.328,0.1915,0.255,15,0,1 0.53,0.435,0.16,0.883,0.316,0.16399999999999998,0.335,15,0,1 0.53,0.415,0.14,0.7240000000000001,0.3105,0.1675,0.205,10,0,1 0.605,0.47,0.16,1.1735,0.4975,0.2405,0.345,12,0,1 0.52,0.41,0.155,0.727,0.29100000000000004,0.1835,0.235,12,0,0 0.545,0.43,0.165,0.802,0.2935,0.183,0.28,11,0,0 0.5,0.4,0.125,0.6675,0.261,0.1315,0.22,10,0,0 0.51,0.39,0.135,0.6335,0.231,0.179,0.2,9,0,0 0.435,0.395,0.105,0.3635,0.136,0.098,0.13,9,0,0 0.495,0.395,0.125,0.5415,0.2375,0.1345,0.155,9,0,1 0.465,0.36,0.105,0.431,0.172,0.107,0.175,9,0,1 0.435,0.32,0.08,0.3325,0.1485,0.0635,0.105,9,1,0 0.425,0.35,0.105,0.393,0.13,0.063,0.165,9,0,1 0.545,0.41,0.125,0.6935,0.2975,0.146,0.21,11,0,0 0.53,0.415,0.115,0.5915,0.233,0.1585,0.18,11,0,0 0.49,0.375,0.135,0.6125,0.2555,0.102,0.22
Answered 2 days AfterJul 02, 2021

Answer To: abalone.jpg abalone_cleaned.csv...

Pritam Kumar answered on Jul 05 2021
157 Votes
{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [],
"source": [
"%matplotlib notebook\n",
"import pandas as pd\n",
"import numpy as np\n",
"import matplotlib.pyplot as plt"
]
},
{
"cell_type": "code",
"execution_count": 32,
"metadata": {},
"outputs": [],
"source": [
"### GRADED\n",
"###\n",
"### Use the function pd.read_csv() to load the data set. \n",
"### The path to the file is `DATA_PATH`.\n",
"### Set the appropriate parameter to use the first row as the column names.\n",
"### Assign the resulting DataFrame to the variable 'data'.\n",
"\n",
"DATA_PATH = 'D:\\\\New\\\\iris_dataset.csv'\n",
"\n",
"### YOUR ANSWER BELOW\n",
"data = pd.read_csv(DATA_PATH)\n",
"\n",
"###\n",
"### YOUR CODE HERE\n",
"###\n"
]
},
{
"cell_type": "code",
"execution_count": 33,
"metadata": {},
"outputs": [],
"source": [
"###\n",
"### AUTOGRADER TEST - DO NOT REMOVE\n",
"###\n"
]
},
{
"cell_type": "code",
"execution_count": 34,
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"
\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"
sepal_lensepal_widthpetal_lenpetal_widthclass
05.13.51.40.2Iris-setosa
14.93.01.40.2Iris-setosa
24.73.21.30.2Iris-setosa
34.63.11.50.2Iris-setosa
45.03.61.40.2Iris-setosa
\n",
"
"
],
"text/plain": [
" sepal_len sepal_width petal_len petal_width class\n",
"0 5.1 3.5 1.4 0.2 Iris-setosa\n",
"1 4.9 3.0 1.4 0.2 Iris-setosa\n",
"2 4.7 3.2 1.3 0.2 Iris-setosa\n",
"3 4.6 3.1 1.5 0.2 Iris-setosa\n",
"4 5.0 3.6 1.4 0.2 Iris-setosa"
]
},
"execution_count": 34,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"data.head()"
]
},
{
"cell_type": "code",
"execution_count": 35,
"metadata": {},
"outputs": [],
"source": [
"### GRADED\n",
"###\n",
"### Separate the features and the labels from data. The labels are the column 'class'.\n",
"### Assign a pd.DataFrame with the features to 'X'.\n",
"### Assign a pd.Series with the labels to 'labels'.\n",
"\n",
"### YOUR ANSWER BELOW\n",
"X = data.iloc[:, 0:4]\n",
"labels = data[\"class\"]\n",
"\n",
"###\n",
"### YOUR CODE HERE\n",
"###\n"
]
},
{
"cell_type": "code",
"execution_count": 36,
"metadata": {},
"outputs": [],
"source": [
"###\n",
"### AUTOGRADER TEST - DO NOT REMOVE\n",
"###\n"
]
},
{
"cell_type": "code",
"execution_count": 37,
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"
\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"
sepal_lensepal_widthpetal_lenpetal_width
05.13.51.40.2
14.93.01.40.2
24.73.21.30.2
34.63.11.50.2
45.03.61.40.2
\n",
"
"
],
"text/plain": [
" sepal_len sepal_width petal_len petal_width\n",
"0 5.1 3.5 1.4 0.2\n",
"1 4.9 3.0 1.4 0.2\n",
"2 4.7 3.2 1.3 0.2\n",
"3 4.6 3.1 1.5 0.2\n",
"4 5.0 3.6 1.4 0.2"
]
},
"execution_count": 37,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"X.head()"
]
},
{
"cell_type": "code",
"execution_count": 38,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"0 Iris-setosa\n",
"1 Iris-setosa\n",
"2 Iris-setosa\n",
"3 Iris-setosa\n",
"4 Iris-setosa\n",
"Name: class, dtype: object"
]
},
"execution_count": 38,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"labels.head()"
]
},
{
"cell_type": "code",
"execution_count": 39,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"array(['Iris-setosa', 'Iris-versicolor', 'Iris-virginica'], dtype=object)"
]
},
"execution_count": 39,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"np.unique(labels)"
]
},
{
"cell_type": "code",
"execution_count": 40,
"metadata": {},
"outputs": [],
"source": [
"### GRADED\n",
"###\n",
"### Convert the classes in 'labels' to integers as follows:\n",
"### 'Iris-setosa' -> 0\n",
"### 'Iris-versicolor' -> 1\n",
"### 'Iris-virginica' -> 2\n",
"### Assign a `np.array` with the same number of elements as `labels` to `y`.\n",
"###\n",
"### NOTE: Do not alter the order of the samples.\n",
"\n",
"### YOUR ANSWER BELOW\n",
"\n",
"labels = labels.replace(to_replace = 'Iris-setosa', value = 0)\n",
"labels = labels.replace(to_replace = 'Iris-versicolor', value = 1)\n",
"labels = labels.replace(to_replace = 'Iris-virginica', value = 2)\n",
"\n",
"y = np.array(labels)\n",
"\n",
"###\n",
"### YOUR CODE HERE\n",
"###\n"
]
},
{
"cell_type": "code",
"execution_count": 42,
"metadata": {},
"outputs": [],
"source": [
"###\n",
"### AUTOGRADER TEST - DO NOT REMOVE\n",
"###\n"
]
},
{
"cell_type": "code",
"execution_count": 43,
"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",
" '
" 'ui-helper-clearfix\"/>');\n",
" var titletext = $(\n",
" '
" 'text-align: center; padding: 3px;\"/>');\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 " var cell = cells[i];\n",
" if (cell.cell_type === 'code'){\n",
" for (var j=0; j " var data = cell.output_area.outputs[j];\n",
" if (data.data) {\n",
" // IPython >= 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": [
"
SOLUTION.PDF

Answer To This Question Is Available To Download

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here