Skip to main content

Axes

Struct Axes 

Source
pub struct Axes {
    pub title: Option<String>,
    pub x_config: AxisConfig,
    pub y_config: AxisConfig,
    pub legend_position: LegendPosition,
    pub show_legend: bool,
    /* private fields */
}
Expand description

A single plot area containing axes, series, and legend configuration.

Fields§

§title: Option<String>

Title for this plot area.

§x_config: AxisConfig

X-axis configuration.

§y_config: AxisConfig

Y-axis configuration.

§legend_position: LegendPosition

Legend position.

§show_legend: bool

Whether to show the legend.

Implementations§

Source§

impl Axes

Source

pub fn new() -> Self

Create a new axes.

Source

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

Set the plot title.

Source

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

Set the X-axis label.

Examples found in repository?
examples/training_curves.rs (line 53)
10fn main() -> Result<()> {
11    // ── Simulate training curves ─────────────────────────────────────
12    let epochs: Vec<f64> = (1..=50).map(f64::from).collect();
13
14    // Training loss: exponential decay + noise
15    let mut rng = SimpleRng::new(42);
16    let train_loss: Vec<f64> = epochs
17        .iter()
18        .map(|&e| 2.0 * (-e / 15.0).exp() + 0.05 + rng.normal() * 0.02)
19        .collect();
20
21    // Validation loss: decays slower, starts overfitting around epoch 30
22    let val_loss: Vec<f64> = epochs
23        .iter()
24        .map(|&e| {
25            let base = 2.0 * (-e / 20.0).exp() + 0.1;
26            let overfit = if e > 30.0 { (e - 30.0) * 0.005 } else { 0.0 };
27            base + overfit + rng.normal() * 0.03
28        })
29        .collect();
30
31    // Training accuracy: rises from ~50% to ~98%
32    let train_acc: Vec<f64> = epochs
33        .iter()
34        .map(|&e| (0.98 - 0.48 * (-e / 12.0).exp()).min(1.0) + rng.normal() * 0.01)
35        .collect();
36
37    // Validation accuracy: rises but plateaus earlier
38    let val_acc: Vec<f64> = epochs
39        .iter()
40        .map(|&e| {
41            let base = 0.93 - 0.43 * (-e / 18.0).exp();
42            let overfit = if e > 30.0 { -(e - 30.0) * 0.002 } else { 0.0 };
43            (base + overfit + rng.normal() * 0.015).min(1.0)
44        })
45        .collect();
46
47    // ── Plot 1: Loss curves ──────────────────────────────────────────
48    let mut fig = Figure::new()
49        .size(750.0, 500.0)
50        .title("Training & Validation Loss");
51
52    let ax = fig.add_axes();
53    ax.x_label("Epoch").y_label("Loss");
54    ax.line(&epochs, &train_loss)
55        .label("Train Loss")
56        .color(Color::from_hex("#1f77b4").unwrap().into())
57        .width(2.0)
58        .done();
59    ax.line(&epochs, &val_loss)
60        .label("Val Loss")
61        .color(Color::from_hex("#ff7f0e").unwrap().into())
62        .width(2.0)
63        .dash(&[8.0, 4.0])
64        .done();
65
66    fig.save_svg("training_loss.svg")?;
67    println!("Saved training_loss.svg");
68
69    // ── Plot 2: Accuracy curves ──────────────────────────────────────
70    let mut fig2 = Figure::new()
71        .size(750.0, 500.0)
72        .title("Training & Validation Accuracy");
73
74    let ax2 = fig2.add_axes();
75    ax2.x_label("Epoch").y_label("Accuracy").y_range(0.4, 1.05);
76    ax2.line(&epochs, &train_acc)
77        .label("Train Accuracy")
78        .color(Color::from_hex("#2ca02c").unwrap().into())
79        .width(2.0)
80        .done();
81    ax2.line(&epochs, &val_acc)
82        .label("Val Accuracy")
83        .color(Color::from_hex("#d62728").unwrap().into())
84        .width(2.0)
85        .dash(&[8.0, 4.0])
86        .done();
87
88    fig2.save_svg("training_accuracy.svg")?;
89    println!("Saved training_accuracy.svg");
90
91    Ok(())
92}
Source

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

Set the Y-axis label.

Examples found in repository?
examples/training_curves.rs (line 53)
10fn main() -> Result<()> {
11    // ── Simulate training curves ─────────────────────────────────────
12    let epochs: Vec<f64> = (1..=50).map(f64::from).collect();
13
14    // Training loss: exponential decay + noise
15    let mut rng = SimpleRng::new(42);
16    let train_loss: Vec<f64> = epochs
17        .iter()
18        .map(|&e| 2.0 * (-e / 15.0).exp() + 0.05 + rng.normal() * 0.02)
19        .collect();
20
21    // Validation loss: decays slower, starts overfitting around epoch 30
22    let val_loss: Vec<f64> = epochs
23        .iter()
24        .map(|&e| {
25            let base = 2.0 * (-e / 20.0).exp() + 0.1;
26            let overfit = if e > 30.0 { (e - 30.0) * 0.005 } else { 0.0 };
27            base + overfit + rng.normal() * 0.03
28        })
29        .collect();
30
31    // Training accuracy: rises from ~50% to ~98%
32    let train_acc: Vec<f64> = epochs
33        .iter()
34        .map(|&e| (0.98 - 0.48 * (-e / 12.0).exp()).min(1.0) + rng.normal() * 0.01)
35        .collect();
36
37    // Validation accuracy: rises but plateaus earlier
38    let val_acc: Vec<f64> = epochs
39        .iter()
40        .map(|&e| {
41            let base = 0.93 - 0.43 * (-e / 18.0).exp();
42            let overfit = if e > 30.0 { -(e - 30.0) * 0.002 } else { 0.0 };
43            (base + overfit + rng.normal() * 0.015).min(1.0)
44        })
45        .collect();
46
47    // ── Plot 1: Loss curves ──────────────────────────────────────────
48    let mut fig = Figure::new()
49        .size(750.0, 500.0)
50        .title("Training & Validation Loss");
51
52    let ax = fig.add_axes();
53    ax.x_label("Epoch").y_label("Loss");
54    ax.line(&epochs, &train_loss)
55        .label("Train Loss")
56        .color(Color::from_hex("#1f77b4").unwrap().into())
57        .width(2.0)
58        .done();
59    ax.line(&epochs, &val_loss)
60        .label("Val Loss")
61        .color(Color::from_hex("#ff7f0e").unwrap().into())
62        .width(2.0)
63        .dash(&[8.0, 4.0])
64        .done();
65
66    fig.save_svg("training_loss.svg")?;
67    println!("Saved training_loss.svg");
68
69    // ── Plot 2: Accuracy curves ──────────────────────────────────────
70    let mut fig2 = Figure::new()
71        .size(750.0, 500.0)
72        .title("Training & Validation Accuracy");
73
74    let ax2 = fig2.add_axes();
75    ax2.x_label("Epoch").y_label("Accuracy").y_range(0.4, 1.05);
76    ax2.line(&epochs, &train_acc)
77        .label("Train Accuracy")
78        .color(Color::from_hex("#2ca02c").unwrap().into())
79        .width(2.0)
80        .done();
81    ax2.line(&epochs, &val_acc)
82        .label("Val Accuracy")
83        .color(Color::from_hex("#d62728").unwrap().into())
84        .width(2.0)
85        .dash(&[8.0, 4.0])
86        .done();
87
88    fig2.save_svg("training_accuracy.svg")?;
89    println!("Saved training_accuracy.svg");
90
91    Ok(())
92}
Source

pub fn x_range(&mut self, min: f64, max: f64) -> &mut Self

Set the X-axis range manually.

Source

pub fn y_range(&mut self, min: f64, max: f64) -> &mut Self

Set the Y-axis range manually.

Examples found in repository?
examples/training_curves.rs (line 75)
10fn main() -> Result<()> {
11    // ── Simulate training curves ─────────────────────────────────────
12    let epochs: Vec<f64> = (1..=50).map(f64::from).collect();
13
14    // Training loss: exponential decay + noise
15    let mut rng = SimpleRng::new(42);
16    let train_loss: Vec<f64> = epochs
17        .iter()
18        .map(|&e| 2.0 * (-e / 15.0).exp() + 0.05 + rng.normal() * 0.02)
19        .collect();
20
21    // Validation loss: decays slower, starts overfitting around epoch 30
22    let val_loss: Vec<f64> = epochs
23        .iter()
24        .map(|&e| {
25            let base = 2.0 * (-e / 20.0).exp() + 0.1;
26            let overfit = if e > 30.0 { (e - 30.0) * 0.005 } else { 0.0 };
27            base + overfit + rng.normal() * 0.03
28        })
29        .collect();
30
31    // Training accuracy: rises from ~50% to ~98%
32    let train_acc: Vec<f64> = epochs
33        .iter()
34        .map(|&e| (0.98 - 0.48 * (-e / 12.0).exp()).min(1.0) + rng.normal() * 0.01)
35        .collect();
36
37    // Validation accuracy: rises but plateaus earlier
38    let val_acc: Vec<f64> = epochs
39        .iter()
40        .map(|&e| {
41            let base = 0.93 - 0.43 * (-e / 18.0).exp();
42            let overfit = if e > 30.0 { -(e - 30.0) * 0.002 } else { 0.0 };
43            (base + overfit + rng.normal() * 0.015).min(1.0)
44        })
45        .collect();
46
47    // ── Plot 1: Loss curves ──────────────────────────────────────────
48    let mut fig = Figure::new()
49        .size(750.0, 500.0)
50        .title("Training & Validation Loss");
51
52    let ax = fig.add_axes();
53    ax.x_label("Epoch").y_label("Loss");
54    ax.line(&epochs, &train_loss)
55        .label("Train Loss")
56        .color(Color::from_hex("#1f77b4").unwrap().into())
57        .width(2.0)
58        .done();
59    ax.line(&epochs, &val_loss)
60        .label("Val Loss")
61        .color(Color::from_hex("#ff7f0e").unwrap().into())
62        .width(2.0)
63        .dash(&[8.0, 4.0])
64        .done();
65
66    fig.save_svg("training_loss.svg")?;
67    println!("Saved training_loss.svg");
68
69    // ── Plot 2: Accuracy curves ──────────────────────────────────────
70    let mut fig2 = Figure::new()
71        .size(750.0, 500.0)
72        .title("Training & Validation Accuracy");
73
74    let ax2 = fig2.add_axes();
75    ax2.x_label("Epoch").y_label("Accuracy").y_range(0.4, 1.05);
76    ax2.line(&epochs, &train_acc)
77        .label("Train Accuracy")
78        .color(Color::from_hex("#2ca02c").unwrap().into())
79        .width(2.0)
80        .done();
81    ax2.line(&epochs, &val_acc)
82        .label("Val Accuracy")
83        .color(Color::from_hex("#d62728").unwrap().into())
84        .width(2.0)
85        .dash(&[8.0, 4.0])
86        .done();
87
88    fig2.save_svg("training_accuracy.svg")?;
89    println!("Saved training_accuracy.svg");
90
91    Ok(())
92}
Source

pub fn x_axis(&mut self, config: AxisConfig) -> &mut Self

Set X-axis config.

Source

pub fn y_axis(&mut self, config: AxisConfig) -> &mut Self

Set Y-axis config.

Source

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

Set legend position.

Source

pub fn line(&mut self, x: &[f64], y: &[f64]) -> LineBuilder<'_>

Add a line series and return a builder for customization.

Examples found in repository?
examples/training_curves.rs (line 54)
10fn main() -> Result<()> {
11    // ── Simulate training curves ─────────────────────────────────────
12    let epochs: Vec<f64> = (1..=50).map(f64::from).collect();
13
14    // Training loss: exponential decay + noise
15    let mut rng = SimpleRng::new(42);
16    let train_loss: Vec<f64> = epochs
17        .iter()
18        .map(|&e| 2.0 * (-e / 15.0).exp() + 0.05 + rng.normal() * 0.02)
19        .collect();
20
21    // Validation loss: decays slower, starts overfitting around epoch 30
22    let val_loss: Vec<f64> = epochs
23        .iter()
24        .map(|&e| {
25            let base = 2.0 * (-e / 20.0).exp() + 0.1;
26            let overfit = if e > 30.0 { (e - 30.0) * 0.005 } else { 0.0 };
27            base + overfit + rng.normal() * 0.03
28        })
29        .collect();
30
31    // Training accuracy: rises from ~50% to ~98%
32    let train_acc: Vec<f64> = epochs
33        .iter()
34        .map(|&e| (0.98 - 0.48 * (-e / 12.0).exp()).min(1.0) + rng.normal() * 0.01)
35        .collect();
36
37    // Validation accuracy: rises but plateaus earlier
38    let val_acc: Vec<f64> = epochs
39        .iter()
40        .map(|&e| {
41            let base = 0.93 - 0.43 * (-e / 18.0).exp();
42            let overfit = if e > 30.0 { -(e - 30.0) * 0.002 } else { 0.0 };
43            (base + overfit + rng.normal() * 0.015).min(1.0)
44        })
45        .collect();
46
47    // ── Plot 1: Loss curves ──────────────────────────────────────────
48    let mut fig = Figure::new()
49        .size(750.0, 500.0)
50        .title("Training & Validation Loss");
51
52    let ax = fig.add_axes();
53    ax.x_label("Epoch").y_label("Loss");
54    ax.line(&epochs, &train_loss)
55        .label("Train Loss")
56        .color(Color::from_hex("#1f77b4").unwrap().into())
57        .width(2.0)
58        .done();
59    ax.line(&epochs, &val_loss)
60        .label("Val Loss")
61        .color(Color::from_hex("#ff7f0e").unwrap().into())
62        .width(2.0)
63        .dash(&[8.0, 4.0])
64        .done();
65
66    fig.save_svg("training_loss.svg")?;
67    println!("Saved training_loss.svg");
68
69    // ── Plot 2: Accuracy curves ──────────────────────────────────────
70    let mut fig2 = Figure::new()
71        .size(750.0, 500.0)
72        .title("Training & Validation Accuracy");
73
74    let ax2 = fig2.add_axes();
75    ax2.x_label("Epoch").y_label("Accuracy").y_range(0.4, 1.05);
76    ax2.line(&epochs, &train_acc)
77        .label("Train Accuracy")
78        .color(Color::from_hex("#2ca02c").unwrap().into())
79        .width(2.0)
80        .done();
81    ax2.line(&epochs, &val_acc)
82        .label("Val Accuracy")
83        .color(Color::from_hex("#d62728").unwrap().into())
84        .width(2.0)
85        .dash(&[8.0, 4.0])
86        .done();
87
88    fig2.save_svg("training_accuracy.svg")?;
89    println!("Saved training_accuracy.svg");
90
91    Ok(())
92}
Source

pub fn scatter(&mut self, x: &[f64], y: &[f64]) -> ScatterBuilder<'_>

Add a scatter series and return a builder for customization.

Source

pub fn bar(&mut self, x: &[f64], heights: &[f64]) -> BarBuilder<'_>

Add a bar series and return a builder for customization.

Source

pub fn histogram(&mut self, data: &[f64]) -> HistogramBuilder<'_>

Add a histogram series and return a builder for customization.

Source

pub fn boxplot(&mut self, datasets: Vec<Vec<f64>>) -> BoxPlotBuilder<'_>

Add a box plot series and return a builder for customization.

Source

pub fn heatmap(&mut self, data: Vec<Vec<f64>>) -> HeatmapBuilder<'_>

Add a heatmap series and return a builder for customization.

Source

pub fn errorbar( &mut self, x: &[f64], y: &[f64], err: &[f64], ) -> ErrorBarBuilder<'_>

Add an error bar series and return a builder for customization.

Source

pub fn add_series(&mut self, series: Box<dyn SeriesRenderer>) -> &mut Self

Add an arbitrary series.

Trait Implementations§

Source§

impl Default for Axes

Source§

fn default() -> Axes

Returns the “default value” for a type. Read more

Auto Trait Implementations§

§

impl Freeze for Axes

§

impl !RefUnwindSafe for Axes

§

impl !Send for Axes

§

impl !Sync for Axes

§

impl Unpin for Axes

§

impl UnsafeUnpin for Axes

§

impl !UnwindSafe for Axes

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.