Struct Plot

Source
pub struct Plot { /* private fields */ }
Expand description

Struct to represent an ImPlot. This is the main construct used to contain all kinds of plots in ImPlot.

Plot is to be used (within an imgui window) with the following pattern:

let plotting_context = implot::Context::create();
let plot_ui = plotting_context.get_plot_ui();
implot::Plot::new("my title")
    .size([300.0, 200.0]) // other things such as .x_label("some_label") can be added too
    .build(&plot_ui, || {
        // Do things such as plotting lines
    });

(If you are coming from the C++ implementation or the C bindings: build() calls both begin() and end() internally)

Implementations§

Source§

impl Plot

Source

pub fn new(title: &str) -> Self

Create a new plot with some defaults set. Does not draw anything yet. Note that this uses antialiasing by default, unlike the C++ API. If you are seeing artifacts or weird rendering, try disabling it.

Source

pub fn size(self, size: [f32; 2]) -> Self

Sets the plot size, given as [size_x, size_y]. Units are the same as what imgui uses. TODO(4bb4) … which is? I’m not sure it’s pixels

Source

pub fn x_label(self, label: &str) -> Self

Set the x label of the plot

Source

pub fn y_label(self, label: &str) -> Self

Set the y label of the plot

Source

pub fn x_limits<L: Into<ImPlotRange>>( self, limits: L, condition: Condition, ) -> Self

Set the x limits of the plot.

Note: This conflicts with linked_x_limits, whichever is called last on plot construction takes effect.

Source

pub fn linked_x_limits(self, limits: Rc<RefCell<ImPlotRange>>) -> Self

Set linked x limits for this plot. Pass clones of the same Rc into other plots to link their limits with the same values.

Note: This conflicts with x_limits, whichever is called last on plot construction takes effect.

Source

pub fn y_limits<L: Into<ImPlotRange>>( self, limits: L, y_axis_choice: YAxisChoice, condition: Condition, ) -> Self

Set the Y limits of the plot for the given Y axis. Call multiple times with different y_axis_choice values to set for multiple axes, or use the convenience methods such as Plot::y1_limits.

Note: This conflicts with linked_y_limits, whichever is called last on plot construction takes effect for a given axis.

Source

pub fn y1_limits<L: Into<ImPlotRange>>( self, limits: L, condition: Condition, ) -> Self

Convenience function to directly set the Y limits for the first Y axis. To programmatically (or on demand) decide which axis to set limits for, use Plot::y_limits

Source

pub fn y2_limits<L: Into<ImPlotRange>>( self, limits: L, condition: Condition, ) -> Self

Convenience function to directly set the Y limits for the second Y axis. To programmatically (or on demand) decide which axis to set limits for, use Plot::y_limits

Source

pub fn y3_limits<L: Into<ImPlotRange>>( self, limits: L, condition: Condition, ) -> Self

Convenience function to directly set the Y limits for the third Y axis. To programmatically (or on demand) decide which axis to set limits for, use Plot::y_limits

Source

pub fn linked_y_limits( self, limits: Rc<RefCell<ImPlotRange>>, y_axis_choice: YAxisChoice, ) -> Self

Set linked Y limits of the plot for the given Y axis. Pass clones of the same Rc into other plots to link their limits with the same values. Call multiple times with different y_axis_choice values to set for multiple axes, or use the convenience methods such as Plot::y1_limits.

Note: This conflicts with y_limits, whichever is called last on plot construction takes effect for a given axis.

Source

pub fn linked_y1_limits(self, limits: Rc<RefCell<ImPlotRange>>) -> Self

Convenience function to directly set linked Y limits for the first Y axis. To programmatically (or on demand) decide which axis to set limits for, use Plot::linked_y_limits.

Source

pub fn linked_y2_limits(self, limits: Rc<RefCell<ImPlotRange>>) -> Self

Convenience function to directly set linked Y limits for the second Y axis. To programmatically (or on demand) decide which axis to set limits for, use Plot::linked_y_limits.

Source

pub fn linked_y3_limits(self, limits: Rc<RefCell<ImPlotRange>>) -> Self

Convenience function to directly set linked Y limits for the third Y axis. To programmatically (or on demand) decide which axis to set limits for, use Plot::linked_y_limits.

Source

pub fn x_ticks(self, ticks: &[f64], show_default: bool) -> Self

Set X ticks without labels for the plot. The vector contains one label each in the form of a tuple (label_position, label_string). The show_default setting determines whether the default ticks are also shown.

Source

pub fn y_ticks( self, y_axis_choice: YAxisChoice, ticks: &[f64], show_default: bool, ) -> Self

Set X ticks without labels for the plot. The vector contains one label each in the form of a tuple (label_position, label_string). The show_default setting determines whether the default ticks are also shown.

Source

pub fn x_ticks_with_labels( self, tick_labels: &[(f64, String)], show_default: bool, ) -> Self

Set X ticks with labels for the plot. The vector contains one position and label each in the form of a tuple (label_position, label_string). The show_default setting determines whether the default ticks are also shown.

Source

pub fn y_ticks_with_labels( self, y_axis_choice: YAxisChoice, tick_labels: &[(f64, String)], show_default: bool, ) -> Self

Set Y ticks with labels for the plot. The vector contains one position and label each in the form of a tuple (label_position, label_string). The show_default setting determines whether the default ticks are also shown.

Source

pub fn with_plot_flags(self, flags: &PlotFlags) -> Self

Set the plot flags, see the help for PlotFlags for what the available flags are

Source

pub fn with_x_axis_flags(self, flags: &AxisFlags) -> Self

Set the axis flags for the X axis in this plot

Source

pub fn with_y_axis_flags( self, y_axis_choice: YAxisChoice, flags: &AxisFlags, ) -> Self

Set the axis flags for the selected Y axis in this plot

Source

pub fn with_legend_location( self, location: &PlotLocation, orientation: &PlotOrientation, outside: bool, ) -> Self

Set the legend location, orientation and whether it is to be drawn outside the plot

Source

pub fn begin(&self, plot_ui: &PlotUi<'_>) -> Option<PlotToken>

Attempt to show the plot. If this returns a token, the plot will actually be drawn. In this case, use the drawing functionality to draw things on the plot, and then call end() on the token when done with the plot. If none was returned, that means the plot is not rendered.

For a convenient implementation of all this, use build() instead.

Source

pub fn build<F: FnOnce()>(self, plot_ui: &PlotUi<'_>, f: F)

Creates a window and runs a closure to construct the contents. This internally calls begin and end.

Note: the closure is not called if ImPlot::BeginPlot() returned false - TODO(4bb4) figure out if this is if things are not rendered

Auto Trait Implementations§

§

impl Freeze for Plot

§

impl !RefUnwindSafe for Plot

§

impl !Send for Plot

§

impl !Sync for Plot

§

impl Unpin for Plot

§

impl !UnwindSafe for Plot

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<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, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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.