|
33 | 33 | "outputs": [], |
34 | 34 | "source": [ |
35 | 35 | "import math\n", |
| 36 | + "\n", |
36 | 37 | "number = 2\n", |
37 | 38 | "math.sqrt(number)" |
38 | 39 | ] |
|
44 | 45 | "outputs": [], |
45 | 46 | "source": [ |
46 | 47 | "import math as m\n", |
| 48 | + "\n", |
47 | 49 | "m.log(number)" |
48 | 50 | ] |
49 | 51 | }, |
|
62 | 64 | "In most cases, the input to matplotlib plotting functions is arrays of numerical types, floats or integers. " |
63 | 65 | ] |
64 | 66 | }, |
65 | | - { |
66 | | - "cell_type": "code", |
67 | | - "execution_count": null, |
68 | | - "metadata": {}, |
69 | | - "outputs": [], |
70 | | - "source": [ |
71 | | - "# The code below installs the latest version of numpy and matplotlib\n", |
72 | | - "!sudo -H pip3 install -U numpy\n", |
73 | | - "!sudo -H pip3 install -U matplotlib" |
74 | | - ] |
75 | | - }, |
76 | 67 | { |
77 | 68 | "cell_type": "code", |
78 | 69 | "execution_count": null, |
79 | 70 | "metadata": {}, |
80 | 71 | "outputs": [], |
81 | 72 | "source": [ |
82 | 73 | "import matplotlib\n", |
| 74 | + "\n", |
83 | 75 | "matplotlib.__version__" |
84 | 76 | ] |
85 | 77 | }, |
|
90 | 82 | "outputs": [], |
91 | 83 | "source": [ |
92 | 84 | "# used to embed plots inside an ipython notebook\n", |
93 | | - "%matplotlib inline \n", |
| 85 | + "%matplotlib inline\n", |
94 | 86 | "import matplotlib.pyplot as plt\n", |
95 | 87 | "\n", |
96 | 88 | "# really simple example:\n", |
97 | | - "y = [1,2,3,4,5,4,3,2,1]\n", |
98 | | - "x = [1,2,3,4,5,6,7,8,9]\n", |
| 89 | + "y = [1, 2, 3, 4, 5, 4, 3, 2, 1]\n", |
| 90 | + "x = [1, 2, 3, 4, 5, 6, 7, 8, 9]\n", |
99 | 91 | "plt.plot(x, y)\n", |
100 | | - "plt.plot([1,2,3,4])\n", |
101 | | - "plt.ylabel('some numbers')\n", |
| 92 | + "plt.plot([1, 2, 3, 4])\n", |
| 93 | + "plt.ylabel(\"some numbers\")\n", |
102 | 94 | "plt.show()" |
103 | 95 | ] |
104 | 96 | }, |
|
110 | 102 | "source": [ |
111 | 103 | "import numpy as np\n", |
112 | 104 | "\n", |
113 | | - "X = np.linspace(0, 10, 101) #create values from 0 to 10, and use 101 values\n", |
| 105 | + "X = np.linspace(0, 10, 101) # create values from 0 to 10, and use 101 values\n", |
114 | 106 | "X" |
115 | 107 | ] |
116 | 108 | }, |
|
123 | 115 | "import numpy as np\n", |
124 | 116 | "import math as math\n", |
125 | 117 | "\n", |
126 | | - "X = np.linspace(0, 10, 100001) #create values from 0 to 10, and use 10001 values\n", |
| 118 | + "X = np.linspace(0, 10, 100001) # create values from 0 to 10, and use 10001 values\n", |
127 | 119 | "Y = []\n", |
128 | 120 | "\n", |
129 | 121 | "for x in X:\n", |
130 | 122 | " y = math.sin(x)\n", |
131 | 123 | " Y.append(y)\n", |
132 | | - " \n", |
133 | | - "plt.plot(X, Y, 'mx')\n", |
134 | | - "plt.title('The Sine Wave')\n", |
135 | | - "plt.xlabel('X')\n", |
136 | | - "plt.ylabel('sin(X)')" |
| 124 | + "\n", |
| 125 | + "plt.plot(X, Y, \"mx\")\n", |
| 126 | + "plt.title(\"The Sine Wave\")\n", |
| 127 | + "plt.xlabel(\"X\")\n", |
| 128 | + "plt.ylabel(\"sin(X)\")" |
137 | 129 | ] |
138 | 130 | }, |
139 | 131 | { |
|
194 | 186 | "source": [ |
195 | 187 | "Y = []\n", |
196 | 188 | "for x in X:\n", |
197 | | - " y = [math.sin(x), math.cos(x), 0.1*x]\n", |
| 189 | + " y = [math.sin(x), math.cos(x), 0.1 * x]\n", |
198 | 190 | " Y.append(y)\n", |
199 | 191 | "\n", |
200 | 192 | "plt.plot(X, Y)\n", |
201 | | - "plt.legend(['sin(x)', 'cos(x)', 'x/10'])" |
| 193 | + "plt.legend([\"sin(x)\", \"cos(x)\", \"x/10\"])" |
202 | 194 | ] |
203 | 195 | }, |
204 | 196 | { |
|
215 | 207 | "outputs": [], |
216 | 208 | "source": [ |
217 | 209 | "plt.plot(Y)\n", |
218 | | - "plt.xlabel('index')\n", |
219 | | - "plt.ylabel('f(x)')\n", |
220 | | - "plt.legend(['sin(x)', 'cos(x)', 'x/10'])" |
| 210 | + "plt.xlabel(\"index\")\n", |
| 211 | + "plt.ylabel(\"f(x)\")\n", |
| 212 | + "plt.legend([\"sin(x)\", \"cos(x)\", \"x/10\"])" |
221 | 213 | ] |
222 | 214 | }, |
223 | 215 | { |
|
238 | 230 | "for x in X:\n", |
239 | 231 | " Y.append(math.sin(x))\n", |
240 | 232 | " Z.append(math.cos(x))\n", |
241 | | - " \n", |
242 | | - "plt.plot(X, Y, 'b-.')\n", |
243 | | - "plt.plot(X, Z, 'r--')\n", |
244 | | - "plt.legend(['sin(x)', 'cos(x)'])" |
| 233 | + "\n", |
| 234 | + "plt.plot(X, Y, \"b-.\")\n", |
| 235 | + "plt.plot(X, Z, \"r--\")\n", |
| 236 | + "plt.legend([\"sin(x)\", \"cos(x)\"])" |
245 | 237 | ] |
246 | 238 | }, |
247 | 239 | { |
|
261 | 253 | "source": [ |
262 | 254 | "vals = [7, 6.2, 3, 5, 9]\n", |
263 | 255 | "xval = [1, 2, 3, 4, 5]\n", |
264 | | - "plt.bar(xval, vals)\n" |
| 256 | + "plt.bar(xval, vals)" |
265 | 257 | ] |
266 | 258 | }, |
267 | 259 | { |
|
280 | 272 | "outputs": [], |
281 | 273 | "source": [ |
282 | 274 | "Y = []\n", |
283 | | - "for x in range(0,100000):\n", |
| 275 | + "for x in range(0, 100000):\n", |
284 | 276 | " Y.append(np.random.randn())\n", |
285 | | - " \n", |
| 277 | + "\n", |
286 | 278 | "plt.hist(Y, 50)" |
287 | 279 | ] |
288 | 280 | }, |
|
310 | 302 | "name": "python", |
311 | 303 | "nbconvert_exporter": "python", |
312 | 304 | "pygments_lexer": "ipython3", |
313 | | - "version": "3.5.2" |
| 305 | + "version": "3.8.2" |
314 | 306 | } |
315 | 307 | }, |
316 | 308 | "nbformat": 4, |
317 | | - "nbformat_minor": 0 |
| 309 | + "nbformat_minor": 1 |
318 | 310 | } |
0 commit comments