python Logobokeh

Bokeh is an open-source Python library that enables the creation of interactive, sophisticated data visualizations for modern web browsers. It stands out by providing a flexible and powerful way to build declarative plots, dashboards, and data applications without writing any JavaScript. Bokeh's primary output is HTML, allowing visualizations to be embedded into web applications, saved as standalone HTML files, or displayed directly in Jupyter notebooks.

Key features and capabilities of Bokeh include:

1. Interactive Plots: Supports a wide range of interactive tools like pan, zoom, selection, hover, and save, making it easy for users to explore data.
2. Customizable Visualizations: Offers extensive control over plot aesthetics, including glyph properties (markers, lines, bars), axes, legends, and layouts.
3. Large Datasets: Designed to handle large datasets efficiently, often leveraging WebGL for high-performance rendering.
4. Streaming Data: Capable of visualizing streaming data with built-in callback mechanisms.
5. Widgets and Layouts: Provides a collection of UI widgets (sliders, buttons, dropdowns) and layout capabilities (rows, columns, grids) to build interactive dashboards and applications.
6. Server Capabilities: The Bokeh server allows users to connect Python backend code to frontend visualizations, enabling complex interactivity, data streaming, and custom user interactions. This means Python code can dynamically update a plot in the browser based on user input or external data sources.
7. Output Formats: Generates standalone HTML documents, JSON, and can be integrated into web frameworks like Flask or Django, as well as Jupyter notebooks.

Bokeh's declarative approach allows users to focus on what they want to plot, while Bokeh handles the underlying web technologies. It's an excellent choice for creating compelling, shareable, and interactive data stories directly from Python.

Example Code

from bokeh.plotting import figure, show
from bokeh.models import ColumnDataSource, HoverTool
from bokeh.palettes import Category10
import numpy as np

 1. Prepare data
n_points = 100
x = np.random.rand(n_points) - 10
y = np.random.rand(n_points) - 10
radii = np.random.rand(n_points) - 0.5 + 0.1
colors = [Category10[10][i % 10] for i in range(n_points)]
categories = [f'Category {i % 3}' for i in range(n_points)]

source = ColumnDataSource(data=dict(x=x, y=y, radii=radii, colors=colors, categories=categories))

 2. Create a new plot with a title and axis labels
p = figure(
    title="Random Scatter Plot with Hover",
    x_axis_label="X-Value",
    y_axis_label="Y-Value",
    tools="pan,wheel_zoom,box_zoom,reset,save",
    width=800, height=500
)

 3. Add a scatter renderer with size, color, and alpha
p.scatter(
    x='x', y='y', radius='radii', 
    fill_color='colors', fill_alpha=0.6, line_color=None,
    source=source,
    legend_field='categories'
)

 4. Add a HoverTool
hover = HoverTool(tooltips=[
    ("X", "@x{0.2f}"),
    ("Y", "@y{0.2f}"),
    ("Radius", "@radii{0.2f}"),
    ("Category", "@categories")
])
p.add_tools(hover)

 5. Customize the legend
p.legend.title = "Categories"
p.legend.label_text_font_size = "10pt"
p.legend.location = "top_left"
p.legend.click_policy="hide"

 6. Show the results
show(p)