Session Ready
Exercise

The Bokeh ColumnDataSource (continued)

You can create a ColumnDataSource object directly from a Pandas DataFrame by passing the DataFrame to the class initializer.

In this exercise, we have imported pandas as pd and read in a data set containing all Olympic medals awarded in the 100 meter sprint from 1896 to 2012. A color column has been added indicating the CSS colorname we wish to use in the plot for every data point.

Your job is to import the ColumnDataSource class, create a new ColumnDataSource object from the DataFrame df, and plot circle glyphs with 'Year' on the x-axis and 'Time' on the y-axis. Color each glyph by the color column.

The figure object p has already been created for you.

Instructions
100 XP
  • Import the ColumnDataSource class from bokeh.plotting.
  • Use the ColumnDataSource() function to make a new ColumnDataSource object called source from the DataFrame df.
  • Use p.circle() to plot circle glyphs on the figure p with 'Year' on the x-axis and 'Time' on the y-axis.
    • Make the size of the circles 8, and use color='color' to ensure each glyph is colored by the color column.
    • Make sure to specify source=source so that the ColumnDataSource object is used.