1 00:00:00,110 --> 00:00:03,560 When we left off, we had a couple of lines plotted on our chart, but 2 00:00:03,560 --> 00:00:06,410 no reference as to what either line was. 3 00:00:06,410 --> 00:00:09,432 This is where legends can come in handy. 4 00:00:09,432 --> 00:00:14,620 Fortunately, matplotlib makes this easy to implement as well. 5 00:00:14,620 --> 00:00:16,820 We add labels to our data series and 6 00:00:16,820 --> 00:00:20,290 call the legend method on the plot object before we show it. 7 00:00:23,260 --> 00:00:28,395 So our label, we'll just call this dash-dot, 8 00:00:31,740 --> 00:00:39,060 And dashed, and then call a legend method and run our cell. 9 00:00:41,100 --> 00:00:44,824 And there we have a nice legend for our chart. 10 00:00:44,824 --> 00:00:47,340 There are several options available for the legend. 11 00:00:47,340 --> 00:00:48,890 We can change the location and 12 00:00:48,890 --> 00:00:52,550 styling on the legend with some attributes in the legend method. 13 00:00:53,570 --> 00:00:55,620 I won't go into all those right now, but 14 00:00:55,620 --> 00:00:58,880 we'll see some of them implemented throughout this course. 15 00:00:58,880 --> 00:01:02,690 I'll put a link in the teacher's notes for more information as well. 16 00:01:02,690 --> 00:01:06,210 One thing I do want to show you here is the idea of subplots. 17 00:01:06,210 --> 00:01:09,940 This allows for multiple plots to be displayed in the same window. 18 00:01:09,940 --> 00:01:14,660 We use the subplot method on our plot object, and pass in the number of rows, 19 00:01:14,660 --> 00:01:18,580 columns and which panel a particular plot is going to reside in. 20 00:01:18,580 --> 00:01:20,959 Let's try this in a new notebook cell. 21 00:01:29,940 --> 00:01:31,419 So we'll create the first panel. 22 00:01:34,246 --> 00:01:37,865 Plot subplot, again, rows, columns. 23 00:01:37,865 --> 00:01:40,703 So two rows, one column, and this is the first panel. 24 00:01:46,084 --> 00:01:48,674 We'll use the same x and y values, 25 00:01:54,177 --> 00:01:58,368 And 16 color, we'll keep as green. 26 00:02:02,838 --> 00:02:07,142 And we'll keep the first panel to be dashdot. 27 00:02:13,100 --> 00:02:18,947 And for the second panel, We want, 28 00:02:18,947 --> 00:02:22,977 again, two rows, one column, and this is the second panel. 29 00:02:31,760 --> 00:02:33,011 Two, three, four and five. 30 00:02:37,360 --> 00:02:41,761 Let's use that same hex value, 2B5B84 31 00:02:51,040 --> 00:02:55,062 And call the show method, and run our cell. 32 00:02:58,795 --> 00:03:02,596 Very nice, there's one thing to consider with this image though and 33 00:03:02,596 --> 00:03:04,720 that's chart scale. 34 00:03:04,720 --> 00:03:07,280 Both images look like they have the same slope, 35 00:03:07,280 --> 00:03:12,480 and hereby represent themselves as being of similar importance. 36 00:03:12,480 --> 00:03:16,270 However, when we look at the numeric values of their axis, 37 00:03:16,270 --> 00:03:18,310 we see they are very different. 38 00:03:18,310 --> 00:03:21,110 Let's update the scale of out two plots here to make their 39 00:03:21,110 --> 00:03:23,200 axis have the same values. 40 00:03:23,200 --> 00:03:28,802 We do that by setting limits on our x and y axis with the set_xlim and 41 00:03:28,802 --> 00:03:31,540 set_ylim methods. 42 00:03:31,540 --> 00:03:35,750 We pass in a list of the starting and ending values for our axes, 43 00:03:35,750 --> 00:03:41,070 this constrains our charts to those dimensions along the x and, or y axis. 44 00:03:41,070 --> 00:03:42,286 Let's see this in action. 45 00:03:45,218 --> 00:03:46,270 Let's make this a variable. 46 00:03:49,400 --> 00:03:54,264 Save some typing, 47 00:03:54,264 --> 00:04:02,780 panel_1 will set xlim 0 to 6. 48 00:04:08,570 --> 00:04:12,403 Ylim 0 and 20. 49 00:04:12,403 --> 00:04:19,999 So again, the x limit will now be between 0 and 6 and the y limit will be 0 to 20. 50 00:04:21,750 --> 00:04:25,500 Let's do this same thing for second panel. 51 00:04:28,483 --> 00:04:29,091 Panel_2, 52 00:04:38,339 --> 00:04:39,309 0 and 6. 53 00:04:45,687 --> 00:04:47,345 0 and 20. 54 00:04:52,019 --> 00:04:52,910 And run our cell. 55 00:04:57,987 --> 00:05:02,964 Now that we've normalized the scale of the plot, we see that the slope of line in 56 00:05:02,964 --> 00:05:07,980 the upper plot is actually much steeper than that of the lower line. 57 00:05:07,980 --> 00:05:11,880 We'll continue to discuss scale throughout the course. 58 00:05:11,880 --> 00:05:14,860 It's an important aspect of data [INAUDIBLE] reporting. 59 00:05:14,860 --> 00:05:19,670 With some matplotlib basics down, I think this is a great place for a break. 60 00:05:19,670 --> 00:05:23,970 Next, we'll discuss some of the chart options available and why and 61 00:05:23,970 --> 00:05:25,520 when we would use each one.