Data Visualization using Python - Plotly and Bokeh


20 Jul
20Jul

Bokeh

Bokeh distinguishes itself from other Python visualization libraries such as Matplotlib or Seaborn in the fact that it is an interactive visualization library that is ideal for anyone who would like to quickly and easily create interactive plots, dashboards, and data applications

  • Bokeh is an interactive visualization library that targets modern web browsers for presentation. 
  • Its goal is to provide elegant, concise construction of versatile graphics, and to extend this capability with high-performance interactivity over very large or streaming datasets. 
  • Bokeh can help anyone who would like to quickly and easily create interactive plots, dashboards, and data applications.
  • Bokeh is a fiscally sponsored project of NumFOCUS, a nonprofit dedicated to supporting the open source scientific computing community
  • To offer both simplicity and the powerful and flexible features needed for advanced customizations, Bokeh exposes two interface levels to users:
    bokeh.models
    A low-level interface that provides the most flexibility to application developers.
    bokeh.plotting
    A higher-level interface centered around composing visual glyphs.

    bokeh.charts 

    A high-level interface for quickly creating statistical charts. The interface includes chart types such as: Bar(), BoxPlot(), Histogram(), TimeSeries(), and many others.

    There are various ways to generate output for Bokeh documents. The commonly used include:

    1. output_file – Generates simple standalone HTML documents for Bokeh visualizations
    2. output_notebook – Displays Bokeh visualizations inline in Jupyter notebook cells

    These functions are most often used together with the show or save functions.


Installation

It is same as we did it for ay other library

conda install bokeh
or
pip install bokeh

You can use Jupiter notebook, Zeppelin or Jupyter Lab to run your bokeh plot code.

Let us now plot some charts which will demonstrate the ease and power of Bokeh plots. Main important feature of bokeh is interactive graphs.  Refer my not notebook for more details.

The  scatter charts, box plots, histograms all can be plotted with bokeh. But important feature is plotting interactive widget. Lets learn little bit more about it.

Bokeh Widgets

Widgets are interactive controls that can be added to Bokeh applications to provide a front end user interface to a visualization. They can drive new computations, update plots, and connect to other programmatic functionality. When used with the Bokeh server, widgets can run arbitrary Python code, enabling complex applications. Widgets can also be used without the Bokeh server in standalone HTML documents through the browser’s Javascript runtime.

To use widgets, you must add them to your document and define their functionality. Widgets can be added directly to the document root or nested inside a layout. There are two ways to program a widget’s functionality:

  • Use the CustomJS callback (see CustomJS for Widgets. This will work in standalone HTML documents.
  • Use bokeh serve to start the Bokeh server and set up event handlers with .on_change (or for some widgets, .on_click).


Start the Bokeh dashboard

Run bokeh serve 

e.g.

Run bokeh serve app.py


Advantages of Bokeh

  • For data scientists, Bokeh is the ideal tool to build statistical charts quickly and easily.
  • But there are also other advantages, such as the various output options and the fact that you can embed your visualizations in applications. 
  • The wide variety of visualization customization options makes this Python library an indispensable tool for your data science toolbox.

Maintained by?

Lets move toward our second library - Plotly

Plotly

Plotly is one of the finest data visualization tools available built on top of visualization library D3.js, HTML and CSS. 

It is created using Python and the Django framework.  One can choose to create interactive data visualizations online or use the libraries that plotly offers to create these visualizations in the language/ tool of choice.

 It is compatible with a number of languages/ tools: R, Python, MATLAB, Perl, Julia, Arduino

Advantages:

  • It lets you create interactive visualizations built using D3.js without even having to know D3.js.
  • It provides compatibility with number of different languages/ tools like R, Python, MATLAB, Perl, Julia, Arduino.
  • Using plotly, interactive plots can easily be shared online with multiple people.
  • Plotly can also be used by people with no technical background for creating interactive plots by uploading the data and using plotly GUI.
  • Plotly is compatible with ggplots in R and Python.
  • It allows to embed interactive plots in  projects or websites using iframes or html.
  • The syntax for creating interactive plots using plotly is very simple as well.

Disadvantages:

  • The plots made using plotly community version are always public and can be viewed by anyone.
  • For plotly community version, there is an upper limit on the API calls per day.
  • There are also limited  number of color Palettes available in community version which acts as an upper bound on the coloring options.

Installation

pip install plotly
For more refer here.