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
impl Plot
Sourcepub fn new() -> Plot
pub fn new() -> Plot
Create and return a plot
Examples found in repository?
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
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}
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}
Sourcepub fn set_color(self, color: Rgba) -> Self
pub fn set_color(self, color: Rgba) -> Self
Set plot background color. Note: This is different from the canvas background color.
Sourcepub fn set_color_rgb(self, red: f32, green: f32, blue: f32) -> Self
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.
Sourcepub fn set_color_rgba(self, red: f32, green: f32, blue: f32, alpha: f32) -> Self
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.
Sourcepub fn set_local_frame(
self,
left: f64,
right: f64,
bottom: f64,
top: f64,
) -> Self
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?
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
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}
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}
Sourcepub fn set_data_range(
self,
x_min: f64,
x_max: f64,
y_min: f64,
y_max: f64,
) -> Self
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.
Sourcepub fn set_x_range(self, x_min: f64, x_max: f64) -> Self
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.
Sourcepub fn set_y_range(self, y_min: f64, y_max: f64) -> Self
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.
Sourcepub fn set_x_min(self, x_min: f64) -> Self
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.
Sourcepub fn set_x_max(self, x_max: f64) -> Self
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.
Sourcepub fn set_y_min(self, y_min: f64) -> Self
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?
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
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}
Sourcepub fn set_y_max(self, y_max: f64) -> Self
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.
Sourcepub fn display_border(self, val: bool) -> Self
pub fn display_border(self, val: bool) -> Self
Whether or not to display a border around the plot
Sourcepub fn set_border_color(self, color: Rgba) -> Self
pub fn set_border_color(self, color: Rgba) -> Self
Set the color of the border around the plot
Sourcepub fn set_border_thickness(self, val: f64) -> Self
pub fn set_border_thickness(self, val: f64) -> Self
Set the line width of the border around the plot
Sourcepub fn add(self, chart: Chart) -> Self
pub fn add(self, chart: Chart) -> Self
Add a canvas to the plot
Examples found in repository?
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
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}
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}
Trait Implementations§
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> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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