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: AxisConfigX-axis configuration.
y_config: AxisConfigY-axis configuration.
legend_position: LegendPositionLegend position.
show_legend: boolWhether to show the legend.
Implementations§
Source§impl Axes
impl Axes
Sourcepub fn x_label(&mut self, label: impl Into<String>) -> &mut Self
pub fn x_label(&mut self, label: impl Into<String>) -> &mut Self
Set the X-axis label.
Examples found in repository?
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}Sourcepub fn y_label(&mut self, label: impl Into<String>) -> &mut Self
pub fn y_label(&mut self, label: impl Into<String>) -> &mut Self
Set the Y-axis label.
Examples found in repository?
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}Sourcepub fn y_range(&mut self, min: f64, max: f64) -> &mut Self
pub fn y_range(&mut self, min: f64, max: f64) -> &mut Self
Set the Y-axis range manually.
Examples found in repository?
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}Sourcepub fn x_axis(&mut self, config: AxisConfig) -> &mut Self
pub fn x_axis(&mut self, config: AxisConfig) -> &mut Self
Set X-axis config.
Sourcepub fn y_axis(&mut self, config: AxisConfig) -> &mut Self
pub fn y_axis(&mut self, config: AxisConfig) -> &mut Self
Set Y-axis config.
Sourcepub fn legend(&mut self, position: LegendPosition) -> &mut Self
pub fn legend(&mut self, position: LegendPosition) -> &mut Self
Set legend position.
Sourcepub fn line(&mut self, x: &[f64], y: &[f64]) -> LineBuilder<'_>
pub fn line(&mut self, x: &[f64], y: &[f64]) -> LineBuilder<'_>
Add a line series and return a builder for customization.
Examples found in repository?
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}Sourcepub fn scatter(&mut self, x: &[f64], y: &[f64]) -> ScatterBuilder<'_>
pub fn scatter(&mut self, x: &[f64], y: &[f64]) -> ScatterBuilder<'_>
Add a scatter series and return a builder for customization.
Sourcepub fn bar(&mut self, x: &[f64], heights: &[f64]) -> BarBuilder<'_>
pub fn bar(&mut self, x: &[f64], heights: &[f64]) -> BarBuilder<'_>
Add a bar series and return a builder for customization.
Sourcepub fn histogram(&mut self, data: &[f64]) -> HistogramBuilder<'_>
pub fn histogram(&mut self, data: &[f64]) -> HistogramBuilder<'_>
Add a histogram series and return a builder for customization.
Sourcepub fn boxplot(&mut self, datasets: Vec<Vec<f64>>) -> BoxPlotBuilder<'_>
pub fn boxplot(&mut self, datasets: Vec<Vec<f64>>) -> BoxPlotBuilder<'_>
Add a box plot series and return a builder for customization.
Sourcepub fn heatmap(&mut self, data: Vec<Vec<f64>>) -> HeatmapBuilder<'_>
pub fn heatmap(&mut self, data: Vec<Vec<f64>>) -> HeatmapBuilder<'_>
Add a heatmap series and return a builder for customization.
Sourcepub fn errorbar(
&mut self,
x: &[f64],
y: &[f64],
err: &[f64],
) -> ErrorBarBuilder<'_>
pub fn errorbar( &mut self, x: &[f64], y: &[f64], err: &[f64], ) -> ErrorBarBuilder<'_>
Add an error bar series and return a builder for customization.
Sourcepub fn add_series(&mut self, series: Box<dyn SeriesRenderer>) -> &mut Self
pub fn add_series(&mut self, series: Box<dyn SeriesRenderer>) -> &mut Self
Add an arbitrary series.