Join us and get access to hundreds of tutorials and a community of expert Pythonistas.

Unlock This Lesson

This lesson is for members only. Join us and get access to hundreds of tutorials and a community of expert Pythonistas.

Unlock This Lesson

Hint: You can adjust the default video playback speed in your account settings.
Hint: You can set the default subtitles language in your account settings.
Sorry! Looks like there’s an issue with video playback 🙁 This might be due to a temporary outage or because of a configuration issue with your browser. Please see our video player troubleshooting guide to resolve the issue.

Multiple Glyphs and Adding a Legend

Give Feedback

In this video you will build on top of what you learned in the last video about glyphs. You will create a visualization with multiple glyphs and learn about how to add a legend. Along the way you will practice using numpy and the methods numpy.linspace() and numpy.cumsum().

You can check out much more info about styling legends.


import numpy as np 

# Bokeh libraries
from import output_file
from bokeh.plotting import figure, show

# My word count data
day_num = np.linspace(1, 10, 10)
daily_words = [450, 628, 488, 210, 287, 791, 508, 639, 397, 943]
cumulative_words = np.cumsum(daily_words)

# Output the visualization to 
# a static HTML page my_tutorial_progress.html
output_file('my_tutorial_progress.html', title='My Tutorial Progress')

# Create a figure with a datetime type x-axis
fig = figure(title='My Tutorial Progress',
             x_axis_label='Day Number', 
             y_axis_label='Words Written',
             y_range=(0, 6000),

# The daily words will be represented as vertical bars (columns)
fig.vbar(x=day_num, bottom=0, top=daily_words,
         color='blue', width=0.75, 

# The cumulative sum will be a trend line
fig.line(x=day_num, y=cumulative_words,
         color='gray', line_width=1,

# Put the legend in the upper left corner
fig.legend.location = 'top_left'

# Let's check it out

Cooper Labenske on Aug. 11, 2020

legend is being deprecated. For:


Instead use:


Become a Member to join the conversation.