Trusted answers to developer questions

Python Bokeh line plot

Get Started With Data Science

Learn the fundamentals of Data Science with this free course. Future-proof your career by adding Data Science skills to your toolkit — or prepare to land a job in AI, Machine Learning, or Data Analysis.

Like many Python libraries, Bokeh is a large library with complex commands and detailed representations of many types of plots.

Getting started

In order to get started, you need to make sure you have the library installed on your computer. Write:

pip install bokeh

Bokeh is used for several kinds of plots namely scatter plots, grid plots, and line plots. Let’s see how to make a simple line plot in bokeh.

Bokeh line plot

A line plot is a simple line drawn to represent the frequency of data.

import bokeh
from bokeh.plotting import figure, output_notebook, show
#initialise using some x and y data
'''
These represents the co ordinates of the plot in terms of
x and y like (3,6),(2,4).
'''
x = [3, 2, 1, 11, 15]
y = [6, 4, 2, 22, 30]
# output in notebook environment
output_notebook()
#new plot
'''
figure command draws the figure. Title is the title of your
figure. x and y label represents the x and y size.
store this figure in a variable plt.
'''
plt = figure(title="Bokeh Line Example", x_axis_label='x_value', y_axis_label='y_value')
# add a line to the plot between x and y co ordinates.
# paramters of line
# legend_label - This refers to what does the line represent.
# line_width - The width of the line that is to be plotted.
# line_color - The color of the line that is to be plotted.
plt.line(x, y, legend_label="y = 2x", line_width=3.5, line_color="red")
# show the results using show command.
show(plt)

For this code, x and y are the data points on the x and y-axis. The function figure creates a space for data to be plotted. The .line function draws a line among the data points. The parameters of .line are:

  • legend_label refers to what the line represents.

  • line_width refers to the width of the line to be plotted.

  • line_color refers to the color of the line to be plotted.

For Further Understanding:

RELATED TAGS

bokeh
line plot
bokeh plot
bokeh line plot
figure
Copyright ©2024 Educative, Inc. All rights reserved
Did you find this helpful?