Trusted answers to developer questions
Trusted Answers to Developer Questions

Related Tags

python plot
bokeh scatter plot
scatter plot

Python Bokeh scatter plot

Educative Answers Team


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 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 scatter plot in bokeh.

Scatter plot

Scatter plots are used to display all the coordinates of your x-y values onto the graph. It is a type of plot that shows data as a collection of points. A point’s position depends on its two-dimensional value, where each value is positioned on either the horizontal or vertical dimension.

A dataset can have a million values, so scatter plots are used to visualize large pieces of data.

Don't Worry, Bokeh has you covered
Don't Worry, Bokeh has you covered
## Scatter Plot
import bokeh
from bokeh.plotting import figure, output_notebook, show
from random import seed
from random import randint
for i in range(20):
  d = randint(0,30) 
  x_value.append(d) #fill x with random values.
y_value = [4, 11, 27, 23, 24, 20, 18, 13, 1, 4, 14, 5, 15, 2, 5, 16, 13, 5, 10, 8]
#fill y with above values. You can always play around with them.
# paramters of figure
# plot_width - The width of the solution space for plotting.
# plot_height - The height of the solution space for plotting 
a=figure(plot_width = 500, plot_height=500)

# color = 'red' makes sure co-ordinates are of red color., value,size=14,color='red')

# color = 'red' makes sure co-ordinates are of red color., y_value, size=14, color = 'blue')

# show the plot.

# In the circles and diamond you can visualize a scatter plot. There can be thousand of such values.
Code for a simple Bokeh scatter plot

For this code, x and y are the data points on the x and y-axis. The function figure creates a space for the data to be plotted, and the .circle function draws the respective co-ordinates. As you can see in the output, there are co-ordinates that have a circle shape. This function has several parameters, but we have used #key# color(refers to the color of the co-ordinate) and size(refers to the size of the co-ordinates to be plotted) for this example. In order to differentiate between two different datasets, we have written color='blue' and color = 'red'.

For Further Understanding:


python plot
bokeh scatter plot
scatter plot
Copyright ©2022 Educative, Inc. All rights reserved

View all Courses

Keep Exploring