Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
suyashi29
GitHub Repository: suyashi29/python-su
Path: blob/master/Key Python Libraries/Data Visualization using Bokeh.ipynb
3074 views
Kernel: Python 3 (ipykernel)

You can create interactive plots with Bokeh and also dashboards and data applications.

from bokeh.plotting import figure, show from bokeh.io import output_notebook import pandas as pd import numpy as np
  • The figure function allows us to create a basic plot object, where we can define things like height, grids, and tools.

data = pd.read_csv("Airline.csv") data.head(2)
p = figure(width=800, height=400) # add a circle renderer with a size, color, and alpha p.circle(data.sum_departures_performed, data.Passengers, size=20, color="navy", alpha=0.2) # show the results show(p)
# add a title with providing the title parameter p = figure(width=800, height=400, title="Average Fuel Price") # compute the histogram of the price variable hist, edges = np.histogram(data.avg_Fuel_Price, density=True, bins=50) # call the quad method on our figure object p p.quad(top=hist, bottom=0, left=edges[:-1], right=edges[1:], line_color="white") show(p)

if we wanted to specify the position of the title, and we wanted a title for each axis? Well, Bokeh also offers a simple solution to this problem

from bokeh.palettes import Spectral7 from bokeh.models import Title # prepare the Aircratft value counts colors = sorted(list(data.Aircraft.unique())) counts = [i for i in data.Aircraft.value_counts().sort_index()] p = figure(x_range=Aircraft, width=800, height=400) p.vbar(x=Arcraft ,op=counts, width=0.9, color=Spectral7) p.y_range.start = 0 p.add_layout(Title(text="Aircraft", align="center"), "below") p.add_layout(Title(text="Unnique", align="center"), "left") show(p)