Struct Plot

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

§Plot

Determines a single plot. A plot is part of a figure, and contains a canvas where things are drawn. By default, there is some space around the canvas, to make space for labels, ticks, and tick labels.

Implementations§

Source§

impl Plot

Source

pub fn new() -> Plot

Create and return a plot

Examples found in repository?
examples/multiple_figures.rs (line 50)
40fn main() {
41
42    // Figure 1
43
44    // Plot 1
45    let init_val: u64 = 123;
46    let y_data: Vec<f64> = collatz(init_val);
47    let x_data: Vec<f64> = (0u64..y_data.len() as u64).map(|x| x as f64).collect();
48    let line = Line::new(&x_data, &y_data).set_color_rgba(0.9, 0.2, 0.2, 0.9);
49
50    let plot11 = Plot::new().add(Chart::Line(line))
51                            .set_local_frame(0.0, 0.49, 0.0, 0.69);
52
53    // Plot 2
54    let init_val: u64 = 237;
55    let y_data: Vec<f64> = collatz(init_val);
56    let x_data: Vec<f64> = (0u64..y_data.len() as u64).map(|x| x as f64).collect();
57    let line = Line::new(&x_data, &y_data).set_stroke_style("dashed");
58
59    let plot12 = Plot::new().add(Chart::Line(line))
60                            .set_local_frame(0.5, 0.99, 0.3, 0.99);
61
62    let fig1 = Figure::new().add(plot11)
63                            .add(plot12);
64
65    // Figure 2
66
67    let x_data = Array::from_iter((0..100).map(|x| (x as f64) * 2.0 * PI / 100.0));
68    let y_data1 = Array::from_iter((0..100).map(|i| x_data[i].sin()));
69    let y_data2 = Array::from_iter((0..100).map(|i| (x_data[i] - PI / 2.0).sin()));
70
71    let line1 = Line::new(&x_data, &y_data1);
72    let line2 = Line::new(&x_data, &y_data2).set_color_rgba(0.9, 0.2, 0.2, 0.9);
73
74    let plot21 = Plot::new().add(Chart::Line(line1))
75                            .add(Chart::Line(line2))
76                            .set_y_min(-1.2);
77
78    let fig2 = Figure::new().add(plot21)
79                            .save("multiple_figures.png").expect("Could not save multiple_figures.png");
80
81    // Display on screen
82    View::new_from(fig1).expect("Could not add fig1 to view")
83                        .add(fig2).expect("Could not add fig2 to view")
84                        .show();
85}
More examples
Hide additional examples
examples/frontpage_example.rs (line 33)
21fn main() {
22
23    // Create data contained in ndarray
24    let x_data = Array::from_iter((0..100).map(|x| (x as f64) * 2.0 * PI / 100.0));
25    let y_data1 = Array::from_iter((0..100).map(|i| x_data[i].sin()));
26    let y_data2 = Array::from_iter((0..100).map(|i| (x_data[i] - PI / 2.0).sin()));
27
28    // Plot lines
29    let line1 = Line::new(&x_data, &y_data1).set_stroke_style("dotted");
30    let line2 = Line::new(&x_data, &y_data2).set_color_rgba(0.9, 0.2, 0.2, 0.9);
31
32    // Add lines to a plot
33    let line_plot = Plot::new().add(Chart::Line(line1))
34                               .add(Chart::Line(line2))
35                               .set_y_min(-1.2)
36                               .set_local_frame(0.0, 0.7, 0.51, 1.0);
37
38    // Create scatter points
39    let normal_0_1 = Normal::new(0.0, 1.0);
40    let normal_0_2 = Normal::new(0.0, 2.0);
41    let x_data: Vec<f64> = (0..1000)
42                           .map(|_| normal_0_1.ind_sample(&mut thread_rng()))
43                           .collect();
44    let y_data: Vec<f64> = (0..1000)
45                           .map(|_| normal_0_2.ind_sample(&mut thread_rng()))
46                           .collect();
47    let scatter = Scatter::new(&x_data, &y_data).set_color_rgba(0.1, 0.8, 0.3, 0.9)
48                                                .set_point_size(0.005);
49
50    // Add scatter points to a new plot
51    let scatter_plot = Plot::new().set_local_frame(0.3, 1.0, 0.0, 0.49)
52                                  .add(Chart::Scatter(scatter));
53
54    // Add the plots to a figure, and save it
55    let fig = Figure::new().add(line_plot)
56                           .add(scatter_plot)
57                           .set_width(1000)
58                           .set_height(800)
59                           .set_border_thickness(0.001)
60                           .save("assets/frontpage_example.png").expect("Could not save frontpage_example.png")
61                           .save("target/doc/astrup/frontpage_example.png").expect("Could not save doc frontpage_example.png");
62
63    // Display the result on screen
64    View::new_from(fig).expect("Could not add figure to view")
65                       .show();
66}
examples/kaplan_meier_survival.rs (line 104)
95fn main() {
96    let analysis_fname = Path::new("assets/larynx_survival_estimate.csv");
97    match get_survival_data(&analysis_fname) {
98        Ok(data) => {
99            let (surv_stage_1, cens_stage_1) = survival_charts(&data, 1, 224.0, 52.0, 11.0);
100            let (surv_stage_2, cens_stage_2) = survival_charts(&data, 2, 23.0, 108.0, 190.0);
101            let (surv_stage_3, cens_stage_3) = survival_charts(&data, 3, 255.0, 200.0, 14.0);
102            let (surv_stage_4, cens_stage_4) = survival_charts(&data, 4, 34.0, 174.0, 51.0);
103
104            let survival_plot = Plot::new().add(Chart::Line(surv_stage_1.clone()))
105                                           .add(Chart::Scatter(cens_stage_1.clone()))
106                                           .add(Chart::Line(surv_stage_2))
107                                           .add(Chart::Scatter(cens_stage_2))
108                                           .add(Chart::Line(surv_stage_3))
109                                           .add(Chart::Scatter(cens_stage_3))
110                                           .add(Chart::Line(surv_stage_4.clone()))
111                                           .add(Chart::Scatter(cens_stage_4.clone()))
112                                           .set_local_frame(0.0, 1.0, 0.5, 1.0);
113
114            let (lower_stage_1, upper_stage_1) = ci_charts(&data, 1, 224.0, 52.0, 11.0);
115            //let (surv_stage_2, cens_stage_2) = survival_charts(&data, 2, 23.0, 108.0, 190.0);
116            //let (surv_stage_3, cens_stage_3) = survival_charts(&data, 3, 255.0, 200.0, 14.0);
117            let (lower_stage_4, upper_stage_4) = ci_charts(&data, 4, 34.0, 174.0, 51.0);
118
119            let ci_plot = Plot::new().add(Chart::Line(surv_stage_1))
120                                     .add(Chart::Line(lower_stage_1))
121                                     .add(Chart::Line(upper_stage_1))
122                                     .add(Chart::Scatter(cens_stage_1))
123                                     .add(Chart::Line(surv_stage_4))
124                                     .add(Chart::Line(lower_stage_4))
125                                     .add(Chart::Line(upper_stage_4))
126                                     .add(Chart::Scatter(cens_stage_4))
127                                     .set_local_frame(0.0, 1.0, 0.0, 0.5);
128
129            let fig = Figure::new().add(survival_plot)
130                                   .add(ci_plot)
131                                   .set_height(1000)
132                                   .set_width(1000);
133                                   //.save("kaplan_meier_survival.png").expect("Could not save kaplan_meier_survival.png");
134
135            match View::new_from(fig) {
136                Ok(view) => view.show(),
137                Err(msg) => println!("Error in view: \n {}", msg),
138            }
139        }
140        Err(msg) => println!("Error in getting survival data: \n {}", msg),
141    }
142}
Source

pub fn set_title(self, title: &str) -> Self

Set plot title

Source

pub fn set_color(self, color: Rgba) -> Self

Set plot background color. Note: This is different from the canvas background color.

Source

pub fn set_color_rgb(self, red: f32, green: f32, blue: f32) -> Self

Set the plot background color. Note: This is different from the canvas background color.

Source

pub fn set_color_rgba(self, red: f32, green: f32, blue: f32, alpha: f32) -> Self

Set the plot background color. Note: This is different from the canvas background color.

Source

pub fn set_local_frame( self, left: f64, right: f64, bottom: f64, top: f64, ) -> Self

Set local plot coordinates, relative to the figure it belongs to.

A value of 0.0 is the minimum figure coordinate, and a value of 1.0 is the maximum figure coordinate.

Examples found in repository?
examples/multiple_figures.rs (line 51)
40fn main() {
41
42    // Figure 1
43
44    // Plot 1
45    let init_val: u64 = 123;
46    let y_data: Vec<f64> = collatz(init_val);
47    let x_data: Vec<f64> = (0u64..y_data.len() as u64).map(|x| x as f64).collect();
48    let line = Line::new(&x_data, &y_data).set_color_rgba(0.9, 0.2, 0.2, 0.9);
49
50    let plot11 = Plot::new().add(Chart::Line(line))
51                            .set_local_frame(0.0, 0.49, 0.0, 0.69);
52
53    // Plot 2
54    let init_val: u64 = 237;
55    let y_data: Vec<f64> = collatz(init_val);
56    let x_data: Vec<f64> = (0u64..y_data.len() as u64).map(|x| x as f64).collect();
57    let line = Line::new(&x_data, &y_data).set_stroke_style("dashed");
58
59    let plot12 = Plot::new().add(Chart::Line(line))
60                            .set_local_frame(0.5, 0.99, 0.3, 0.99);
61
62    let fig1 = Figure::new().add(plot11)
63                            .add(plot12);
64
65    // Figure 2
66
67    let x_data = Array::from_iter((0..100).map(|x| (x as f64) * 2.0 * PI / 100.0));
68    let y_data1 = Array::from_iter((0..100).map(|i| x_data[i].sin()));
69    let y_data2 = Array::from_iter((0..100).map(|i| (x_data[i] - PI / 2.0).sin()));
70
71    let line1 = Line::new(&x_data, &y_data1);
72    let line2 = Line::new(&x_data, &y_data2).set_color_rgba(0.9, 0.2, 0.2, 0.9);
73
74    let plot21 = Plot::new().add(Chart::Line(line1))
75                            .add(Chart::Line(line2))
76                            .set_y_min(-1.2);
77
78    let fig2 = Figure::new().add(plot21)
79                            .save("multiple_figures.png").expect("Could not save multiple_figures.png");
80
81    // Display on screen
82    View::new_from(fig1).expect("Could not add fig1 to view")
83                        .add(fig2).expect("Could not add fig2 to view")
84                        .show();
85}
More examples
Hide additional examples
examples/frontpage_example.rs (line 36)
21fn main() {
22
23    // Create data contained in ndarray
24    let x_data = Array::from_iter((0..100).map(|x| (x as f64) * 2.0 * PI / 100.0));
25    let y_data1 = Array::from_iter((0..100).map(|i| x_data[i].sin()));
26    let y_data2 = Array::from_iter((0..100).map(|i| (x_data[i] - PI / 2.0).sin()));
27
28    // Plot lines
29    let line1 = Line::new(&x_data, &y_data1).set_stroke_style("dotted");
30    let line2 = Line::new(&x_data, &y_data2).set_color_rgba(0.9, 0.2, 0.2, 0.9);
31
32    // Add lines to a plot
33    let line_plot = Plot::new().add(Chart::Line(line1))
34                               .add(Chart::Line(line2))
35                               .set_y_min(-1.2)
36                               .set_local_frame(0.0, 0.7, 0.51, 1.0);
37
38    // Create scatter points
39    let normal_0_1 = Normal::new(0.0, 1.0);
40    let normal_0_2 = Normal::new(0.0, 2.0);
41    let x_data: Vec<f64> = (0..1000)
42                           .map(|_| normal_0_1.ind_sample(&mut thread_rng()))
43                           .collect();
44    let y_data: Vec<f64> = (0..1000)
45                           .map(|_| normal_0_2.ind_sample(&mut thread_rng()))
46                           .collect();
47    let scatter = Scatter::new(&x_data, &y_data).set_color_rgba(0.1, 0.8, 0.3, 0.9)
48                                                .set_point_size(0.005);
49
50    // Add scatter points to a new plot
51    let scatter_plot = Plot::new().set_local_frame(0.3, 1.0, 0.0, 0.49)
52                                  .add(Chart::Scatter(scatter));
53
54    // Add the plots to a figure, and save it
55    let fig = Figure::new().add(line_plot)
56                           .add(scatter_plot)
57                           .set_width(1000)
58                           .set_height(800)
59                           .set_border_thickness(0.001)
60                           .save("assets/frontpage_example.png").expect("Could not save frontpage_example.png")
61                           .save("target/doc/astrup/frontpage_example.png").expect("Could not save doc frontpage_example.png");
62
63    // Display the result on screen
64    View::new_from(fig).expect("Could not add figure to view")
65                       .show();
66}
examples/kaplan_meier_survival.rs (line 112)
95fn main() {
96    let analysis_fname = Path::new("assets/larynx_survival_estimate.csv");
97    match get_survival_data(&analysis_fname) {
98        Ok(data) => {
99            let (surv_stage_1, cens_stage_1) = survival_charts(&data, 1, 224.0, 52.0, 11.0);
100            let (surv_stage_2, cens_stage_2) = survival_charts(&data, 2, 23.0, 108.0, 190.0);
101            let (surv_stage_3, cens_stage_3) = survival_charts(&data, 3, 255.0, 200.0, 14.0);
102            let (surv_stage_4, cens_stage_4) = survival_charts(&data, 4, 34.0, 174.0, 51.0);
103
104            let survival_plot = Plot::new().add(Chart::Line(surv_stage_1.clone()))
105                                           .add(Chart::Scatter(cens_stage_1.clone()))
106                                           .add(Chart::Line(surv_stage_2))
107                                           .add(Chart::Scatter(cens_stage_2))
108                                           .add(Chart::Line(surv_stage_3))
109                                           .add(Chart::Scatter(cens_stage_3))
110                                           .add(Chart::Line(surv_stage_4.clone()))
111                                           .add(Chart::Scatter(cens_stage_4.clone()))
112                                           .set_local_frame(0.0, 1.0, 0.5, 1.0);
113
114            let (lower_stage_1, upper_stage_1) = ci_charts(&data, 1, 224.0, 52.0, 11.0);
115            //let (surv_stage_2, cens_stage_2) = survival_charts(&data, 2, 23.0, 108.0, 190.0);
116            //let (surv_stage_3, cens_stage_3) = survival_charts(&data, 3, 255.0, 200.0, 14.0);
117            let (lower_stage_4, upper_stage_4) = ci_charts(&data, 4, 34.0, 174.0, 51.0);
118
119            let ci_plot = Plot::new().add(Chart::Line(surv_stage_1))
120                                     .add(Chart::Line(lower_stage_1))
121                                     .add(Chart::Line(upper_stage_1))
122                                     .add(Chart::Scatter(cens_stage_1))
123                                     .add(Chart::Line(surv_stage_4))
124                                     .add(Chart::Line(lower_stage_4))
125                                     .add(Chart::Line(upper_stage_4))
126                                     .add(Chart::Scatter(cens_stage_4))
127                                     .set_local_frame(0.0, 1.0, 0.0, 0.5);
128
129            let fig = Figure::new().add(survival_plot)
130                                   .add(ci_plot)
131                                   .set_height(1000)
132                                   .set_width(1000);
133                                   //.save("kaplan_meier_survival.png").expect("Could not save kaplan_meier_survival.png");
134
135            match View::new_from(fig) {
136                Ok(view) => view.show(),
137                Err(msg) => println!("Error in view: \n {}", msg),
138            }
139        }
140        Err(msg) => println!("Error in getting survival data: \n {}", msg),
141    }
142}
Source

pub fn set_data_range( self, x_min: f64, x_max: f64, y_min: f64, y_max: f64, ) -> Self

Set the data range of the plot

Note: This is a soft suggestion, and can be overwritten before the final result for aestethics. See more here.

Source

pub fn set_x_range(self, x_min: f64, x_max: f64) -> Self

Set the horisontal data range of the plot

Note: This is a soft suggestion, and can be overwritten before the final result for aestethics. See more here.

Source

pub fn set_y_range(self, y_min: f64, y_max: f64) -> Self

Set the vertical data range of the plot

Note: This is a soft suggestion, and can be overwritten before the final result for aestethics. See more here.

Source

pub fn set_x_min(self, x_min: f64) -> Self

Set the left horisontal data range end of the plot

Note: This is a soft suggestion, and can be overwritten before the final result for aestethics. See more here.

Source

pub fn set_x_max(self, x_max: f64) -> Self

Set the right horisontal data range end of the plot

Note: This is a soft suggestion, and can be overwritten before the final result for aestethics. See more here.

Source

pub fn set_y_min(self, y_min: f64) -> Self

Set the bottom vertical data range end of the plot

Note: This is a soft suggestion, and can be overwritten before the final result for aestethics. See more here.

Examples found in repository?
examples/multiple_figures.rs (line 76)
40fn main() {
41
42    // Figure 1
43
44    // Plot 1
45    let init_val: u64 = 123;
46    let y_data: Vec<f64> = collatz(init_val);
47    let x_data: Vec<f64> = (0u64..y_data.len() as u64).map(|x| x as f64).collect();
48    let line = Line::new(&x_data, &y_data).set_color_rgba(0.9, 0.2, 0.2, 0.9);
49
50    let plot11 = Plot::new().add(Chart::Line(line))
51                            .set_local_frame(0.0, 0.49, 0.0, 0.69);
52
53    // Plot 2
54    let init_val: u64 = 237;
55    let y_data: Vec<f64> = collatz(init_val);
56    let x_data: Vec<f64> = (0u64..y_data.len() as u64).map(|x| x as f64).collect();
57    let line = Line::new(&x_data, &y_data).set_stroke_style("dashed");
58
59    let plot12 = Plot::new().add(Chart::Line(line))
60                            .set_local_frame(0.5, 0.99, 0.3, 0.99);
61
62    let fig1 = Figure::new().add(plot11)
63                            .add(plot12);
64
65    // Figure 2
66
67    let x_data = Array::from_iter((0..100).map(|x| (x as f64) * 2.0 * PI / 100.0));
68    let y_data1 = Array::from_iter((0..100).map(|i| x_data[i].sin()));
69    let y_data2 = Array::from_iter((0..100).map(|i| (x_data[i] - PI / 2.0).sin()));
70
71    let line1 = Line::new(&x_data, &y_data1);
72    let line2 = Line::new(&x_data, &y_data2).set_color_rgba(0.9, 0.2, 0.2, 0.9);
73
74    let plot21 = Plot::new().add(Chart::Line(line1))
75                            .add(Chart::Line(line2))
76                            .set_y_min(-1.2);
77
78    let fig2 = Figure::new().add(plot21)
79                            .save("multiple_figures.png").expect("Could not save multiple_figures.png");
80
81    // Display on screen
82    View::new_from(fig1).expect("Could not add fig1 to view")
83                        .add(fig2).expect("Could not add fig2 to view")
84                        .show();
85}
More examples
Hide additional examples
examples/frontpage_example.rs (line 35)
21fn main() {
22
23    // Create data contained in ndarray
24    let x_data = Array::from_iter((0..100).map(|x| (x as f64) * 2.0 * PI / 100.0));
25    let y_data1 = Array::from_iter((0..100).map(|i| x_data[i].sin()));
26    let y_data2 = Array::from_iter((0..100).map(|i| (x_data[i] - PI / 2.0).sin()));
27
28    // Plot lines
29    let line1 = Line::new(&x_data, &y_data1).set_stroke_style("dotted");
30    let line2 = Line::new(&x_data, &y_data2).set_color_rgba(0.9, 0.2, 0.2, 0.9);
31
32    // Add lines to a plot
33    let line_plot = Plot::new().add(Chart::Line(line1))
34                               .add(Chart::Line(line2))
35                               .set_y_min(-1.2)
36                               .set_local_frame(0.0, 0.7, 0.51, 1.0);
37
38    // Create scatter points
39    let normal_0_1 = Normal::new(0.0, 1.0);
40    let normal_0_2 = Normal::new(0.0, 2.0);
41    let x_data: Vec<f64> = (0..1000)
42                           .map(|_| normal_0_1.ind_sample(&mut thread_rng()))
43                           .collect();
44    let y_data: Vec<f64> = (0..1000)
45                           .map(|_| normal_0_2.ind_sample(&mut thread_rng()))
46                           .collect();
47    let scatter = Scatter::new(&x_data, &y_data).set_color_rgba(0.1, 0.8, 0.3, 0.9)
48                                                .set_point_size(0.005);
49
50    // Add scatter points to a new plot
51    let scatter_plot = Plot::new().set_local_frame(0.3, 1.0, 0.0, 0.49)
52                                  .add(Chart::Scatter(scatter));
53
54    // Add the plots to a figure, and save it
55    let fig = Figure::new().add(line_plot)
56                           .add(scatter_plot)
57                           .set_width(1000)
58                           .set_height(800)
59                           .set_border_thickness(0.001)
60                           .save("assets/frontpage_example.png").expect("Could not save frontpage_example.png")
61                           .save("target/doc/astrup/frontpage_example.png").expect("Could not save doc frontpage_example.png");
62
63    // Display the result on screen
64    View::new_from(fig).expect("Could not add figure to view")
65                       .show();
66}
Source

pub fn set_y_max(self, y_max: f64) -> Self

Set the top vertical data range end of the plot

Note: This is a soft suggestion, and can be overwritten before the final result for aestethics. See more here.

Source

pub fn display_border(self, val: bool) -> Self

Whether or not to display a border around the plot

Source

pub fn set_border_color(self, color: Rgba) -> Self

Set the color of the border around the plot

Source

pub fn set_border_thickness(self, val: f64) -> Self

Set the line width of the border around the plot

Source

pub fn add(self, chart: Chart) -> Self

Add a canvas to the plot

Examples found in repository?
examples/multiple_figures.rs (line 50)
40fn main() {
41
42    // Figure 1
43
44    // Plot 1
45    let init_val: u64 = 123;
46    let y_data: Vec<f64> = collatz(init_val);
47    let x_data: Vec<f64> = (0u64..y_data.len() as u64).map(|x| x as f64).collect();
48    let line = Line::new(&x_data, &y_data).set_color_rgba(0.9, 0.2, 0.2, 0.9);
49
50    let plot11 = Plot::new().add(Chart::Line(line))
51                            .set_local_frame(0.0, 0.49, 0.0, 0.69);
52
53    // Plot 2
54    let init_val: u64 = 237;
55    let y_data: Vec<f64> = collatz(init_val);
56    let x_data: Vec<f64> = (0u64..y_data.len() as u64).map(|x| x as f64).collect();
57    let line = Line::new(&x_data, &y_data).set_stroke_style("dashed");
58
59    let plot12 = Plot::new().add(Chart::Line(line))
60                            .set_local_frame(0.5, 0.99, 0.3, 0.99);
61
62    let fig1 = Figure::new().add(plot11)
63                            .add(plot12);
64
65    // Figure 2
66
67    let x_data = Array::from_iter((0..100).map(|x| (x as f64) * 2.0 * PI / 100.0));
68    let y_data1 = Array::from_iter((0..100).map(|i| x_data[i].sin()));
69    let y_data2 = Array::from_iter((0..100).map(|i| (x_data[i] - PI / 2.0).sin()));
70
71    let line1 = Line::new(&x_data, &y_data1);
72    let line2 = Line::new(&x_data, &y_data2).set_color_rgba(0.9, 0.2, 0.2, 0.9);
73
74    let plot21 = Plot::new().add(Chart::Line(line1))
75                            .add(Chart::Line(line2))
76                            .set_y_min(-1.2);
77
78    let fig2 = Figure::new().add(plot21)
79                            .save("multiple_figures.png").expect("Could not save multiple_figures.png");
80
81    // Display on screen
82    View::new_from(fig1).expect("Could not add fig1 to view")
83                        .add(fig2).expect("Could not add fig2 to view")
84                        .show();
85}
More examples
Hide additional examples
examples/frontpage_example.rs (line 33)
21fn main() {
22
23    // Create data contained in ndarray
24    let x_data = Array::from_iter((0..100).map(|x| (x as f64) * 2.0 * PI / 100.0));
25    let y_data1 = Array::from_iter((0..100).map(|i| x_data[i].sin()));
26    let y_data2 = Array::from_iter((0..100).map(|i| (x_data[i] - PI / 2.0).sin()));
27
28    // Plot lines
29    let line1 = Line::new(&x_data, &y_data1).set_stroke_style("dotted");
30    let line2 = Line::new(&x_data, &y_data2).set_color_rgba(0.9, 0.2, 0.2, 0.9);
31
32    // Add lines to a plot
33    let line_plot = Plot::new().add(Chart::Line(line1))
34                               .add(Chart::Line(line2))
35                               .set_y_min(-1.2)
36                               .set_local_frame(0.0, 0.7, 0.51, 1.0);
37
38    // Create scatter points
39    let normal_0_1 = Normal::new(0.0, 1.0);
40    let normal_0_2 = Normal::new(0.0, 2.0);
41    let x_data: Vec<f64> = (0..1000)
42                           .map(|_| normal_0_1.ind_sample(&mut thread_rng()))
43                           .collect();
44    let y_data: Vec<f64> = (0..1000)
45                           .map(|_| normal_0_2.ind_sample(&mut thread_rng()))
46                           .collect();
47    let scatter = Scatter::new(&x_data, &y_data).set_color_rgba(0.1, 0.8, 0.3, 0.9)
48                                                .set_point_size(0.005);
49
50    // Add scatter points to a new plot
51    let scatter_plot = Plot::new().set_local_frame(0.3, 1.0, 0.0, 0.49)
52                                  .add(Chart::Scatter(scatter));
53
54    // Add the plots to a figure, and save it
55    let fig = Figure::new().add(line_plot)
56                           .add(scatter_plot)
57                           .set_width(1000)
58                           .set_height(800)
59                           .set_border_thickness(0.001)
60                           .save("assets/frontpage_example.png").expect("Could not save frontpage_example.png")
61                           .save("target/doc/astrup/frontpage_example.png").expect("Could not save doc frontpage_example.png");
62
63    // Display the result on screen
64    View::new_from(fig).expect("Could not add figure to view")
65                       .show();
66}
examples/kaplan_meier_survival.rs (line 104)
95fn main() {
96    let analysis_fname = Path::new("assets/larynx_survival_estimate.csv");
97    match get_survival_data(&analysis_fname) {
98        Ok(data) => {
99            let (surv_stage_1, cens_stage_1) = survival_charts(&data, 1, 224.0, 52.0, 11.0);
100            let (surv_stage_2, cens_stage_2) = survival_charts(&data, 2, 23.0, 108.0, 190.0);
101            let (surv_stage_3, cens_stage_3) = survival_charts(&data, 3, 255.0, 200.0, 14.0);
102            let (surv_stage_4, cens_stage_4) = survival_charts(&data, 4, 34.0, 174.0, 51.0);
103
104            let survival_plot = Plot::new().add(Chart::Line(surv_stage_1.clone()))
105                                           .add(Chart::Scatter(cens_stage_1.clone()))
106                                           .add(Chart::Line(surv_stage_2))
107                                           .add(Chart::Scatter(cens_stage_2))
108                                           .add(Chart::Line(surv_stage_3))
109                                           .add(Chart::Scatter(cens_stage_3))
110                                           .add(Chart::Line(surv_stage_4.clone()))
111                                           .add(Chart::Scatter(cens_stage_4.clone()))
112                                           .set_local_frame(0.0, 1.0, 0.5, 1.0);
113
114            let (lower_stage_1, upper_stage_1) = ci_charts(&data, 1, 224.0, 52.0, 11.0);
115            //let (surv_stage_2, cens_stage_2) = survival_charts(&data, 2, 23.0, 108.0, 190.0);
116            //let (surv_stage_3, cens_stage_3) = survival_charts(&data, 3, 255.0, 200.0, 14.0);
117            let (lower_stage_4, upper_stage_4) = ci_charts(&data, 4, 34.0, 174.0, 51.0);
118
119            let ci_plot = Plot::new().add(Chart::Line(surv_stage_1))
120                                     .add(Chart::Line(lower_stage_1))
121                                     .add(Chart::Line(upper_stage_1))
122                                     .add(Chart::Scatter(cens_stage_1))
123                                     .add(Chart::Line(surv_stage_4))
124                                     .add(Chart::Line(lower_stage_4))
125                                     .add(Chart::Line(upper_stage_4))
126                                     .add(Chart::Scatter(cens_stage_4))
127                                     .set_local_frame(0.0, 1.0, 0.0, 0.5);
128
129            let fig = Figure::new().add(survival_plot)
130                                   .add(ci_plot)
131                                   .set_height(1000)
132                                   .set_width(1000);
133                                   //.save("kaplan_meier_survival.png").expect("Could not save kaplan_meier_survival.png");
134
135            match View::new_from(fig) {
136                Ok(view) => view.show(),
137                Err(msg) => println!("Error in view: \n {}", msg),
138            }
139        }
140        Err(msg) => println!("Error in getting survival data: \n {}", msg),
141    }
142}
Source

pub fn fit(&mut self) -> Result<(), Error>

This method is called by figure after all plots are added, and all plot adjustment is made. This happend right before the plot is drawn on the figure.

The function scales various elements within the plot, and calls a similar plot for its canvasses.

Source

pub fn draw(&self, cr: &Context, fig_rel_height: f64, fig_rel_width: f64)

Do the actual drawing of the plot

Trait Implementations§

Source§

impl Clone for Plot

Source§

fn clone(&self) -> Plot

Returns a copy of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Plot

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.