ANALYSIS TOOL BOX

Visualizations

PlotOverlappingAreaChart

Generate a formatted overlapping area chart for multi-variable time series comparison.

visualizationchartsplottinggraphs

Introduction

Several time series plotted as thin lines on the same axes tend to blur together, especially once you're past two or three of them — filled areas make magnitude and overlap far easier to read than lines alone. PlotOverlappingAreaChart renders multiple categorical variables over time as semi-transparent overlapping areas, automatically ordering them by mean value and optionally labeling each area directly, so both the trend and the relative scale of each series stay visible at once.

Teaching Note

Overlapping area charts are essential for:

  • Epidemiology: Comparing time-series trends of infection rates across multiple regions.
  • Healthcare: Visualizing patient census levels by hospital department over a fiscal year.
  • Intelligence Analysis: Monitoring threat activity levels across monitored geopolitical sectors.
  • Data Science: Tracking cumulative performance metrics across different model training versions.
  • Public Health: Monitoring atmospheric pollutant concentrations across several urban stations.
  • Finance: Visualizing the growth of multiple asset classes within an investment portfolio.
  • Operations: Tracking resource utilization (CPU/Memory) across different server clusters.
  • Economics: Visualizing historical unemployment rates across various demographic segments.

Parameters

ParameterTypeDefaultDescription
dataframerequiredpd.DataFrameThe pandas DataFrame containing the time series data in long format.
value_column_namerequiredstrThe name of the column containing the numeric values (y-axis).
variable_column_namerequiredstrThe name of the categorical column used to group the data into different areas.
time_column_namerequiredstrThe name of the column containing the temporal data (x-axis).
figure_sizetuple(8, 5)Dimensions of the output figure as a (width, height) tuple in inches. Defaults to (8, 5).
line_alphafloat0.9The transparency level (alpha) for the boundary lines. Defaults to 0.9.
color_palettestr'Paired'The name of the seaborn color palette to use for the areas. Defaults to 'Paired'.
fill_alphafloat0.8The transparency level (alpha) for the filled areas beneath the lines. Defaults to 0.8.
label_variable_on_areaboolTrueWhether to place text labels for each variable directly inside their respective areas. Defaults to True.
label_font_sizeint12The font size for the internal area labels. Defaults to 12.
label_font_colorstr'#FFFFFF'The hex color code for the internal area labels. Defaults to '#FFFFFF'.
number_of_x_axis_ticksintNoneThe maximum number of ticks to display on the horizontal time axis. Defaults to None.
x_axis_tick_rotationintNoneThe rotation angle (in degrees) for the x-axis tick labels. Defaults to None.
title_for_plotstrNoneThe primary title text displayed at the top of the chart. Defaults to None.
subtitle_for_plotstrNoneDescriptive subtitle text displayed below the main title. Defaults to None.
caption_for_plotstrNoneExplanatory text or notes displayed at the bottom of the plot. Defaults to None.
data_source_for_plotstrNoneText identifying the data origin, appended to the caption. Defaults to None.
x_indentfloat-0.127Horizontal offset for the titles and captions relative to the axes. Defaults to -0.127.
title_y_indentfloat1.125Vertical offset for the title position relative to the grid. Defaults to 1.125.
subtitle_y_indentfloat1.05Vertical offset for the subtitle position relative to the grid. Defaults to 1.05.
caption_y_indentfloat-0.3Vertical offset for the caption position relative to the grid. Defaults to -0.3.
filepath_to_save_plotstrNoneThe local path (ending in .png or .jpg) where the plot should be exported. If None, the file is not saved. Defaults to None.

Returns

None — the function displays the overlapping area chart using matplotlib and optionally saves it to disk.

Example

python
from analysistoolbox.visualizations import PlotOverlappingAreaChart
import pandas as pd
import numpy as np

# Epidemiology: regional infection trends over 6 months
dates = pd.date_range(start="2024-01-01", periods=6, freq='M')
epi_df = pd.DataFrame({
    'Date': np.tile(dates, 3),
    'Region': np.repeat(['East', 'West', 'Central'], 6),
    'Cases': [10, 15, 45, 60, 30, 20, 5, 8, 22, 35, 18, 12, 15, 25, 35, 45, 50, 40]
})
PlotOverlappingAreaChart(
    epi_df, 'Cases', 'Region', 'Date',
    title_for_plot="Viral Transmission Velocity",
    subtitle_for_plot="New confirmed cases per 100,000 residents"
)