

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. Plt.# 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. Plt.title('Scatter plot showing correlation') Here we will define 2 variables, such that we get some sort of linear relation between themĪ = ī = Example to Implement Matplotlib Scatterįinally, let us take an example where we have a correlation between the variables: Example #1 Z = fig.add_subplot(1, 1, 1, facecolor='#E6E6E6')Įxplanation: So here we have created scatter plot for different categories and labeled them. Z = fig.add_subplot(1, 1, 1, facecolor='#E6E6E6') įor data, color, group in zip(data, colors, groups):

Next let us create our data for Scatter plotĪ1 = (1 + 0.6 * np.random.rand(A), np.random.rand(A))Ī2 = (2+0.3 * np.random.rand(A), 0.5*np.random.rand(A))Ĭolors = (“red”, “green”) Step #2: Next, let us take 2 different categories of data and visualize them using scatter plots. As we mentioned in the introduction of scatter plots, they help us in understanding the correlation between the variables, and since our input values are random, we can clearly see there is no correlation. This is how our input and output will look like in python:Įxplanation: For our plot, we have taken random values for variables, the same is justified in the output. Step #1: We are now ready to create our Scatter plot Next, let us create our data for Scatter plotĪ = np.random.rand(A)ī = np.random.rand(A)Ĭolors = (0,0,0)
