Patch Glyph

The patch glyph shades a region of space in a particular color. We use the patch() method to develop a single patch and patches() method to develop multiple patches.

Single patch

Syntax:

p.patch(x, y, fill_color, line_color, alpha, line_width)

Code:

Python




# Bokeh libraries
from bokeh.plotting import figure, show, output_file
 
# data
x = [1, 2, 3, 4, 5]
y = [6, 7, 8, 5, 2]
 
# Create a figure
p = figure(title='Patch Glyph',
           plot_height=400, plot_width=600,
           x_axis_label='x', y_axis_label='y',
           toolbar_location=None)
 
# add patch glyph
p.patch(x, y, fill_color="blue", line_color='black',
        alpha=0.5, line_width=2)
 
# show the results
show(p)
output_file("ex.html")


Output: 

Multiple Patches

Multiple patches can be created in a similar way by using the function patches() instead of patch(). We are passing the data in the form of a list of arrays for creating three patches with different colors in the example shown below.

Code:

Python




# Bokeh libraries
from bokeh.plotting import figure, show, output_file
 
# data
x = [[1, 2, 3], [4, 6, 8], [2, 4, 5, 4]]
y = [[2, 5, 6], [3, 6, 7], [2, 4, 7, 8]]
 
# Create a figure
p = figure(title='Patch Glyph',
           plot_height=400, plot_width=600,
           x_axis_label='x', y_axis_label='y',
           toolbar_location=None)
 
# add patches glyph
p.patches(x, y, fill_color=["blue", "green", "yellow"], line_width=2)
 
# show the results
show(p)
output_file("ex.html")


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....

Contact Us