Python data visualization with Bokeh

Share
  • February 12, 2020

Even though Python has been originally released almost three decades ago, in 1991, by Guido van Rossum, during the past few years it has gained a lot of traction during the past few years due to the availability of complex Big Data, Machine Learning and Artificial Intelligence libraries.

One of them, Bokeh, launched roughly 6 years and is a modern interactive visualization library that can be used in modern web browsers. By using it, you can create user-friendly, elegant, and dynamic graphics. A very important benefit of this library is the fact that it enables high-performance interactivity over large datasets, regardless of their nature, static or dynamic.

Here are the steps you need to go through if you are looking to visualize your data using Bokeh:

SEE ALSO: Python package Detecto released for simple video object detection

Prepare the data

Before you prepare the visualization of your data, it’s very important that you prepare it thoroughly. For example, if you have a batch of data containing information about 100,000 cars and you want to evidentiate the correlations between their fuel type, engine size, and fuel consumption. It is very important that all those 100,000 or a large majority of them have all this information.

If they have them, it’s important to extract only that certain information into another, smaller data set. Each car might have 20 or 30 different variables, but you only need three of them, that’s why you need to create a smaller and more precise data set.

Static HTML vs inline visualization in Jupyter Notebook

Once you prepared your set or sets of data, you need to decide whether you want your API to deliver static HTML or the raw data. The static HTML files will be rendered by the web browsers as they arrive. This puts more stress on the server because it needs to manipulate the data and create a static HTML, but the user won’t have any ‘downtime’ when the HTML is rendered.

On the other hand, if you are opting for inline visualization using libraries, such as Jupyter Notebook, the API will send the raw data and the front end of your application will manipulate it and render it. The stress on the API is lower because it doesn’t have to manipulate the data, it will only send it in a raw format, but the UI might not be as fast.

Create the user interface for your dataset

Creating the user interface for your dataset refers to the process of creating the elements that will be displayed on the user interface. For example, if you are looking to mark each car’s information with a different dot or other sign, this is the process that will take care of that.

During this step, you create the legend of your visualization and you provide all the information a user should need in order to be able to read the data that you are looking to highlight.

Plug-in the data to the user interface

Now that you’ve prepared your datasets and the user interface is looking the way you like, it’s time to combine the dataset and the user interface using Bokeh’s renderers to shape your data. This library offers a lot of flexibility when drawing the data because it has lots of markers and shape options available, all of them being very easy to customize.

Also, Bokeh offers a few native functionalities like bar charts, maps, and network graphs.

Define the layout of your user interface

Considering the complexity a dataset can have, you probably need more than one chart, pie, maps or graph, whatever type of representation you are using.

The Bokeh library offers both standard representations, such as grid-like layouts and tabbed layouts, which you can easily organize with a minimum amount of time spent. It all depends on the amount of information you are looking to highlight, its complexity, and the people you are targeting through your visualizations.

SEE ALSO: CodinGame 2020 developer survey says Python is the most loved programming language

Save and preview your masterpiece

Right, you’ve created a new dataset that contains only the information you need for your visualization, then you’ve used static HTML to render the information, you’ve created the user interface of your visualization, and defined the entire layout. Now, it’s time to save your data visualization to an image file. If you are not pleased with the result, you can always go through these steps and create your visualization all over again.

Conclusion

During the past years, Python has become a very popular language because it has lots of useful implementations. For example, a developer looking to present large and complex datasets can use Python together with the Bokeh library. This combination can help him represent information easily. If you are looking to use the two, go through these steps and you will be able to create top-notch visualizations of datasets.

The post Python data visualization with Bokeh appeared first on JAXenter.

Source : JAXenter