![]() ![]() ![]() For example, If the myapp folder is located inside your desktop/python directory, traverse (cd desktop/python) to the folder on terminal/cmd and run the bokeh serve command. For the plot to appear, run the bokeh serve from the directory where your myapp folder is placed. Now run the bokeh server using bokeh serve –show myapp. add_layout ( labels ) layout = column ( row ( plot )) #add plot to layoutĬurdoc (). Labels = LabelSet ( x = 'x', y = 'y', text = 'player_id', level = 'glyph', x_offset =- 5, y_offset =- 7, source = source, render_mode = 'canvas', text_color = 'white', text_font_size = "10pt" ) plot. scatter ( 'x', 'y', source = source, size = 20, fill_color = 'color' ) #Add labels to the scatter plot visible = False #Plot the player coordinates image_url ( url =, x =- 52.5, y =- 34, w = 105, h = 68, anchor = "bottom_left" ) #x,y,w,h are given based on STATS definition of the dataset Plot = figure ( name = 'base', plot_height = 600, plot_width = 800, title = "Game Animation", tools = "reset,save", x_range =, y_range =, toolbar_location = "below" ) plot. Once the player and team tags are added, we’d have the data as below Once you’ve the data file ready, create the below folder directory, which would be needed to run the bokeh server. Also, an similar dataset can be used (for any sports) as long as you’ve the below columns. Once you get the dataset and have doubts on adding team/player tags, do contact me on twitter/mail. ![]() I’m not going to explain in depth about the data cleaning process. Note that I’ve already done some pre-processing to clean the raw data since the data from STATS doesn’t have player/team tags and we’d have to manually add them. The data used in the viz is not available for public use. You can submit an online request to obtain the dataset from them. The dataset used in the post is from STATS. I could write a separate blog post to outline the process in Matplotlib. But the features of bokeh (compared to matplotlib) makes it a better choice, for this purpose alone. I’ve also tried the same with Matplotlib and it was successful. Bokeh gives a good looking viz in the browser and also provides smooth interface for animation. Also, this post explains the steps to create a toggle button, to show/hide the convex hull plot of the teams. This blog post looks at creating an animation slider (with Play and Pause buttons) to plot 2D coordinates of player movement in a soccer game. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |