Heatmap Widget for Plots
- Dominant language
- Rust
- Stars
- 468
- Forks
- 108
- Avg merge
- 15m
- Merged PRs (30d)
- 3
Description
I did not find a feature request about heat maps. Heat map plotting is available in the [ImPlot](https://traineq.org/implot_demo/src/implot_demo.html) library. The related demo widget looks like this:

I started implementing a similar feature for the egui plot widget which currently looks like this:
[simplescreenrecorder.webm](https://user-images.githubusercontent.com/80203331/200167865-b68dddf9-a7cf-4ed3-acac-b7ffc593b96d.webm)
And the API to create such a thing is:
```rust
let mut vals = Vec::new();
const ROWS: usize = 16; // tiles y
const COLS: usize = ROWS; // tiles x
// populate values
for x in 0..COLS {
for y in 0..ROWS {
let r = f32::sqrt((x.pow(2) + y.pow(2)) as f32);
vals.push(f64::sin(r as f64 + self.t as f64 / 100.0));
}
}
const RESOLUTION: usize = 256; // number of color steps in interpolated color palette
let heatmap = egui::plot::Heatmap::::new(vals, COLS)
.unwrap()
.show_labels(self.show_labels) // bool
.palette(self.color_gradient.clone()) // Vec
.name("something");
Plot::new("plot")
.legend(Legend::default())
.allow_zoom(false)
.allow_scroll(false)
.allow_boxed_zoom(false)
.allow_drag(false)
.set_margin_fraction(Vec2::new(0.0, 0.0))
.width(500.0)
.view_aspect(1.0)
.show(ui, |plot_ui| {
plot_ui.heatmap(heatmap);
});
```
## TODO
* axis legends (related to/depends on https://github.com/emilk/egui/issues/889). I also think axis labels and ticks should be **outside** of the plotting window, similar to ImPlot. ImPlot has an option to move the legend out of the plotting window which I find convenient, too.
* Value to color mapping is sometimes weird, debugging needed
* Legend (similar to ImPlot, an extra window that shows value-to-color-mapping).
Contributor guide
Assessment
This issue has not been assessed yet.