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
impl Plot
Sourcepub fn new(title: &str) -> Self
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.
Sourcepub fn size(self, size: [f32; 2]) -> Self
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
Sourcepub fn x_limits<L: Into<ImPlotRange>>(
self,
limits: L,
condition: Condition,
) -> Self
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.
Sourcepub fn linked_x_limits(self, limits: Rc<RefCell<ImPlotRange>>) -> Self
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.
Sourcepub fn y_limits<L: Into<ImPlotRange>>(
self,
limits: L,
y_axis_choice: YAxisChoice,
condition: Condition,
) -> Self
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.
Sourcepub fn y1_limits<L: Into<ImPlotRange>>(
self,
limits: L,
condition: Condition,
) -> Self
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
Sourcepub fn y2_limits<L: Into<ImPlotRange>>(
self,
limits: L,
condition: Condition,
) -> Self
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
Sourcepub fn y3_limits<L: Into<ImPlotRange>>(
self,
limits: L,
condition: Condition,
) -> Self
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
Sourcepub fn linked_y_limits(
self,
limits: Rc<RefCell<ImPlotRange>>,
y_axis_choice: YAxisChoice,
) -> Self
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.
Sourcepub fn linked_y1_limits(self, limits: Rc<RefCell<ImPlotRange>>) -> Self
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
.
Sourcepub fn linked_y2_limits(self, limits: Rc<RefCell<ImPlotRange>>) -> Self
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
.
Sourcepub fn linked_y3_limits(self, limits: Rc<RefCell<ImPlotRange>>) -> Self
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
.
Sourcepub fn x_ticks(self, ticks: &[f64], show_default: bool) -> Self
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.
Sourcepub fn y_ticks(
self,
y_axis_choice: YAxisChoice,
ticks: &[f64],
show_default: bool,
) -> Self
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.
Sourcepub fn x_ticks_with_labels(
self,
tick_labels: &[(f64, String)],
show_default: bool,
) -> Self
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.
Sourcepub fn y_ticks_with_labels(
self,
y_axis_choice: YAxisChoice,
tick_labels: &[(f64, String)],
show_default: bool,
) -> Self
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.
Sourcepub fn with_plot_flags(self, flags: &PlotFlags) -> Self
pub fn with_plot_flags(self, flags: &PlotFlags) -> Self
Set the plot flags, see the help for PlotFlags
for what the available flags are
Sourcepub fn with_x_axis_flags(self, flags: &AxisFlags) -> Self
pub fn with_x_axis_flags(self, flags: &AxisFlags) -> Self
Set the axis flags for the X axis in this plot
Sourcepub fn with_y_axis_flags(
self,
y_axis_choice: YAxisChoice,
flags: &AxisFlags,
) -> Self
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
Sourcepub fn with_legend_location(
self,
location: &PlotLocation,
orientation: &PlotOrientation,
outside: bool,
) -> Self
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
Sourcepub fn begin(&self, plot_ui: &PlotUi<'_>) -> Option<PlotToken>
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.