Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
-
Economics & Finance
How can Bokeh be used to visualize different shapes of data points in Python?
Bokeh is a Python package that helps in data visualization. It is an open source project that renders plots using HTML and JavaScript, making it useful for web-based dashboards. It helps in communicating quantitative insights to the audience effectively through interactive visualizations.
Bokeh converts the data source into a JSON file, which is used as input to BokehJS, a JavaScript library written in TypeScript that renders visualizations on modern browsers. Unlike Matplotlib and Seaborn which produce static plots, Bokeh creates interactive plots that respond to user interactions.
Installation
Install Bokeh using pip or conda :
pip3 install bokeh
Or using Anaconda :
conda install bokeh
Creating Different Shape Markers
The figure function contains multiple methods for drawing vectorized glyphs of different shapes like circles, squares, and crosses. Here's how to create various shape markers :
from bokeh.plotting import figure, show
from bokeh.io import output_notebook
# Create a figure
plot = figure(plot_width=400, plot_height=400, title="Different Shape Markers")
# Circle markers
plot.circle(x=[1, 4, 6], y=[3, 7, 8], size=20, fill_color='red', alpha=0.8)
# Circle with cross markers
plot.circle_cross(x=[2, 4, 5], y=[3, 8, 11], size=20, fill_color='blue',
fill_alpha=0.6, line_width=2, line_color='darkblue')
# Circle with X markers
plot.circle_x(x=[5, 3, 2], y=[2, 1, 7], size=20, fill_color='green',
fill_alpha=0.6, line_width=2, line_color='darkgreen')
# Square markers
plot.square(x=[3, 5, 7], y=[4, 6, 9], size=15, fill_color='orange', alpha=0.7)
# Triangle markers
plot.triangle(x=[1, 3, 6], y=[5, 9, 12], size=18, fill_color='purple', alpha=0.7)
show(plot)
Available Shape Methods
Bokeh provides various marker methods for different shapes :
| Method | Shape | Description |
|---|---|---|
circle() |
Circle | Basic circular markers |
circle_cross() |
Circle + Cross | Circle with cross overlay |
circle_x() |
Circle + X | Circle with X overlay |
square() |
Square | Square markers |
triangle() |
Triangle | Triangular markers |
diamond() |
Diamond | Diamond-shaped markers |
Customizing Marker Properties
You can customize various properties of shape markers :
from bokeh.plotting import figure, show
plot = figure(plot_width=400, plot_height=300, title="Customized Markers")
# Customize size, color, and transparency
plot.circle(x=[1, 2, 3], y=[1, 2, 3],
size=[10, 20, 30], # Different sizes
fill_color=['red', 'green', 'blue'], # Different colors
fill_alpha=0.7,
line_width=2,
line_color='black')
show(plot)
Conclusion
Bokeh provides extensive support for visualizing data with different shaped markers through methods like circle(), square(), and triangle(). You can customize size, color, transparency, and line properties to create rich, interactive visualizations suitable for web-based applications.
