Data Visualization Using Pandas Bokeh | by Raji Rai | Towards Data Science

Exploratory data analysis is the foundation for understanding and building effective ML models. Data visualization is a key part of EDA, and there are many tools available for this. Bokeh is an interactive visualization library. It provides intuitive and versatile graphics. Bokeh can help to quickly and easily make interactive plots and dashboards. Pandas Bokeh provides a Bokeh plotting backend for Pandas.
Integrating Pandas Bokeh with your Python code is very simple. You only need to install and import the pandas-bokeh library, and then you can use it like any other visual tool. You should import Pandas-Bokeh library after importing Pandas. Use the following command to download and import pandas-bokeh library:
#Load the pandas_bokeh library!pip install pandas_bokehimport pandas as pdimport pandas_bokeh
You can set the plotting output as HTML or Notebook. To set the output to notebook use the command, pandas_bokeh.output_notebook(). This will embed the plot in the notebook cell. To display the output as a HTML file use the command, pandas_bokeh.output_file(filename).
You can easily plot Pandas DataFrames using the command, df.plot_bokeh(). Pandas Bokeh offers a wide variety of plotting options such as line, scatter, bar, histogram, area, mapplot, step, point, and pie. All the plots are interactive, pannable, and zoomable. Here are some examples with the code of popular visualizations, plotted using pandas_bokeh that are commonly used in data analysis.
Bar Plot
#Vertical barchartcarhpbot.plot_bokeh(    kind="bar",    figsize =(1000,800),    x="name",    xlabel="Car Models",     title="Bottom 10 Car Features",     alpha=0.6,    legend = "top_right",    show_figure=True)#Stacked vertical barcarhpbot.plot_bokeh.bar(    figsize =(1000,800),    x="name",    stacked=True,    xlabel="Car Models",     title="Bottom 10 Car Features",     alpha=0.6,    legend = "top_right",    show_figure=True)
Line Plot
iris.plot_bokeh(    kind='line',    x='species',    y=['sepal_length', 'sepal_width','petal_length','petal_width'],    xlabel='Species',    ylabel='Length and Width',    title='Flowers',)
Histogram
iris.plot_bokeh(kind="hist",title ="Iris feature distribution",                   figsize =(1000,800),                   xlabel = "Features",                   ylabel="Measure"                )
Scatter Plot
car.plot_bokeh.scatter(    x='horsepower',     y=['weight'],    figsize=(1000, 700),    zooming=False,    panning=False)
Map Plot
mapplot["size"] = mapplot["pop_max"] / 1000000mapplot.plot_bokeh.map(    x="longitude",    y="latitude",    hovertool_string="""<h2> @{name} </h2>                             <h3> Population: @{pop_max} </h3>""",    tile_provider="STAMEN_TERRAIN_RETINA",    size="size",     figsize=(1200, 600),    title="Cities with more than 1000K population")
Area Plot
carhp.plot_bokeh.area(    x="name",    stacked=True,    figsize=(1300, 700),    title="Compare Car Models",    xlabel="Top 10 Car models",    )
These were some basic plots plotted using pandas_bokeh. Each of these plots can be enhanced further using various optional parameters. Pandas Bokeh has provided a wonderful GitHub repository explaining all the plots with some great examples. The examples that I have shown above are all available with the data set in my Kaggle notebook.