Skip to content

Conversation

@Eshaan-byte
Copy link
Contributor

Summary

Adds a new FilledArea plot item that fills the area between two lines, useful for visualizing confidence intervals, ranges, and uncertainty bands.

Changes

  • Added FilledArea struct in egui_plot/src/items/filled_area.rs
  • Simple API: FilledArea::new(name, &xs, &ys_min, &ys_max) takes plain f64 slices
  • Supports customizable fill color (Color32)
  • Optional stroke around boundaries
  • Follows existing plot item patterns

Example Usage

let xs = vec![0.0, 1.0, 2.0, 3.0];
let ys_min = vec![1.0, 1.5, 2.0, 1.8];
let ys_max = vec![3.0, 3.5, 4.0, 3.8];

let filled_area = FilledArea::new("Range", &xs, &ys_min, &ys_max)
    .fill_color(Color32::from_rgba_unmultiplied(100, 200, 100, 50));

plot_ui.add(filled_area);

This adds a new FilledArea plot item that fills the area between
two lines defined by x values and corresponding y_min and y_max values.

API: FilledArea::new(name, &xs, &ys_min, &ys_max)

Useful for visualizing:
- Confidence intervals
- Min-max ranges
- Uncertainty bands

Features:
- Customizable fill color (Color32)
- Optional stroke around boundaries
- Follows existing plot item patterns

Closes emilk#190
@michalsustr
Copy link
Collaborator

michalsustr commented Nov 30, 2025

Great, thank you for the PR! This is something I wanted to have in the library soon, good timing :)

Can you please add a demo example with controls? E.g.

  • Copy an existing example, like box_plot as a new filled_area example.
  • Plot some line, like sin(x)
  • Add a control to adjust upper and lower bounds, i.e. sin(x)-delta_lb and sin(x) + delta_ub
  • Add reference to demo gallery.

Thank you!

@michalsustr michalsustr added the include in changelog This change will be included in the changelog label Nov 30, 2025
- Created filled_area example with sin(x) and adjustable bounds
- Added controls for delta_lower and delta_upper offsets
- Integrated into demo gallery
- Added workspace dependencies
@michalsustr
Copy link
Collaborator

michalsustr commented Nov 30, 2025

Great, please also expose pub use crate::items::FilledArea; in lib.rs

The demo uses filled polygons, which connect in a weird way to first point I presume. Please fix it (there should be three sin waves in total: sin and upper/lower bounds) and we can merge.

image

@michalsustr
Copy link
Collaborator

Oh and please run UPDATE_SNAPSHOTS=1 cargo test -p filled_area after the fix, to add new screenshots.

- Export FilledArea in lib.rs for public use
- Fix polygon rendering by using Mesh instead of convex_polygon
- Creates proper triangle strips to avoid connecting first/last points
- Fills area correctly between upper and lower boundaries
@michalsustr
Copy link
Collaborator

You might find https://github.com/0xb-s/egui_plot/pull/2/files#diff-7f61f3f9c96e213424b0aab7f15a33796acdb63d36548c771759f13030cb986a useful.

@michalsustr
Copy link
Collaborator

There are some CI failures, pls fix them.

- Wrap Mesh in Arc as required by egui Shape::Mesh API
- Fix unused variable warning (ui -> _ui)
- Add std::sync::Arc import
- Generate screenshots using UPDATE_SNAPSHOTS=1 cargo test
- Screenshots now show actual filled area demo with interactive controls
@michalsustr
Copy link
Collaborator

Closing in favor of #202 with some fixes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

include in changelog This change will be included in the changelog

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants