![]() 'x' is the player points, 'y' is the player’s rebounds. The first is the common_figure_kwargs, which will be with the plot_width of 400, an x_axis_label named 'Points', and a toolbar_location you’re going to set to be None so it won’t show up.Ġ4:12 For glyphs, you’ll set up common circle keyword arguments. And what’s nice is you can consolidate all that information into dictionaries and reuse them.Ġ3:37 This will help eliminate redundant code and provide an easy way to tweak parameters using the legends you’re about to set up.Ġ3:49 You’re going to consolidate the common keyword arguments into dictionaries. Cool! All right.Ġ3:28 There are some common parameters that you’re going to use across all the figures, markers, and data. So you create these filters, these grouping filters, that are pulling 'LeBron' and 'James' from first name and last name, and 'Kevin' and 'Durant' from first name and last name from player_gm_stats CDS-column data source-and making this new view. So a lot of this information is going to be the same, so why not repeat this data and say durant_filters and the group will be 'Kevin' and 'Durant'.Ġ3:09 And then here, it’s the durant_view, which will be loading in the durant_filters. And the filters are equal to the lebron_filters you just built. source will be the ColumnDataSource you created, player_gm_stats. And you’re going to do the same basic info, except for it’s going to be the player last name and the grouping will be 'James'.Ġ2:47 And lebron_view is a CDSView. ![]() lebron_filters will be using a GroupFilter with a column_name equal to- and this you might remember-pulling the player first name.Ġ2:28 It should be part of the 'LeBron' group. All right.Ġ2:10 It’s time to create a view for each player. Call it player_gm_stats, and it’s going to use player_stats. Create your output file.Ġ1:43 It’s going to be called 'lebron_vs_durant.html' with a title equal toĠ1:54 'LeBron James vs. From layouts, you’re going to put this all in a row.Ġ1:31 from read_nba_data import player_stats. From models import ColumnDataSource, and for this one you’re going to use CDSView again and GroupFilter.Ġ1:18 Do some of that data management inside of Bokeh instead of creating it externally. ![]() from plotting import figure, show,Ġ1:05 from bokeh.io import output_file. So create a new file that’ll be called InteractiveLegends.py.Ġ0:52 And at the top of your file, you’re going to bring in some libraries. click_policy while the other uses "mute".Ġ0:36 The first step is to create a new file and isolate the data for the two players from the player_stats DataFrame. The only difference will be that one will use a "hide" as its. ![]() Using just a single line of code, you can quickly add the ability to either hide or mute data using your legend.Ġ0:23 For this example, you’re going to create two identical scatter plots comparing the game by game points and rebounds for LeBron James and Kevin Durant. You saw how easy it was to implement a legend when creating a plot.Ġ0:11 When you have a legend in place, adding interactivity is merely a matter of assigning what’s called a. For that, you may remember from a earlier exercise drawing data with glyphs. click_policy = 'mute' # Visualize show ( row ( hide_fig, mute_fig ))Ġ0:00 For the last example, you’re going to create interactive legends. circle ( ** common_circle_kwargs, ** common_durant_kwargs, muted_alpha = 0.1 ) # Add interactivity to the legend hide_fig. circle ( ** common_circle_kwargs, ** common_lebron_kwargs, muted_alpha = 0.1 ) mute_fig. circle ( ** common_circle_kwargs, ** common_durant_kwargs ) mute_fig = figure ( ** common_figure_kwargs, title = 'Click Legend to MUTE Data' ) mute_fig. circle ( ** common_circle_kwargs, ** common_lebron_kwargs ) hide_fig. Kevin Durant' ) # Store the data in a ColumnDataSource player_gm_stats = ColumnDataSource ( player_stats ) # Create a view for each player lebron_filters = lebron_view = CDSView ( source = player_gm_stats, filters = lebron_filters ) durant_filters = durant_view = CDSView ( source = player_gm_stats, filters = durant_filters ) # Consolidate the common keyword arguments in dicts common_figure_kwargs = # Create the two figures and draw the data hide_fig = figure ( ** common_figure_kwargs, title = 'Click Legend to HIDE Data', y_axis_label = 'Rebounds' ) hide_fig. # Bokeh Libraries from otting import figure, show from bokeh.io import output_file from bokeh.models import ColumnDataSource, CDSView, GroupFilter from bokeh.layouts import row # Import the data from read_nba_data import player_stats # Output to a static html file output_file ( 'lebron_vs_durant.html', title = 'LeBron James vs.
0 Comments
Leave a Reply. |