The Wayback Machine - https://web.archive.org/web/20240914152624/https://www.geeksforgeeks.org/python-data-visualization-using-bokeh/
Open In App

Python – Data visualization using Bokeh

Last Updated : 22 May, 2024
Summarize
Comments
Improve
Suggest changes
Like Article
Like
Save
Share
Report
News Follow

Bokeh is a data visualization library in Python that provides high-performance interactive charts and plots. Bokeh output can be obtained in various mediums like notebook, html and server. It is possible to embed bokeh plots in Django and flask apps.

Bokeh provides two visualization interfaces to users:

bokeh.models : A low level interface that provides high flexibility to application developers.
bokeh.plotting : A high level interface for creating visual glyphs.

To install bokeh package, run the following command in the terminal:

pip install bokeh

The dataset used for generating bokeh graphs is collected from Kaggle.

Code #1: Scatter Markers
To create scatter circle markers, circle() method is used.




# import modules
from bokeh.plotting import figure, output_notebook, show
  
# output to notebook
output_notebook()
  
# create figure
p = figure(plot_width = 400, plot_height = 400)
  
# add a circle renderer with
# size, color and alpha
p.circle([1, 2, 3, 4, 5], [4, 7, 1, 6, 3], 
         size = 10, color = "navy", alpha = 0.5)
  
# show the results
show(p) 


Output :

Code #2: Single line
To create a single line, line() method is used.




# import modules
from bokeh.plotting import figure, output_notebook, show
  
# output to notebook
output_notebook()
  
# create figure
p = figure(plot_width = 400, plot_height = 400)
   
# add a line renderer
p.line([1, 2, 3, 4, 5], [3, 1, 2, 6, 5], 
        line_width = 2, color = "green")
  
# show the results
show(p)


Output :

Code #3: Bar Chart
Bar chart presents categorical data with rectangular bars. The length of the bar is proportional to the values that are represented.




# import necessary modules
import pandas as pd
from bokeh.charts import Bar, output_notebook, show
  
# output to notebook
output_notebook()
  
# read data in dataframe
df = pd.read_csv(r"D:/kaggle/mcdonald/menu.csv")
  
# create bar
p = Bar(df, "Category", values = "Calories",
        title = "Total Calories by Category", 
                        legend = "top_right")
  
# show the results
show(p)


Output :

Code #4: Box Plot
Box plot is used to represent statistical data on a plot. It helps to summarize statistical properties of various data groups present in the data.




# import necessary modules
from bokeh.charts import BoxPlot, output_notebook, show
import pandas as pd
  
# output to notebook
output_notebook()
  
# read data in dataframe
df = pd.read_csv(r"D:/kaggle / mcdonald / menu.csv")
  
# create bar
p = BoxPlot(df, values = "Protein", label = "Category", 
            color = "yellow", title = "Protein Summary (grouped by category)",
             legend = "top_right")
  
# show the results
show(p)


Output :

Code #5: Histogram
Histogram is used to represent distribution of numerical data. The height of a rectangle in a histogram is proportional to the frequency of values in a class interval.




# import necessary modules
from bokeh.charts import Histogram, output_notebook, show
import pandas as pd
  
# output to notebook
output_notebook()
  
# read data in dataframe
df = pd.read_csv(r"D:/kaggle / mcdonald / menu.csv")
  
# create histogram
p = Histogram(df, values = "Total Fat",
               title = "Total Fat Distribution", 
               color = "navy")
  
# show the results
show(p) 


Output :

Code #6: Scatter plot
Scatter plot is used to plot values of two variables in a dataset. It helps to find correlation among the two variables that are selected.




# import necessary modules
from bokeh.charts import Scatter, output_notebook, show
import pandas as pd
  
# output to notebook
output_notebook()
  
# read data in dataframe
df = pd.read_csv(r"D:/kaggle / mcdonald / menu.csv")
  
# create scatter plot
p = Scatter(df, x = "Carbohydrates", y = "Saturated Fat",
            title = "Saturated Fat vs Carbohydrates",
            xlabel = "Carbohydrates", ylabel = "Saturated Fat",
            color = "orange")
   
# show the results
show(p) 


Output :




Previous Article
Next Article

Similar Reads

Interactive visualization of data using Bokeh
Bokeh is a Python library for creating interactive data visualizations in a web browser. It offers human-readable and fast presentation of data in an visually pleasing manner. If you’ve worked with visualization in Python before, it’s likely that you have used matplotlib. But Bokeh differs from matplotlib. To install Bokeh type the below command in
4 min read
Interactive Data Visualization with Python and Bokeh
In this article, we'll learn how to do Interactive Data Visualization with Bokeh. Bokeh is a Python library that is used for creating interactive visualizations for modern web browsers. It handles custom or specialized use cases very simply. It provides high-performance interactive charts and plots. Bokeh output can be obtained in various mediums l
8 min read
Handling Categorical Data with Bokeh - Python
As a data scientist, you will often come across datasets with categorical data. Categorical data is a type of data that can be divided into distinct categories or groups. For example, a dataset might have a column with the categories "red", "green", and "blue". Handling categorical data can be challenging because it cannot be processed in the same
5 min read
Python Bokeh – Visualizing Stock Data
Bokeh is a Python interactive data visualization. It renders its plots using HTML and JavaScript. It targets modern web browsers for presentation providing elegant, concise construction of novel graphics with high-performance interactivity. Bokeh can be used to visualize stock market data. Visualization is be done using the plotting module. Here we
3 min read
Conditional Data Visualization Using Google Data Studio
In this article, we will learn how to do Conditional Data Visualization using Google Data studio. Before moving forward, let's understand the title itself. Data visualization Data visualization is all about getting useful insights from the data through graphical media or visuals. When data is presented in a visual format. It becomes easy and quick
3 min read
Make an area plot in Python using Bokeh
Bokeh is a Python interactive data visualization. Unlike Matplotlib and Seaborn, Bokeh renders its plots using HTML and JavaScript. It targets modern web browsers for presentation providing elegant, concise construction of novel graphics with high-performance interactivity. Plotting the Area Plots Area plots are defined as the filled regions betwee
2 min read
Make an Circle Glyphs in Python using Bokeh
Bokeh is a Python interactive data visualization. Unlike Matplotlib and Seaborn, Bokeh renders its plots using HTML and JavaScript. It targets modern web browsers for presentation providing elegant, concise construction of novel graphics with high-performance interactivity. Plotting the Circle Glyphs Different shapes such as circle, rectangle, poly
4 min read
How to change ticks label sizes using Python's Bokeh?
Bokeh is an interactive data plotting visualization library for modern web browsers. It provides elegant, concise construction of versatile graphics, and affords high-performance interactivity over large or streaming datasets. In this article, we are going to discuss How to change ticks label sizes using Python's Bokeh. Step-by-step Approach: Now t
2 min read
Create a plot with Multiple Glyphs using Python Bokeh
In this article, we will be learning about multiple glyphs and also about adding a legend in bokeh. Now bokeh provides us with a variety of glyphs that can be used to represent a point in a plot. Some glyphs are circle, square, asterik, inverted_triangle(), triangle() etc. Installation This module does not come in-built with Python. To install it t
7 min read
Why Data Visualization Matters in Data Analytics?
What if you wanted to know the number of movies produced in the world per year in different countries? You could always read this data in the form of a black and white text written on multiple pages. Or you could have a colorful bar chart that would immediately tell you which countries are producing more movies and if the total movies per year are
7 min read
Difference Between Data Mining and Data Visualization
Data mining: Data mining is the method of analyzing expansive sums of data in an exertion to discover relationships, designs, and insights. These designs, concurring to Witten and Eibemust be "meaningful in that they lead to a few advantages, more often than not a financial advantage." Data in data mining is additionally ordinarily quantitative par
2 min read
Difference Between Data Visualization and Data Analytics
Data Visualization: Data visualization is the graphical representation of information and data in a pictorial or graphical format(Example: charts, graphs, and maps). Data visualization tools provide an accessible way to see and understand trends, patterns in data and outliers. Data visualization tools and technologies are essential to analyze massi
3 min read
Difference Between Data Science and Data Visualization
Data Science: Data science is study of data. It involves developing methods of recording, storing, and analyzing data to extract useful information. The goal of data science is to gain knowledge from any type of data both structured and unstructured. Data science is a term for set of fields that are focused on mining big data sets and discovering t
2 min read
Stock Data Analysis and Data Visualization with Quantmod in R
Analysis of historical stock price and volume data is done in order to obtain knowledge, make wise decisions, and create trading or investment strategies. The following elements are frequently included in the examination of stock data in the R Programming Language. Historical Price Data: Historical price data contains information about a stock's op
8 min read
Why is Data Visualization so Important in Data Science
Would you prefer to view large data tables and then make sense of that data or view a data visualization that represents that data in an easy-to-understand visual format? Well, most of you would prefer data visualization! That is because data visualization is extremely useful in understanding the data and obtaining useful insights. It can allow you
8 min read
COVID-19 Data Visualization using matplotlib in Python
It feels surreal to imagine how the virus began to spread from one person that is patient zero to four million today. It was possible because of the transport system. Earlier back in the days, we didn’t have a fraction of the transportation system we have today. Well, what good practices you can follow for now is to sanitize your grocery products a
8 min read
Visualization and Prediction of Crop Production data using Python
Prerequisite: Data Visualization in Python Visualization is seeing the data along various dimensions. In python, we can visualize the data using various plots available in different modules. In this article, we are going to visualize and predict the crop production data for different years using various illustrations and python libraries. Dataset T
4 min read
Python - Data visualization using covid19 India API
API (Application Programming Interface) is a computing interface that interacts between multiple software. JSON (JavaScript Object Notation) is a lightweight format for storing and transporting data. It is used to send data from server to web. Required modules: matplotlibrequestspandasjson Commands to install modules: pip install matplotlib pip ins
5 min read
Data Visualization using Turicreate in Python
In Machine Learning, Data Visualization is a very important phase. In order to correctly understand the behavior and features of your data one needs to visualize it perfectly. So here I am with my post on how to efficiently and at the same time easily visualize your data to extract most out of it. Before going in detail about how to visualize data
3 min read
Data Visualization Using Bqplot in Python
Bqplot is a powerful and flexible tool for creating interactive visualizations within Jupyter Notebooks. Its integration with ipywidgets and use of D3.js make it a valuable library for data scientists and developers who need to build interactive data visualization applications. What is BqPlot in Python?BqPlot is a fun tool that helps you make cool
9 min read
Data Visualization using Matplotlib in Python
Data visualization is a crucial aspect of data analysis, enabling data scientists and analysts to present complex data in a more understandable and insightful manner. One of the most popular libraries for data visualization in Python is Matplotlib. In this article, we will provide a comprehensive guide to using Matplotlib for creating various types
15+ min read
Data Visualization using Plotnine and ggplot2 in Python
Data Visualization is the technique of presenting data in the form of graphs, charts, or plots. Visualizing data makes it easier for the data analysts to analyze the trends or patterns that may be present in the data as it summarizes the huge amount of data in a simple and easy-to-understand format.  In this article, we will discuss how to visualiz
10 min read
Disabling Scientific Notation on Axes Using Bokeh
Bokeh is a powerful and flexible Python library used to create interactive plots and data visualizations. One of the default features of Bokeh is its ability to format large or small numbers using scientific notation on the axes of your plots. While this is useful in certain contexts, there are many cases where scientific notation may not be desira
4 min read
Using Custom Labels for Ticks in Bokeh
Bokeh is a versatile library that allows for creating interactive plots and visualizations with detailed customization options. One powerful feature of Bokeh is the ability to modify the appearance and labels of tick marks on the axes of your plots. By using custom labels for ticks, you can make your data more readable, informative, or visually app
5 min read
bokeh.plotting.figure.diamond_cross() function in Python
Bokeh is a data visualization library in Python that provides high-performance interactive charts and plots and the output can be obtained in various mediums like a notebook, HTML and server. Figure Class create a new Figure for plotting. It is a subclass of Plot that simplifies plot creation with default axes, grids, tools, etc. bokeh.plotting.fig
2 min read
bokeh.plotting.figure.step() function in Python
Bokeh is a data visualization library in Python that provides high-performance interactive charts and plots and the output can be obtained in various mediums like notebook, html and server. The Figure Class create a new Figure for plotting. It is a subclass of Plot that simplifies plot creation with default axes, grids, tools, etc. bokeh.plotting.f
4 min read
bokeh.plotting.figure.circle_cross() function in Python
Bokeh is a data visualization library in Python that provides high-performance interactive charts and plots and the output can be obtained in various mediums like notebook, html and server. The Figure Class create a new Figure for plotting. It is a subclass of Plot that simplifies plot creation with default axes, grids, tools, etc. bokeh.plotting.f
4 min read
bokeh.plotting.figure.annular_wedge() function in Python
Bokeh is a data visualization library in Python that provides high-performance interactive charts and plots and the output can be obtained in various mediums like notebook, html and server. The Figure Class create a new Figure for plotting. It is a subclass of Plot that simplifies plot creation with default axes, grids, tools, etc. bokeh.plotting.f
4 min read
bokeh.plotting.figure.arc() function in Python
Bokeh is a data visualization library in Python that provides high-performance interactive charts and plots and the output can be obtained in various mediums like notebook, html and server. The Figure Class create a new Figure for plotting. It is a subclass of Plot that simplifies plot creation with default axes, grids, tools, etc. bokeh.plotting.f
4 min read
bokeh.plotting.figure.asterisk() function in Python
Bokeh is a data visualization library in Python that provides high-performance interactive charts and plots and the output can be obtained in various mediums like notebook, html and server. The Figure Class create a new Figure for plotting. It is a subclass of Plot that simplifies plot creation with default axes, grids, tools, etc. bokeh.plotting.f
4 min read