Skip to main content

Plot

Struct Plot 

Source
pub struct Plot<'a> { /* private fields */ }
Expand description

The plot builder. Add series, then call show with the icon cache and a PlotState.

let data: Vec<[f64; 2]> = (0..100).map(|i| [i as f64 * 0.1, (i as f64 * 0.1).sin()]).collect();
let mut state = PlotState::default();
let response = Plot::new("signal")
    .title("Signal")
    .x_label("t (s)")
    .y_label("V")
    .height(280.0)
    .series(Series::line("sin", &data))
    .series(Series::scatter("samples", &data[..10]))
    .show(ui, &mut icons, &mut state);
if let Some(hover) = response.hovered {
    let _ = hover.point;
}

Implementations§

Source§

impl<'a> Plot<'a>

Source

pub fn new(id: impl Hash + Debug) -> Self

A plot with a stable id.

Source

pub fn measurement_mode(self, mode: MeasurementMode) -> Self

Set the area tool mode: rectangle or curve-vs-chord.

Source

pub fn measurement_area_style(self, style: MeasurementAreaStyle) -> Self

Set which area the curve-segment label emphasizes.

Source

pub fn measurement_snap_radius(self, radius: f32) -> Self

Set the measurement snap radius in points.

Source

pub fn measurement_labels(self, show: bool) -> Self

Show or hide measurement labels.

Source

pub fn config(self, config: PlotConfig) -> Self

Replace the whole appearance (text, sizes, colors, axes, grid, legend, and per-series styles). Call it first; the other builder methods edit it.

Source

pub fn current_config(&self) -> &PlotConfig

The current appearance.

Source

pub fn series_names(&self) -> Vec<String>

The names of the series, in drawing order (for a settings dialog).

Source

pub fn x_limits(self, min: Option<f64>, max: Option<f64>) -> Self

Fixed x limits in data units (None keeps that side automatic).

Source

pub fn y_limits(self, min: Option<f64>, max: Option<f64>) -> Self

Fixed y limits in data units (None keeps that side automatic).

Source

pub fn settings_button(self, show: bool) -> Self

Show a settings button in the toolbar; see PlotResponse::settings_requested.

Source

pub fn export_button(self, show: bool) -> Self

Show an SVG/PNG export menu in the toolbar; see PlotResponse::export_requested.

Source

pub fn series(self, series: Series<'a>) -> Self

Add a series. Series draw in order; the palette color follows the order too.

Source

pub fn fit(self, kind: FitKind, data: &[[f64; 2]]) -> Self

Fit kind to data and add the dashed curve, named with its equation and R². Nothing is added when the fit fails (too few points, singular system).

Source

pub fn title(self, title: impl Into<String>) -> Self

A title above the frame.

Source

pub fn x_label(self, label: impl Into<String>) -> Self

The x axis label (also used in the hover popup).

Source

pub fn y_label(self, label: impl Into<String>) -> Self

The y axis label, drawn vertically.

Source

pub fn x_scale(self, scale: Scale) -> Self

Linear or log10 x axis.

Source

pub fn y_scale(self, scale: Scale) -> Self

Linear or log10 y axis.

Source

pub fn y2_label(self, label: impl Into<String>) -> Self

The right y axis title, drawn vertically (the axis shows when a series uses YAxis::Right).

Source

pub fn y2_scale(self, scale: Scale) -> Self

Linear or log10 right y axis.

Source

pub fn y2_limits(self, min: Option<f64>, max: Option<f64>) -> Self

Fixed right y limits in data units (None keeps that side automatic).

Source

pub fn width(self, width: f32) -> Self

Fixed width; fills the available width otherwise.

Source

pub fn height(self, height: f32) -> Self

Fixed height; fills the available height otherwise (320 pt in scroll areas).

Source

pub fn legend(self, legend: LegendPosition) -> Self

Legend corner, or LegendPosition::Hidden.

Source

pub fn legend_hover(self, config: LegendHoverConfig) -> Self

Replace the legend hover animation settings.

Source

pub fn renderer(self, renderer: Renderer) -> Self

Select the CPU or GPU data layer.

Source

pub fn legend_animation(self, animation: LegendAnimation) -> Self

The animation played while the pointer rests on a legend row (enabled by default).

Source

pub fn series_all(self, series: impl IntoIterator<Item = Series<'a>>) -> Self

Add every series from an iterator, for multi-series families such as box plots.

Source

pub fn direction(self, config: DirectionArrowConfig) -> Self

Replace the direction-arrow settings.

Source

pub fn direction_arrow(self, show: bool) -> Self

Show or hide the direction arrow beside the newest point of line-like series.

Source

pub fn direction_points(self, points: usize) -> Self

How many trailing samples measure the direction arrow (5 by default).

Source

pub fn pie(self, config: PieConfig) -> Self

Replace the pie/donut layout.

Source

pub fn radar(self, config: RadarConfig) -> Self

Replace the radar layout (labels, maximum, rings, fill).

Source

pub fn gauge(self, config: GaugeConfig) -> Self

Replace the gauge layout.

Source

pub fn heatmap(self, config: HeatmapConfig) -> Self

Replace the heatmap layout.

Source

pub fn waterfall(self, config: WaterfallConfig) -> Self

Replace the waterfall layout.

Source

pub fn grid(self, grid: bool) -> Self

Draw the grid (on by default).

Source

pub fn toolbar(self, toolbar: bool) -> Self

Show the tool buttons in the top-right corner (on by default).

Source

pub fn x_window(self, width: f64) -> Self

For streaming data: while the view is automatic, show only the last width x units.

Source

pub fn include(self, point: [f64; 2]) -> Self

Keep point inside the automatic view (for example [0.0, 0.0]).

Source§

impl Plot<'_>

Source

pub fn from_dataset(data: &Dataset) -> DatasetPlot<'_>

Start a plot bound to dataset columns.

Source§

impl Plot<'_>

Source

pub fn to_svg( &self, ctx: &Context, state: &PlotState, options: &ExportOptions, ) -> String

The plot as a standalone SVG document: the same view, colors, legend, and selection as on screen, without the toolbar and hover popup.

Source

pub fn to_pdf( &self, ctx: &Context, state: &PlotState, options: &ExportOptions, ) -> Vec<u8> ⓘ

The plot as a one-page vector PDF.

Source

pub fn to_png( &self, ctx: &Context, state: &PlotState, options: &ExportOptions, ) -> Result<Vec<u8>, String>

The plot as PNG bytes at options.scale pixels per point, rendered from the SVG with egui’s fonts.

§Errors

When the image is too large to allocate or encoding fails.

Source§

impl<'a> Plot<'a>

Source

pub fn chart_mode(&self) -> ChartMode

The chart family: the first special series wins (pie, then radar, then gauge). Mixing families in one plot is not meaningful; cartesian series need no marker.

Source§

impl Plot<'_>

Source

pub fn show( self, ui: &mut Ui, icons: &mut Icons, state: &mut PlotState, ) -> PlotResponse

Paint the plot and handle its interaction.

Trait Implementations§

Source§

impl<'a> Clone for Plot<'a>

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl IconComponent for Plot<'_>

Source§

type Output = PlotResponse

What the component returns after painting.
Source§

fn show(self, ui: &mut Ui, icons: &mut Icons) -> PlotResponse

Paint the component with the application’s icon cache.

Auto Trait Implementations§

§

impl<'a> !RefUnwindSafe for Plot<'a>

§

impl<'a> !Send for Plot<'a>

§

impl<'a> !Sync for Plot<'a>

§

impl<'a> !UnwindSafe for Plot<'a>

§

impl<'a> Forget for Plot<'a>

§

impl<'a> Freeze for Plot<'a>

§

impl<'a> Move for Plot<'a>

§

impl<'a> Unpin for Plot<'a>
where NonZero<u64>: Unpin, *const u8 is !null: Unpin, &'a [[f64; 2]]: Unpin, Vec<[f64; 2]>: Unpin, &'a [f64]: Unpin, Vec<f64>: Unpin, &'a [[f64; 5]]: Unpin, Vec<[f64; 5]>: Unpin, &'a [[f64; 3]]: Unpin, Vec<[f64; 3]>: Unpin, Arc<MinMaxPyramid>: Unpin,

§

impl<'a> UnsafeUnpin for Plot<'a>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, S> SimdFrom<T, S> for T
where S: Simd,

Source§

fn simd_from(_simd: S, value: T) -> T

Source§

impl<F, T, S> SimdInto<T, S> for F
where T: SimdFrom<F, S>, S: Simd,

Source§

fn simd_into(self, simd: S) -> T

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.