Like many Python libraries, Bokeh is a large library with complex commands and detailed representations of many types of plots.
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 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.
## Scatter Plotimport bokehfrom bokeh.plotting import figure, output_notebook, showfrom random import seedfrom random import randintseed(1)x_value=[]y_value=[]for i in range(20):d = randint(0,30)x_value.append(d) #fill x with random values.seed(1)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.key=[1,4,7,9,22]value=[6,1,3,10,15]# paramters of figure# plot_width - The width of the solution space for plotting.# plot_height - The height of the solution space for plottinga=figure(plot_width = 500, plot_height=500)# color = 'red' makes sure co-ordinates are of red color.a.circle(key, value,size=14,color='red')# color = 'red' makes sure co-ordinates are of red color.a.circle(x_value, y_value, size=14, color = 'blue')# show the plot.show(a)# In the circles and diamond you can visualize a scatter plot. There can be thousand of such values.
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: