1 00:00:00,000 --> 00:00:04,643 [MUSIC] 2 00:00:04,643 --> 00:00:09,263 If you recall, when we last looked at our plot, we had our legends separated by 3 00:00:09,263 --> 00:00:14,040 color in a continental bucket and I've added in an associated legend. 4 00:00:14,040 --> 00:00:18,782 However, we are still having some issues with our data visualization in terms of 5 00:00:18,782 --> 00:00:22,630 being able to tell which glyph is associated with which country. 6 00:00:22,630 --> 00:00:26,982 Further, will the labels on the x-axis give us a general idea of the population, 7 00:00:26,982 --> 00:00:31,097 it would be helpful to know the exact number associated with a given country. 8 00:00:31,097 --> 00:00:34,449 With glyphs representing all of our countries and 9 00:00:34,449 --> 00:00:37,251 several of them plotted close together. 10 00:00:37,251 --> 00:00:40,877 Adding labels to each glyph would clutter up our visualization. 11 00:00:40,877 --> 00:00:45,044 Bokeh provides a solution to this with hover tools, which will allow us to hover 12 00:00:45,044 --> 00:00:49,168 over a given data point and have the associated data shown about that country. 13 00:00:49,168 --> 00:00:51,211 Let's have a look from where we left off. 14 00:00:51,211 --> 00:00:56,200 To start working with hover tools, we need to import HoverTool from bokeh.models. 15 00:00:56,200 --> 00:00:58,494 If you remember back to previous video, 16 00:00:58,494 --> 00:01:01,130 we had a parameter tools in our figure object. 17 00:01:01,130 --> 00:01:03,016 We're going to want to add that back in, 18 00:01:03,016 --> 00:01:06,688 along with the tools we want to include with the new addition of our hover tool. 19 00:01:06,688 --> 00:01:09,493 Fit to our plot 20 00:01:10,556 --> 00:01:15,443 Put in tools, we want pan, 21 00:01:15,443 --> 00:01:20,544 wheel_zoom, box_zoom, 22 00:01:20,544 --> 00:01:25,439 reset, hover, and save. 23 00:01:25,439 --> 00:01:30,298 That adds in our hover tool to the other tools we have seen and are used to. 24 00:01:30,298 --> 00:01:34,110 I think it is probably time as well to add a title to our plot, 25 00:01:34,110 --> 00:01:39,247 which can be done with the title parameter being passed into our figure object. 26 00:01:39,247 --> 00:01:45,382 We'll call it Population versus Life Expectancy. 27 00:01:45,382 --> 00:01:51,630 And we're still showing our plot and have all the same configurations for 28 00:01:51,630 --> 00:01:56,880 our color mapper and for our legend and when we run our script. 29 00:02:00,079 --> 00:02:01,370 And hover over our data points. 30 00:02:01,370 --> 00:02:04,900 We got a nice little pop-out tool tip, giving us some information. 31 00:02:04,900 --> 00:02:06,610 So, it is slightly helpful, right? 32 00:02:06,610 --> 00:02:10,707 It shows us the index number, the x and y values of our charted data, or 33 00:02:10,707 --> 00:02:15,580 population and life expectancy, and the data points on the plot itself. 34 00:02:15,580 --> 00:02:20,397 Now we could use that index number to go look in our data to determine 35 00:02:20,397 --> 00:02:23,158 that index 39 for example is China. 36 00:02:23,158 --> 00:02:24,964 However, I don't know about you, but 37 00:02:24,964 --> 00:02:28,431 that seems like a lot off effort to have to look up each point in our raw data. 38 00:02:28,431 --> 00:02:32,499 Let's connect the information from our raw data directly to the tool tip. 39 00:02:32,499 --> 00:02:37,298 We need to select our hover tools, and adjust it's visual attributes. 40 00:02:37,298 --> 00:02:41,108 Since it is assigned to our figure object, we can select it as follows. 41 00:02:44,990 --> 00:02:52,430 Hover=plot.select_one and we'll assign it for HoverTool. 42 00:02:52,430 --> 00:02:58,159 Let's take a quick look at the documentation for styling tools in Bokeh. 43 00:02:58,159 --> 00:03:01,998 I've included a link in the teacher's notes to the Bokeh documentation as well. 44 00:03:01,998 --> 00:03:05,744 If we scroll down about two thirds of the way on the page, 45 00:03:05,744 --> 00:03:09,277 we will find a section called setting tool visuals. 46 00:03:09,277 --> 00:03:11,450 And on the hover tool section there, 47 00:03:11,450 --> 00:03:15,456 it shows us that we want to pass in a list of couples into our tool tip. 48 00:03:15,456 --> 00:03:20,309 Now we can access our data items is in the @ sign special character. 49 00:03:20,309 --> 00:03:22,339 I think for this particular plot, 50 00:03:22,339 --> 00:03:26,889 adding in the country name in English as well as the values of our data points, 51 00:03:26,889 --> 00:03:31,241 populations and life expectancy, would be a good start for our tool tip. 52 00:03:31,241 --> 00:03:33,345 We want to assign to hover.tooltips. 53 00:03:44,194 --> 00:03:46,220 Country name in English, which is the label for that. 54 00:03:54,701 --> 00:03:55,900 And assign their data point. 55 00:03:59,100 --> 00:04:00,031 We'll do this thing for Population. 56 00:04:11,770 --> 00:04:16,310 And Life Expectancy, in years. 57 00:04:24,951 --> 00:04:28,999 Now when we run our script and hover over our data point, 58 00:04:28,999 --> 00:04:34,531 we get the country name, population, and life expectancy in our tool tip. 59 00:04:34,531 --> 00:04:37,672 You'll notice that if we hover over some of the densely charted data, 60 00:04:37,672 --> 00:04:41,293 we will get multiple tool tips covering a range of countries that are pretty close 61 00:04:41,293 --> 00:04:42,747 to where the mouse is pointing. 62 00:04:42,747 --> 00:04:49,619 This is a great opportunity to use some of the zoom tools, To zoom in on 63 00:04:49,619 --> 00:04:54,520 an area of our plot and to be able to get a closer look at individual country data. 64 00:04:58,722 --> 00:05:02,540 When we're done, we can click on the reset tool to reset our display. 65 00:05:04,548 --> 00:05:05,807 Nice work. 66 00:05:05,807 --> 00:05:10,518 I think just looking great and is much easier to gather information from and 67 00:05:10,518 --> 00:05:14,201 about our data set versus looking at rows and rows of data. 68 00:05:14,201 --> 00:05:17,725 We can take up visualization a bit further though and 69 00:05:17,725 --> 00:05:20,619 examine other aspects of our data as well. 70 00:05:20,619 --> 00:05:23,852 Let's have a short break, stand up move around and stretch a bit and 71 00:05:23,852 --> 00:05:26,234 come back to see some options Bokeh provides us for 72 00:05:26,234 --> 00:05:29,770 charting multiple data points from the same data source at the same time.