Header Ads Widget

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

Bokeh Wedges and Arcs: Create Interactive Pie Charts, Circular Visualizations, and Arc Glyphs in Python

Circular visualizations are widely used to represent proportions, angles, progress, and directional data. Bokeh provides several specialized glyphs for drawing curved shapes, including Wedge, Annular Wedge, and Arc glyphs. These allow you to build interactive pie charts, donut charts, gauges, circular dashboards, and engineering diagrams with only a few lines of Python code.

In this tutorial, you'll learn how these glyphs work, how to customize them, and how to create professional interactive circular visualizations using Bokeh.


What Are Wedges and Arcs?

Wedges and arcs are circular geometric glyphs that display portions of a circle.

The primary glyphs are:

  • wedge() – Draws a pie-slice shape from the center of a circle.
  • annular_wedge() – Draws a ring-shaped slice, commonly used for donut charts.
  • arc() – Draws only the curved outline between two angles.

These glyphs are useful whenever your data is best represented by angles or circular segments.


Common Applications

Wedge and arc glyphs are commonly used in:

  • Pie charts
  • Donut charts
  • Progress indicators
  • Circular gauges
  • Financial dashboards
  • Scientific diagrams
  • Engineering illustrations
  • Geographic direction charts
  • Performance monitoring systems

Their interactive nature makes them ideal for web-based analytics.


Creating a Figure

Begin by creating a Bokeh figure.

from bokeh.plotting import figure, show

plot = figure(
    title="Wedge Glyph Example",
    width=700,
    height=500
)

The figure acts as the drawing canvas for all circular glyphs.


Creating a Basic Wedge

The wedge() glyph creates a pie-shaped slice.

plot.wedge(
    x=0,
    y=0,
    radius=1,
    start_angle=0,
    end_angle=1.57,
    fill_color="royalblue"
)

show(plot)

The wedge begins at the starting angle and ends at the ending angle, measured in radians.


Understanding Wedge Parameters

Important properties include:

  • x
  • y
  • radius
  • start_angle
  • end_angle
  • fill_color
  • line_color
  • fill_alpha
  • line_width

These settings control the position, size, and appearance of each wedge.


Creating Multiple Wedges

Several wedges can be combined to form a pie chart.

plot.wedge(
    x=0,
    y=0,
    radius=1,
    start_angle=0,
    end_angle=1.2,
    fill_color="red"
)

plot.wedge(
    x=0,
    y=0,
    radius=1,
    start_angle=1.2,
    end_angle=2.6,
    fill_color="green"
)

plot.wedge(
    x=0,
    y=0,
    radius=1,
    start_angle=2.6,
    end_angle=6.28,
    fill_color="blue"
)

Each wedge represents a portion of the complete circle.


Creating a Donut Chart

The annular_wedge() glyph creates ring-shaped slices.

plot.annular_wedge(
    x=0,
    y=0,
    inner_radius=0.5,
    outer_radius=1,
    start_angle=0,
    end_angle=1.57,
    fill_color="orange"
)

Donut charts are popular in business dashboards because they leave room for labels or summary statistics in the center.


Drawing an Arc

Unlike wedges, arcs only draw the curved outline.

plot.arc(
    x=0,
    y=0,
    radius=1,
    start_angle=0,
    end_angle=3.14,
    line_width=4,
    color="purple"
)

Arc glyphs are useful for gauges, engineering diagrams, and decorative visualizations.


Customizing Colors and Transparency

Improve the appearance of circular glyphs using styling options.

plot.wedge(
    x=0,
    y=0,
    radius=1,
    start_angle=0,
    end_angle=2,
    fill_color="skyblue",
    fill_alpha=0.7,
    line_color="navy",
    line_width=2
)

Consistent colors make charts easier to interpret.


Using ColumnDataSource

For dynamic applications, store your data in a ColumnDataSource.

from bokeh.models import ColumnDataSource

source = ColumnDataSource(data={
    "start":[0,1.5,3],
    "end":[1.5,3,6.28],
    "color":["red","green","blue"]
})

plot.wedge(
    x=0,
    y=0,
    radius=1,
    start_angle="start",
    end_angle="end",
    fill_color="color",
    source=source
)

Using a shared data source simplifies updates and interactive filtering.


Adding Hover Tooltips

Hover tooltips display additional information when users move the cursor over a wedge.

from bokeh.models import HoverTool

hover = HoverTool(
    tooltips=[
        ("Category","@category"),
        ("Value","@value")
    ]
)

plot.add_tools(hover)

Interactive tooltips provide useful details without cluttering the visualization.


Creating Circular Dashboards

Wedges and arcs can be combined with other glyphs to create interactive dashboards.

Examples include:

  • Progress rings
  • Speedometers
  • KPI gauges
  • Circular indicators
  • Activity trackers
  • Performance meters

These visualizations are commonly used in business intelligence applications.


Styling Your Plot

Enhance the chart with titles, colors, and layout adjustments.

plot.title.text_font_size = "18pt"

plot.background_fill_color = "#f7f9fc"

plot.grid.visible = False

plot.axis.visible = False

Removing unnecessary chart elements creates a cleaner circular visualization.


Best Practices

When using wedges and arcs:

  • Use contrasting colors for different segments.
  • Keep labels readable.
  • Avoid using too many slices.
  • Use donut charts when center space is needed.
  • Add hover tooltips for detailed information.
  • Maintain consistent color schemes.
  • Keep charts simple and uncluttered.

Thoughtful design improves user understanding.


Common Mistakes

Avoid these common issues:

  • Using too many pie slices.
  • Choosing similar colors for adjacent wedges.
  • Forgetting to convert angles to radians.
  • Overcrowding the chart with labels.
  • Ignoring accessibility and color contrast.
  • Mixing unrelated categories in one chart.

Simple, well-organized visualizations communicate information more effectively.


Real-World Applications

Wedge and arc glyphs are used across many industries.

Examples include:

  • Business analytics dashboards
  • Sales reports
  • Budget allocation charts
  • Scientific instruments
  • Manufacturing monitoring
  • Network performance dashboards
  • Healthcare analytics
  • IoT monitoring systems
  • Financial reporting

Their ability to represent proportions and progress makes them valuable in both technical and business environments.


Conclusion

Bokeh's wedge(), annular_wedge(), and arc() glyphs provide a flexible way to build interactive circular visualizations ranging from simple pie charts to sophisticated dashboards. By combining these glyphs with customization options, hover tools, and ColumnDataSource, you can create engaging visualizations that clearly communicate proportions, progress, and relationships.

As you continue learning Bokeh, these circular glyphs will become essential tools for developing modern, interactive dashboards and data-driven applications that deliver clear insights and an engaging user experience.

Create Interactive Pie Charts, Circular Visualizations, and Arc Glyphs in Python


Post a Comment

0 Comments