Bokeh tutorial

1.2 Plotting - Timeseries

Exercise: Reproduce the timeseries chart using the plotting interface

  • Data: 'data/Land_Ocean_Monthly_Anomaly_Average.csv'

Note: Don't worry about styling right now. We'll go over plot properties in the next exercise


In [ ]:
import pandas as pd
from bokeh.plotting import figure, show, output_notebook

In [ ]:
# Get data

In [ ]:
# Process data

In [ ]:
# Output option

In [ ]:
# Create your plot

In [ ]:
# Show plot

Exercise: Style the plot appropriately

Ideas:

  • Axis type and format
  • Line colors
  • Legend
  • Grid lines
  • Axis labels
  • Width and height
  • Remove toolbar

Tips:

bokeh.models.DatetimeTickFormatter()

Note: You can create a new figure to see observe the differences.


In [ ]:
from bokeh.models import DatetimeTickFormatter
import math

In [ ]:
# Axis type, width and height

In [ ]:
# Line colors and legend

In [ ]:
# Axis format (e.g tick format and orientation)

In [ ]:
# Axis labels

In [ ]:
# Legend position

In [ ]:
# Grid style

In [ ]:
# Remove toolbar

In [ ]:
# Show plot

Exercise: Add a crosshair and hover tool to the plot


In [ ]:
from bokeh.models import ColumnDataSource, HoverTool
from collections import OrderedDict

In [ ]:
# List all the tools that you want in your plot separated by comas, all in one string.

In [ ]:
# Add the tools to your figure

In [ ]:
# The hover tools doesn't render datetime appropriately. We'll need a string.

In [ ]:
# To reference variables in the hover box, we'll need to use bokeh.ColumnDataSource instead of a pd.DataFrame

In [ ]:
# Change plotting.line to get values from ColumnDataSource

In [ ]:
# Set hover tool

In [ ]:
# Copy your style from the previous exercise

In [ ]:
# Show plot

[OPTIONAL] Exercise: Style the hover tooltip