1 00:00:00,520 --> 00:00:04,480 Let's start our journey by installing matplotlib in a Jupyter Notebook. 2 00:00:04,480 --> 00:00:08,640 Fortunately, that is relatively straightforward by using pip. 3 00:00:08,640 --> 00:00:10,145 Let's kick off jupyter notebooks. 4 00:00:15,847 --> 00:00:17,657 If you aren't familiar with Jupyter Notebooks, 5 00:00:17,657 --> 00:00:20,280 check out the teacher's notes for more information. 6 00:00:20,280 --> 00:00:23,483 We'll start a new notebook here in the matplotlib directory I created for 7 00:00:23,483 --> 00:00:24,111 this course. 8 00:00:29,230 --> 00:00:32,090 And we'll install our matplotlib package. 9 00:00:32,090 --> 00:00:34,957 The syntax is slightly different here. 10 00:00:34,957 --> 00:00:36,372 We import sys, 11 00:00:44,850 --> 00:00:48,868 Pip install matplotlib. 12 00:00:48,868 --> 00:00:50,120 And then we can run our cell. 13 00:00:52,270 --> 00:00:57,320 Just make sure in notebooks that you are running the pip version associated with 14 00:00:57,320 --> 00:01:01,380 the current Python kernel and can be used in the current notebook. 15 00:01:01,380 --> 00:01:04,340 I already had matplotlib installed in this environment. 16 00:01:04,340 --> 00:01:06,710 Now that we have the matplot library installed, 17 00:01:06,710 --> 00:01:12,250 we want to import the pyplot module, which allows us to quickly generate our plots. 18 00:01:12,250 --> 00:01:14,955 It’s convention to import this as plt. 19 00:01:26,476 --> 00:01:28,870 Now, we can pass in a list of matplotlib. 20 00:01:30,080 --> 00:01:32,690 It'll assume that it's a sequence of y values and 21 00:01:32,690 --> 00:01:35,700 will auto generate the x values for us. 22 00:01:35,700 --> 00:01:37,990 We wanted to show some output, right? 23 00:01:37,990 --> 00:01:40,590 For that, we can use the show method. 24 00:01:40,590 --> 00:01:44,350 So, plt.plot([1, 2, 3, 4]) 25 00:01:47,490 --> 00:01:50,861 And then, plt.show and run our cell. 26 00:01:56,158 --> 00:02:01,670 Matplotlib generates our plot and shows it below our notebook work space. 27 00:02:01,670 --> 00:02:05,669 It provides a simple line graph with a default blue solid line. 28 00:02:05,669 --> 00:02:09,533 But wait a moment, why does our x-range end at 3? 29 00:02:09,533 --> 00:02:11,997 Recall that Python ranges start at 0. 30 00:02:11,997 --> 00:02:15,815 So our x data here is 0, 1, 2, 3. 31 00:02:15,815 --> 00:02:20,427 We can pass in an equal length argument and have an x and y pairing as well. 32 00:02:20,427 --> 00:02:25,141 Let's also add a label to our y-axis here to get used to 33 00:02:25,141 --> 00:02:27,713 adding labels to our charts. 34 00:02:27,713 --> 00:02:31,398 So we'll add in our x-values 1, 4, 9, 35 00:02:31,398 --> 00:02:37,866 16, plt.ylabel. 36 00:02:40,830 --> 00:02:42,631 These are very important figures. 37 00:02:46,369 --> 00:02:47,240 And run our cell, again. 38 00:02:48,330 --> 00:02:50,840 Now we see a line with our x and y pairings. 39 00:02:50,840 --> 00:02:52,660 There are additional parameters we can pass or 40 00:02:52,660 --> 00:02:56,370 plot method in addition to our xy pair values. 41 00:02:56,370 --> 00:03:00,521 Some of which allow for the customization of the color and style of the plot. 42 00:03:03,220 --> 00:03:05,067 Let's turn the line green. 43 00:03:08,770 --> 00:03:14,198 And the linestyle, let's do dashdot and run our cell. 44 00:03:16,135 --> 00:03:20,401 The color argument accepts HTML color names and code values, 45 00:03:20,401 --> 00:03:26,160 a tuple of RGB values, grey scale values, and shortcode values. 46 00:03:26,160 --> 00:03:28,000 I've included a link in the teacher's notes for 47 00:03:28,000 --> 00:03:32,550 complete list of color options as well as linestyle possibilities. 48 00:03:32,550 --> 00:03:36,260 What if we want to display multiple pieces of data on the same plot? 49 00:03:36,260 --> 00:03:40,020 We can just add another plot method to our PLT object and 50 00:03:40,020 --> 00:03:42,408 it will display both data series. 51 00:03:47,310 --> 00:03:53,588 Let's do 2, 3, 4, 5, very creative here, and 2, 3, 4, 5. 52 00:03:56,091 --> 00:04:01,441 Let's make this one hex value 2B5B84. 53 00:04:05,974 --> 00:04:08,467 And we'll do a linestyle of dashed. 54 00:04:11,740 --> 00:04:12,530 And run our cell. 55 00:04:14,670 --> 00:04:19,970 As you might imagine, having multiple data series on same plot can get confusing. 56 00:04:19,970 --> 00:04:22,520 Let's see if we can add some clarity in our next video.