Area plots are one of the most effective ways to visualize trends over time while emphasizing the magnitude of values. Unlike simple line charts, area plots fill the space beneath the line, making it easier to compare totals, identify patterns, and highlight changes in datasets.
Bokeh provides flexible tools for creating interactive area plots that allow users to zoom, pan, inspect data with hover tools, and integrate charts into web applications. In this guide, you'll learn how to build area plots, customize their appearance, and create professional interactive visualizations using Python.
What Is an Area Plot?
An area plot is similar to a line chart, but the region between the plotted line and the baseline is filled with color. This filled area helps viewers quickly understand the overall magnitude of the data.
Area plots are commonly used to visualize:
- Sales growth
- Website traffic
- Revenue trends
- Population changes
- Stock market performance
- Energy consumption
- Temperature variations
- Scientific measurements
Because the filled region draws attention to the total value, area charts are particularly useful when showing cumulative data.
Why Use Area Plots?
Area plots provide several advantages over standard line charts.
Benefits include:
- Clearly show trends over time
- Emphasize magnitude as well as direction
- Improve visual comparison
- Highlight cumulative totals
- Work well with interactive dashboards
- Easy to customize using Bokeh
They are ideal when the amount or volume of data is just as important as the trend itself.
Creating a Basic Figure
Begin by importing Bokeh and creating a figure.
from bokeh.plotting import figure, show
plot = figure(
title="Monthly Sales",
width=700,
height=400
)The figure serves as the canvas for your visualization.
Preparing Sample Data
Create simple datasets for plotting.
x = [1,2,3,4,5,6]
y = [12,18,16,25,22,30]These values will be used to generate the area plot.
Creating an Area Plot
Area charts in Bokeh are commonly created using the varea() glyph.
Example:
plot.varea(
x=x,
y1=0,
y2=y,
fill_color="skyblue",
fill_alpha=0.6
)
show(plot)The chart fills the region between the baseline (y1) and the data values (y2).
Creating a Horizontal Area Plot
Bokeh also supports horizontal filled areas using harea().
Example:
plot.harea(
y=x,
x1=0,
x2=y,
fill_color="lightgreen",
fill_alpha=0.5
)Horizontal area plots are useful when working with horizontal layouts or specialized dashboards.
Adding an Outline
Many developers combine an area plot with a line for better readability.
plot.line(
x,
y,
line_width=3,
color="navy"
)The outline clearly defines the upper boundary of the filled region.
Customizing Colors
Bokeh allows full control over chart appearance.
Example:
plot.varea(
x=x,
y1=0,
y2=y,
fill_color="royalblue",
fill_alpha=0.4
)Popular properties include:
- fill_color
- fill_alpha
- line_color
- line_width
- line_alpha
Choosing complementary colors improves readability and visual appeal.
Using ColumnDataSource
For larger datasets, use ColumnDataSource.
from bokeh.models import ColumnDataSource
source = ColumnDataSource(data={
"month":[1,2,3,4,5],
"sales":[15,20,18,27,30]
})
plot.varea(
x="month",
y1=0,
y2="sales",
source=source
)Using a data source simplifies updates, filtering, and sharing data between multiple plots.
Adding Interactive Tools
Interactive tools make area charts much more engaging.
Example:
plot = figure(
tools="pan,wheel_zoom,box_zoom,reset,save,hover"
)Useful tools include:
- Pan
- Wheel Zoom
- Hover
- Box Zoom
- Save
- Reset
- Crosshair
Users can explore the chart without modifying your code.
Adding Hover Tooltips
Display detailed information when users move the cursor over the chart.
from bokeh.models import HoverTool
hover = HoverTool(
tooltips=[
("Month", "@month"),
("Sales", "@sales")
]
)
plot.add_tools(hover)Tooltips improve the user experience by providing precise data values.
Creating Stacked Area Charts
Stacked area charts display multiple datasets on top of each other.
They are commonly used for:
- Product categories
- Revenue by department
- Population groups
- Energy production sources
- Market share
Stacked charts help compare both individual categories and overall totals.
Customizing the Plot
Enhance your visualization with titles, labels, and styling.
Example:
plot.title.text_font_size = "18pt"
plot.xaxis.axis_label = "Month"
plot.yaxis.axis_label = "Sales"
plot.background_fill_color = "#f8f9fa"
plot.grid.grid_line_alpha = 0.4Thoughtful customization improves clarity and creates a more professional appearance.
Saving the Visualization
Save your interactive chart as an HTML file.
from bokeh.io import output_file
output_file("area_plot.html")
show(plot)The HTML file can be shared or embedded into websites and dashboards.
Best Practices
To create effective area plots:
- Use area charts for continuous data.
- Keep color choices simple.
- Avoid stacking too many datasets.
- Label axes clearly.
- Include hover tooltips.
- Use transparency to reduce overlap.
- Highlight important trends with outlines.
- Test charts on different screen sizes.
These practices help users interpret data quickly and accurately.
Common Mistakes
Avoid these common issues:
- Using area charts for unrelated categories
- Filling with overly dark colors
- Overlapping too many areas
- Omitting axis labels
- Ignoring accessibility and contrast
- Using inconsistent scales
Keeping visualizations clean improves both usability and readability.
Real-World Applications
Area plots are widely used in many industries.
Examples include:
- Financial reporting
- Stock price analysis
- Website analytics
- Marketing performance
- Climate research
- Scientific experiments
- Manufacturing statistics
- Business intelligence dashboards
Their ability to emphasize trends and totals makes them valuable in both technical and business environments.
Conclusion
Area plots are an excellent choice for visualizing trends where the magnitude of data is important. Bokeh makes it easy to create interactive area charts that combine attractive design with powerful exploration features such as zooming, panning, and hover tooltips.
By mastering varea(), harea(), customization options, interactive tools, and data sources, you'll be able to build informative visualizations that communicate insights clearly. As you continue learning Bokeh, area plots will become an essential component of your interactive dashboards and data analysis projects.


0 Comments