How can Bokeh be used to create step line plot in Python?


Bokeh is a Python package that helps in data visualization. It is an open source project. Bokeh renders its plot using HTML and JavaScript. This indicates that it is useful while working with web−based dashboards.

Bokeh can be easily used in conjunction with NumPy, Pandas, and other Python packages. It can be used to produce interactive plots, dashboards, and so on.

Dependencies of Bokeh −

Numpy
Pillow
Jinja2
Packaging
Pyyaml
Six
Tornado
Python−dateutil

Installation of Bokeh on Windows command prompt

pip3 install bokeh

Installation of Bokeh on Anaconda prompt

conda install bokeh

The ‘step’ function present in glyph function is used to generate discrete data points.

Example

from bokeh.plotting import figure, output_file, show
output_file("stepLine.html")
p = figure(plot_width=500, plot_height=300)

p.step([2, 5, 3, 6, 7,9], [6,3, 2, 1, 0, 5], line_width=2, mode="center")

show(p)

Output

Explanation

  • The required packages are imported, and aliased.

  • The figure function is called along with plot width and height.

  • The ‘output_file’ function is called to mention the name of the html file that will be generated.

  • The ‘step’ function present in Bokeh is called, along with data.

  • It helps render the steps.

  • The ‘show’ function is used to display the plot.

Updated on: 19-Jan-2021

111 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements