Rendering Bars

Similarly, we can render bars using vbar() function for vertical bars and hbar() function for horizontal bars.

Creating vbar

To draw vbar, we specify center x-coordinate, bottom, and top endpoints as shown in the below example:

Syntax:

p.vbar(x, bottom, top,
color, width, fill_color,legend_label)

Code:      

Python




# Bokeh libraries
from bokeh.io import output_notebook
from bokeh.plotting import figure, show
 
# data
day = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
no_orders = [450, 628, 488, 210, 287,
             791, 508, 639, 397, 943]
 
# Output the visualization directly in the notebook
output_notebook()
 
# Create a figure
p = figure(title='Bar chart',
           plot_height=400, plot_width=600,
           x_axis_label='Day', y_axis_label='Orders Received',
           x_minor_ticks=2, y_range=(0, 1000),
           toolbar_location=None)
 
# The daily orders will be represented as vertical
# bars (columns)
p.vbar(x=day, bottom=0, top=no_orders,
       color='blue', width=0.75, fill_color='red',
       legend_label='Orders')
 
# Let's check it out
show(p)


Output:

Creating hbar

To draw hbar , we specify center y-coordinate, left and right endpoints, and height as shown in the below example:

Syntax:

p.hbar(y, height, left, right,
 color, width, fill_color,
legend_label)

Example Code:

Python




# Bokeh libraries
from bokeh.plotting import figure, show, output_file
 
# data
day = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
no_orders = [450, 628, 488, 210, 287, 791,
             508, 639, 397, 943]
 
# Create a figure
p = figure(title='Bar chart',
           plot_height=400, plot_width=600,
           x_axis_label='Orders Received', y_axis_label='Day',
           x_range=(0, 1000), toolbar_location=None)
 
# The daily orders will be represented as
# horizontal bars
p.hbar(y=day, height=0.5, left=0, right=no_orders,
       color='blue', width=0.75, fill_color='red',
       legend_label='Orders')
 
# Let's check it out
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