Plot yerr/xerr as shaded region rather than error bars
ML System Design practice on Codemia
Design recommenders, ranking systems and training pipelines the way ML interviews actually ask for them, with worked solutions.
Plotting data with associated uncertainties is a critical aspect of data visualization, especially in scientific and engineering fields. Traditionally, error bars have been used to represent the uncertainties in data points. However, an alternative approach involves plotting uncertainties as shaded regions rather than error bars, offering a clearer and often more visually appealing representation. This article delves into the technical explanations and applications of this method.
Understanding Yerr/Xerr as Shaded Regions
Traditional Error Bars
In traditional plots, the uncertainty in a value on a graph is often represented using error bars. These bars extend from each data point vertically (for ) and/or horizontally (for ). They provide an immediate visual cue about the range of uncertainty but can become cluttered in dense data visualizations or when the data has high variability.
Shaded Region Representation
Plotting uncertainties as a shaded region provides a more continuous representation of errors, creating a 'band' around a line plot. This approach has key advantages:
- Improved Clarity: Shaded regions can make the visualization cleaner, especially in plots with many overlapping error bars.
- Better Context: They provide a contiguous visual representation of uncertainty, improving the interpretation of data trends.
- Enhanced Aesthetics: Shaded regions tend to be visually appealing and emphasize the envelope of uncertainty effectively.
Technical Implementation
Tools and Libraries
Numerous tools and libraries facilitate plotting shaded regions in data visualizations. Some of the most widely used in Python include:
- Matplotlib: A versatile library that allows the creation of shaded areas using functions like
fill_between. - Seaborn: Built on Matplotlib, Seaborn simplifies plotting procedures and includes functions to automatically plot shaded error regions.
- Plotly: An interactive plotting library that easily incorporates shaded regions.
Code Example
Here's a basic example using Matplotlib to plot data with a shaded uncertainty region:
- We use
fill_betweento create a shaded region on the plot fromy - yerrtoy + yerr. - The
alphaparameter controls the transparency of the shaded region. - Labels and axes titles are added to enhance plot comprehension.
Related reading
- Plotly How to make an annotated confusion matrix using a heatmap?
- Plotting a 2D heatmap
- Plotting a list of x, y coordinates
- Plotting a pie chart out of a dictionary
- Plotting in a non-blocking way with Matplotlib
- Polygon enclosing a set of points
- Plotting a ROC curve in scikit yields only 3 points
- Plotting decision boundary for High Dimension Data

DSA Fundamentals
Master algorithmic patterns and data structures through hands-on LeetCode-style problems - from arrays and hashing to dynamic programming and advanced graphs.
View the courseTrack what you have practised
A free account saves your progress, solutions and study plan across every problem on Codemia.
ML System Design practice on Codemia
Design recommenders, ranking systems and training pipelines the way ML interviews actually ask for them, with worked solutions.