Plotting with glyphs

Usually, a plot consists of geometric shapes either in the form of a line, circle, etc. So, Glyphs are nothing but visual shapes that are drawn to represent the data such as circles, squares, lines, rectangles, etc.  

Creating a basic line chart:

The line chart displays the visualization of x and y-axis points movements in the form of a line. To draw a line glyph to the figure, we use the line() method of the figure object.

Syntax:

 my_plot.line(a, b, line_width)  

Code:                  

Python




# import the libraries
from bokeh.plotting import figure, show, output_file
 
# prepare some data
a = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
b = [2, 4, 6, 8, 10, 12, 14, 16, 18, 20]
 
# create a plot using figure
my_plot = figure(title="simple line chart", x_axis_label="X-Axis",
                 y_axis_label="Y-Axis")
 
# adding line graph
my_plot.line(a, b, line_width=3)
 
# display output in file
output_file("line.html")
 
# show the result
show(my_plot)


Output: 

Combining multiple graphs

You can also add multiple graphs with the use of bokeh.plotting interface. To do so, you just need to call the line() function multiple times by passing different data as parameters as shown in the example.

Syntax:

p.line(x1, y2, legend_label, line_color, line_width)

Code:

Python




from bokeh.plotting import figure, show
from bokeh.io import output_notebook
 
 
# prepare some data
x1 = [1, 3, 4, 5, 6]
x2 = [5, 3, 8, 1, 8]
y1 = [6, 7, 8, 9, 4]
y2 = [3, 4, 5, 6, 7]
 
# create a new plot
p = figure(title="Drawing multiple lines",
           x_axis_label="X-Axis", y_axis_label="Y-Axis")
 
# add multiple renderers
p.line(x1, y1, legend_label="line 1", line_color="red", line_width=1)
p.line(x2, y2, legend_label="line 2", line_color="blue", line_width=1)
p.line(x1, y2, legend_label="line 3", line_color="black", line_width=1)
 
output_notebook()
show(p)


Output:

Glyphs in Bokeh

Bokeh is a library of Python which is used to create interactive data visualizations. In this article, we will discuss glyphs in Bokeh. But at first let’s see how to install Bokeh in Python.

Similar Reads

Installation

To install this type the below command in the terminal....

Plotting with glyphs

Usually, a plot consists of geometric shapes either in the form of a line, circle, etc. So, Glyphs are nothing but visual shapes that are drawn to represent the data such as circles, squares, lines, rectangles, etc....

Rendering Circles

...

Rendering Bars

...

Patch Glyph

In order to add the circle glyph to your plot, we use the circle() method instead of the line() method used in the above example....