egui_plot

repository·main·Indexed 19 days ago

https://github.com/emilk/egui_plot

An immediate mode 2D plotting library for the egui framework in Rust, providing tools for interactive data visualization. It supports various plot items including lines, polygons, points, arrows, text, images, heatmaps, histograms, and box-and-whisker plots. Key features include performance optimizations via PlotPoints::Borrowed, custom axis formatting, linked axes for synchronized views, and the ability to export plots as PNG images.

Tokens
27.9K
Snippets
57
Records
102
Agent score
66%

What's inside egui_plot

  1. Matplotlib compatibility goals and missing features

    main

    The long-term goal of egui_plot is to support all matplotlib examples. Currently, several styles and pyplot functionalities are identified as missing or needing implementation. Developers looking to extend the library can refer to the following categories of missing features:

    Style Sheets

    Support for various Matplotlib style sheets is currently missing, including:

    • bmh (Bayesian Methods for Hackers)
    • dark_background
    • fivethirtyeight
    • ggplot
    • grayscale
    • petroff10
    • solarized_light

    Pyplot Module Functionality

    Key functionalities from the Matplotlib pyplot module that are still being implemented include:

    • Advanced text and mathtext support.
    • Multiple line plot configurations.
    • Subplot management (e.g., creating multiple subplots in a single figure).
    • Complex 2D plot compositions.
  2. Current limitations and missing features in egui_plot

    main

    The long-term goal of egui_plot is to support all matplotlib examples. Currently, several interactive widgets and layout features found in Matplotlib are not yet implemented or fully supported in egui_plot.

    Missing Interactivity Widgets

    Many interactive components are currently missing, including:

    • Selectors: Lasso Selector, Polygon Selector, Rectangle and ellipse selectors, Span Selector.
    • Cursors: Annotated cursor, Cursor, Mouse Cursor, Multicursor.
    • Input Controls: Buttons, Check buttons, Menu, Radio Buttons, Slider, Textbox, RangeSlider.

    Missing Layout and Plotting Features

    • Subplots and Layout: Support for complex layouts like Nested GridSpecs and snapping sliders to discrete values.
    • Legends: Advanced legend implementations (e.g., those used in Span Selector).
    • Image Plots: Support for image-based plotting combined with selectors.
  3. Understand the Matplotlib compatibility goal

    main

    The long-term goal of egui_plot is to support all matplotlib examples. This means implementing missing features required to replicate the functionality found in various Matplotlib GUI embedding demos (such as GTK, Qt, Tk, and wx).

    If you are looking for specific features that are currently missing or under development, you can track them via GitHub issue labels such as component: figure, component: interactivity, component: text, component: histogram, component: annotation, and component: spectral plot.

  4. Use `PlotPoints::Borrowed` to avoid data cloning

    main

    When creating plot lines in egui_plot, you can use PlotPoints::Borrowed to reference existing data instead of cloning it. This is a performance optimization that avoids unnecessary allocations, making it ideal for performance-critical applications or scenarios where the same data is reused across multiple frames.

    Instead of passing owned data that requires a copy, you provide a reference to the data, allowing the plot to read directly from your existing buffers.

    // Conceptual usage of Borrowed points to avoid cloning
    let data: Vec<[f64; 2]> = get_large_dataset();
    let points = PlotPoints::Borrowed(&data);
    // Use points in your plot line creation
  5. Current limitations in unit support

    main
    The project has a long-term goal to support all matplotlib examples. Currently, several features related to unit handling (such as annotations with units, radian ticks, and unit-aware bar charts) are missing in egui_plot. If you need specific unit-based plotting capabilities, check the existing issues tagged with component: units to see the current status of implementation.
  6. Why choose egui_plot over other Rust plotting libraries

    main

    When deciding on a plotting library for Rust, egui_plot offers two primary advantages over the alternatives found in the ecosystem:

    1. Native Rust Interactivity: Unlike many other libraries (such as plotters) that require JavaScript or other binding layers for interactivity, egui_plot supports plot interactions directly through Rust.
    2. High Performance via GPU Acceleration: egui_plot produces a list of painting commands sent to a backend renderer. This allows for GPU acceleration and easy integration into other GUIs via egui, making it efficient for rendering large numbers of interactive plot items.
  7. Run the Line Demo example

    main

    The Line Demo showcases line plotting features such as animated lines, various line styles (solid, dashed, dotted), gradients, fills, axis inversion, and coordinate display. You can run this example either natively or in a web browser via WASM.

    ### Native
    ```sh
    cargo run -p lines

    Web (WASM)

    cd examples/lines
    trunk serve
  8. Run the Interaction Demo

    main

    The Interaction Demo showcases how to interact with plots programmatically, including accessing plot bounds, pointer coordinates, drag deltas, and detecting hovered plot items. You can run this example as a native application or as a web application using WASM.

    # Run as a native application
    cargo run -p interaction
    
    # Run as a web application (WASM)
    cd examples/interaction
    trunk serve
  9. Run the Heatmap Demo

    main

    The Heatmap Demo showcases how to create animated heatmaps using egui_plot. It visualizes a 2D grid of values using color gradients (specifically the Turbo colormap) and allows for customizable dimensions, labels, and palettes.

    To run the demo locally using Cargo:

    cargo run -p heatmap

    To run the demo in a web browser using WASM and Trunk:

    cd examples/heatmap
    trunk serve
    # Native execution
    cargo run -p heatmap
    
    # Web (WASM) execution
    cd examples/heatmap
    trunk serve