Header Ads Widget

⚡ Premium Tools Hub • EXE Apps + Full Python Source Code
Lite • Pro • Bundle Packs • Instant Download

Bokeh Circle Glyphs: Create Interactive Scatter Plots and Data Point Visualizations in Python

Circle glyphs are among the most frequently used graphical elements in the Bokeh library. They are ideal for representing individual data points, making them the foundation of scatter plots, bubble charts, statistical visualizations, and many interactive dashboards. Whether you're analyzing business metrics, scientific measurements, or financial trends, circle glyphs provide a clear and intuitive way to visualize relationships between variables.

In this tutorial, you'll learn what circle glyphs are, how to create them, customize their appearance, work with data sources, add interactive features, and follow best practices for professional-quality visualizations.


What Is a Circle Glyph?

A Circle Glyph is a graphical marker that displays data points as circles on a Bokeh figure. Each circle corresponds to one pair of x and y coordinates, making it easy to visualize distributions, trends, and relationships.

Circle glyphs are commonly used in:

  • Scatter plots
  • Bubble charts
  • Statistical analysis
  • Scientific research
  • Sales dashboards
  • Financial reports
  • Machine learning visualizations
  • Geographic data displays

Because every point is rendered individually, users can easily inspect specific values using interactive tools.


Why Use Circle Glyphs?

Circle glyphs offer several advantages:

  • Easy to understand
  • Excellent for comparing data points
  • Fully interactive
  • Highly customizable
  • Works with small and large datasets
  • Integrates with dashboards
  • Compatible with hover tools and selections

They are often the first glyph developers learn when working with Bokeh.


Creating Your First Circle Glyph

Start by importing the required modules.

from bokeh.plotting import figure, show

Create some sample data:

x = [1, 2, 3, 4, 5]

y = [4, 7, 5, 8, 6]

Create a figure and add circle glyphs:

plot = figure(
    title="Circle Glyph Example",
    width=700,
    height=400
)

plot.circle(
    x,
    y,
    size=12,
    color="royalblue"
)

show(plot)

Running the script opens an interactive chart in your browser.


Understanding Circle Properties

The circle() glyph includes many customization options.

Common properties include:

  • size
  • fill_color
  • line_color
  • fill_alpha
  • line_alpha
  • line_width
  • radius
  • visible

These properties allow you to control the appearance of every marker.


Changing Marker Size

Increase the size of each point:

plot.circle(
    x,
    y,
    size=18
)

Larger markers make individual observations easier to identify.


Changing Colors

Customize both the fill and border colors.

plot.circle(
    x,
    y,
    size=12,
    fill_color="orange",
    line_color="black"
)

Using contrasting colors improves readability.


Using Transparency

Transparency helps reduce overlap in dense datasets.

plot.circle(
    x,
    y,
    size=15,
    fill_alpha=0.6
)

Lower alpha values allow overlapping circles to remain visible.


Using Radius Instead of Size

Circle glyphs can also be sized using a data-space radius.

plot.circle(
    x,
    y,
    radius=0.2
)

Unlike size, which uses screen pixels, radius scales with the chart's coordinate system.


Working with ColumnDataSource

For larger projects, use a ColumnDataSource.

from bokeh.models import ColumnDataSource

source = ColumnDataSource(data={
    "x":[1,2,3,4,5],
    "y":[3,5,7,6,8]
})

plot.circle(
    x="x",
    y="y",
    source=source,
    size=12
)

A shared data source makes it easier to update and synchronize multiple visualizations.


Adding Hover Tooltips

Interactive tooltips display additional information when users hover over a point.

from bokeh.models import HoverTool

hover = HoverTool(
    tooltips=[
        ("X", "@x"),
        ("Y", "@y")
    ]
)

plot.add_tools(hover)

Hover tooltips improve usability without cluttering the chart.


Combining Circle Glyphs with Lines

Many visualizations combine circles with a connecting line.

plot.line(
    x,
    y,
    line_width=2,
    color="navy"
)

plot.circle(
    x,
    y,
    size=10,
    color="red"
)

This approach highlights individual observations while showing the overall trend.


Creating Bubble Charts

Bubble charts extend circle glyphs by varying the size of each marker.

Example:

sizes = [10, 20, 15, 30, 25]

plot.circle(
    x,
    y,
    size=sizes,
    fill_color="green"
)

Bubble charts can represent an additional variable such as population, revenue, or market share.


Styling Your Plot

Enhance the overall appearance of your visualization.

plot.title.text_font_size = "18pt"

plot.xaxis.axis_label = "Month"

plot.yaxis.axis_label = "Sales"

plot.background_fill_color = "#f5f7fa"

plot.grid.grid_line_alpha = 0.4

Clear labels and consistent styling make charts easier to interpret.


Best Practices

To create effective circle glyph visualizations:

  • Use appropriate marker sizes.
  • Avoid excessive overlap.
  • Choose colors with good contrast.
  • Add hover tooltips for detailed information.
  • Label axes clearly.
  • Keep charts uncluttered.
  • Use transparency when plotting dense datasets.
  • Organize data with ColumnDataSource.

These practices improve readability and user experience.


Common Mistakes

New Bokeh users often encounter these issues:

  • Markers that are too small or too large.
  • Overlapping circles that hide important data.
  • Missing axis labels.
  • Inconsistent color schemes.
  • Ignoring accessibility and contrast.
  • Using radius when size is more appropriate.

Careful design choices produce cleaner and more informative visualizations.


Real-World Applications

Circle glyphs are widely used across many industries.

Examples include:

  • Customer analytics
  • Sales reporting
  • Scientific experiments
  • Financial market analysis
  • Machine learning datasets
  • Geographic mapping
  • Healthcare statistics
  • Educational research

Their flexibility makes them one of the most valuable glyph types in Bokeh.


Conclusion

Circle glyphs are one of the core building blocks of Bokeh visualizations. They provide a simple yet powerful way to represent individual data points while supporting rich interactivity through hover tools, zooming, and selections.

By mastering the circle() glyph, customization options, data sources, and styling techniques, you'll be able to create professional scatter plots, bubble charts, dashboards, and analytical applications. As you continue exploring Bokeh, circle glyphs will remain an essential tool for presenting data clearly and effectively.

Create Interactive Scatter Plots and Data Point Visualizations in Python


Post a Comment

0 Comments