pub struct Axes { /* private fields */ }Expand description
A single set of axes within a figure, containing chart artists and configuration.
Users do not construct Axes directly; they are created by
[Figure::add_subplot] or the convenience function [Figure::subplots].
Once an Axes handle is obtained, chart methods such as plot,
scatter, and bar add data, and
configuration methods like set_title control labels,
limits, and styling.
Implementations§
Source§impl Axes
impl Axes
Sourcepub fn plot<X, Y>(&mut self, x: X, y: Y) -> Result<&mut LineArtist>where
X: IntoSeries,
Y: IntoSeries,
pub fn plot<X, Y>(&mut self, x: X, y: Y) -> Result<&mut LineArtist>where
X: IntoSeries,
Y: IntoSeries,
Plots a line connecting (x, y) data points.
Returns a mutable reference to the newly created LineArtist so
that the caller can chain builder methods (.color(), .width(),
.label(), etc.).
§Errors
Returns PlotError::SeriesLengthMismatch if x and y have
different lengths, or PlotError::EmptyData if either is empty.
Sourcepub fn scatter<X, Y>(&mut self, x: X, y: Y) -> Result<&mut ScatterArtist>where
X: IntoSeries,
Y: IntoSeries,
pub fn scatter<X, Y>(&mut self, x: X, y: Y) -> Result<&mut ScatterArtist>where
X: IntoSeries,
Y: IntoSeries,
Creates a scatter plot of (x, y) data points.
Returns a mutable reference to the ScatterArtist for chaining.
§Errors
Returns PlotError::SeriesLengthMismatch or PlotError::EmptyData
on invalid input.
Sourcepub fn bar<C, H>(&mut self, categories: C, heights: H) -> Result<&mut BarArtist>where
C: IntoCategories,
H: IntoSeries,
pub fn bar<C, H>(&mut self, categories: C, heights: H) -> Result<&mut BarArtist>where
C: IntoCategories,
H: IntoSeries,
Creates a vertical bar chart from categorical data and heights.
Each category label maps to one bar whose height is the corresponding
value in heights.
§Errors
Returns PlotError::SeriesLengthMismatch if categories and
heights have different lengths, or PlotError::EmptyData if empty.
Sourcepub fn barh<C, W>(&mut self, categories: C, widths: W) -> Result<&mut BarArtist>where
C: IntoCategories,
W: IntoSeries,
pub fn barh<C, W>(&mut self, categories: C, widths: W) -> Result<&mut BarArtist>where
C: IntoCategories,
W: IntoSeries,
Sourcepub fn hist<D>(&mut self, data: D, bins: usize) -> Result<&mut HistArtist>where
D: IntoSeries,
pub fn hist<D>(&mut self, data: D, bins: usize) -> Result<&mut HistArtist>where
D: IntoSeries,
Creates a histogram from raw data.
The data is partitioned into bins equal-width bins spanning the data
range, and each bin is drawn as a vertical bar whose height equals the
count of values falling in that bin.
§Errors
Returns PlotError::EmptyData if data is empty.
Sourcepub fn fill_between<X, Y1, Y2>(
&mut self,
x: X,
y1: Y1,
y2: Y2,
) -> Result<&mut FillBetweenArtist>
pub fn fill_between<X, Y1, Y2>( &mut self, x: X, y1: Y1, y2: Y2, ) -> Result<&mut FillBetweenArtist>
Fills the area between two y-series that share the same x values.
Useful for confidence intervals, envelopes, and area charts.
§Errors
Returns PlotError::SeriesLengthMismatch if any of the three
series differ in length, or PlotError::EmptyData if empty.
Sourcepub fn step<X: IntoSeries, Y: IntoSeries>(
&mut self,
x: X,
y: Y,
) -> Result<&mut StepArtist>
pub fn step<X: IntoSeries, Y: IntoSeries>( &mut self, x: X, y: Y, ) -> Result<&mut StepArtist>
Plots a step (staircase) chart connecting (x, y) data points.
Returns a mutable reference to the StepArtist for chaining.
§Errors
Returns PlotError::SeriesLengthMismatch or PlotError::EmptyData
on invalid input.
Sourcepub fn stem<X: IntoSeries, Y: IntoSeries>(
&mut self,
x: X,
y: Y,
) -> Result<&mut StemArtist>
pub fn stem<X: IntoSeries, Y: IntoSeries>( &mut self, x: X, y: Y, ) -> Result<&mut StemArtist>
Plots a stem (lollipop) chart from (x, y) data points.
Returns a mutable reference to the StemArtist for chaining.
§Errors
Returns PlotError::SeriesLengthMismatch or PlotError::EmptyData
on invalid input.
Sourcepub fn boxplot(&mut self, datasets: Vec<Vec<f64>>) -> Result<&mut BoxPlotArtist>
pub fn boxplot(&mut self, datasets: Vec<Vec<f64>>) -> Result<&mut BoxPlotArtist>
Creates a box-and-whisker plot from one or more data groups.
Each inner Vec<f64> produces one box. Groups are placed at integer
x-positions starting from 0.
§Errors
Returns PlotError::EmptyData if datasets is empty.
Sourcepub fn errorbar<X: IntoSeries, Y: IntoSeries>(
&mut self,
x: X,
y: Y,
) -> Result<ErrorBarArtist>
pub fn errorbar<X: IntoSeries, Y: IntoSeries>( &mut self, x: X, y: Y, ) -> Result<ErrorBarArtist>
Creates an error bar plot from (x, y) data points.
Returns an owned ErrorBarArtist that can be configured with
builder methods (.yerr_symmetric(), .cap_size(), etc.) and then
added to the axes via add_errorbar.
§Errors
Returns PlotError::SeriesLengthMismatch or PlotError::EmptyData
on invalid input.
Sourcepub fn add_errorbar(&mut self, artist: ErrorBarArtist)
pub fn add_errorbar(&mut self, artist: ErrorBarArtist)
Adds a finalized ErrorBarArtist to the axes.
Use this after configuring the artist returned by
errorbar.
Sourcepub fn heatmap(&mut self, data: Vec<Vec<f64>>) -> Result<&mut HeatmapArtist>
pub fn heatmap(&mut self, data: Vec<Vec<f64>>) -> Result<&mut HeatmapArtist>
Creates a heatmap from a 2D grid of values.
Returns a mutable reference to the HeatmapArtist for chaining
builder methods (.colormap(), .vmin(), .show_values(), etc.).
§Errors
Returns PlotError::EmptyData if data is empty.
Sourcepub fn pie<S: IntoSeries>(&mut self, sizes: S) -> Result<&mut PieArtist>
pub fn pie<S: IntoSeries>(&mut self, sizes: S) -> Result<&mut PieArtist>
Creates a pie chart from wedge sizes.
The sizes are automatically normalised so that all wedges sum to
a full circle. Returns a mutable reference to the PieArtist
for chaining builder methods (.labels(), .autopct(),
.explode(), etc.).
§Errors
Returns PlotError::EmptyData if sizes is empty.
Source§impl Axes
impl Axes
Sourcepub fn set_title(&mut self, title: &str) -> &mut Self
pub fn set_title(&mut self, title: &str) -> &mut Self
Sets the title displayed above the axes area.
Sourcepub fn set_xlabel(&mut self, label: &str) -> &mut Self
pub fn set_xlabel(&mut self, label: &str) -> &mut Self
Sets the x-axis label.
Sourcepub fn set_ylabel(&mut self, label: &str) -> &mut Self
pub fn set_ylabel(&mut self, label: &str) -> &mut Self
Sets the y-axis label.
Sourcepub fn set_xlim(&mut self, min: f64, max: f64) -> &mut Self
pub fn set_xlim(&mut self, min: f64, max: f64) -> &mut Self
Sets explicit x-axis limits. Pass (min, max).
Sourcepub fn set_ylim(&mut self, min: f64, max: f64) -> &mut Self
pub fn set_ylim(&mut self, min: f64, max: f64) -> &mut Self
Sets explicit y-axis limits. Pass (min, max).
Sourcepub fn set_xscale(&mut self, scale: Scale) -> &mut Self
pub fn set_xscale(&mut self, scale: Scale) -> &mut Self
Sets the x-axis scale (linear, log10, symlog).
Sourcepub fn set_yscale(&mut self, scale: Scale) -> &mut Self
pub fn set_yscale(&mut self, scale: Scale) -> &mut Self
Sets the y-axis scale (linear, log10, symlog).
Sourcepub fn set_legend_loc(&mut self, loc: Loc) -> &mut Self
pub fn set_legend_loc(&mut self, loc: Loc) -> &mut Self
Sets the legend location.
Sourcepub fn set_theme(&mut self, theme: Theme) -> &mut Self
pub fn set_theme(&mut self, theme: Theme) -> &mut Self
Overrides the figure theme for this axes only.
Sourcepub fn grid_axis(&mut self, axis: &str) -> &mut Self
pub fn grid_axis(&mut self, axis: &str) -> &mut Self
Sets which axes display grid lines.
Accepts "x", "y", or "both" (the default). Unrecognised values
are silently treated as "both".
Sourcepub fn grid_alpha(&mut self, alpha: f64) -> &mut Self
pub fn grid_alpha(&mut self, alpha: f64) -> &mut Self
Sets the grid line opacity (0.0 = fully transparent, 1.0 = fully opaque).
Sourcepub fn grid_style(&mut self, style: LineStyle) -> &mut Self
pub fn grid_style(&mut self, style: LineStyle) -> &mut Self
Sets the grid line style.
Sourcepub fn invert_xaxis(&mut self) -> &mut Self
pub fn invert_xaxis(&mut self) -> &mut Self
Inverts the x-axis so that larger values appear on the left.
Sourcepub fn invert_yaxis(&mut self) -> &mut Self
pub fn invert_yaxis(&mut self) -> &mut Self
Inverts the y-axis so that larger values appear at the bottom.
Sourcepub fn set_xticks(&mut self, ticks: &[f64]) -> &mut Self
pub fn set_xticks(&mut self, ticks: &[f64]) -> &mut Self
Sets custom tick positions on the x-axis.
When set, the auto-generated ticks are replaced by these positions.
Sourcepub fn set_yticks(&mut self, ticks: &[f64]) -> &mut Self
pub fn set_yticks(&mut self, ticks: &[f64]) -> &mut Self
Sets custom tick positions on the y-axis.
When set, the auto-generated ticks are replaced by these positions.
Sourcepub fn set_xticklabels(&mut self, labels: &[&str]) -> &mut Self
pub fn set_xticklabels(&mut self, labels: &[&str]) -> &mut Self
Sets custom tick labels for the x-axis.
The number of labels should match the number of custom tick positions
set via set_xticks. Extra labels are ignored;
missing labels default to the formatted tick value.
Sourcepub fn set_yticklabels(&mut self, labels: &[&str]) -> &mut Self
pub fn set_yticklabels(&mut self, labels: &[&str]) -> &mut Self
Sets custom tick labels for the y-axis.
The number of labels should match the number of custom tick positions
set via set_yticks. Extra labels are ignored;
missing labels default to the formatted tick value.
Sourcepub fn tick_params_x_rotation(&mut self, degrees: f64) -> &mut Self
pub fn tick_params_x_rotation(&mut self, degrees: f64) -> &mut Self
Sets the rotation angle (in degrees) for x-axis tick labels.
Sourcepub fn tick_params_y_rotation(&mut self, degrees: f64) -> &mut Self
pub fn tick_params_y_rotation(&mut self, degrees: f64) -> &mut Self
Sets the rotation angle (in degrees) for y-axis tick labels.
Sourcepub fn text(&mut self, x: f64, y: f64, text: &str) -> &mut TextAnnotation
pub fn text(&mut self, x: f64, y: f64, text: &str) -> &mut TextAnnotation
Places a text label at data coordinates (x, y).
Returns a mutable reference to the TextAnnotation for builder-style
configuration (.fontsize(), .color(), .ha(), .va(), .rotation()).
Text annotations do not affect autoscale; they annotate existing data without expanding the axis limits.
Sourcepub fn annotate(
&mut self,
text: &str,
xy: (f64, f64),
xytext: (f64, f64),
) -> &mut Annotation
pub fn annotate( &mut self, text: &str, xy: (f64, f64), xytext: (f64, f64), ) -> &mut Annotation
Annotates the data point xy with text placed at xytext.
Returns a mutable reference to the Annotation for builder-style
configuration (.fontsize(), .color(), .ha(), .va(),
.arrowstyle(), .arrow_color()).
When an ArrowStyle other than ArrowStyle::None is set, an arrow
is drawn from xytext to xy. Annotations do not affect autoscale.
Source§impl Axes
impl Axes
Sourcepub fn contour(
&mut self,
x: &[f64],
y: &[f64],
z: Vec<Vec<f64>>,
) -> Result<&mut ContourArtist>
pub fn contour( &mut self, x: &[f64], y: &[f64], z: Vec<Vec<f64>>, ) -> Result<&mut ContourArtist>
Creates a contour plot (iso-lines) from a 2D grid of z values.
Sourcepub fn contourf(
&mut self,
x: &[f64],
y: &[f64],
z: Vec<Vec<f64>>,
) -> Result<&mut ContourArtist>
pub fn contourf( &mut self, x: &[f64], y: &[f64], z: Vec<Vec<f64>>, ) -> Result<&mut ContourArtist>
Creates a filled contour plot from a 2D grid of z values.
Source§impl Axes
impl Axes
Sourcepub fn collect_legend_entries(&self) -> Vec<LegendEntry>
pub fn collect_legend_entries(&self) -> Vec<LegendEntry>
Collects legend entries from this axes’ artists.