pub struct Trace { /* private fields */ }Expand description
Trace.
A trace represents a single data series to place on a figure.
§Constructing a trace
See the following constructors:
Trace::new_2d- for 2D traces.Trace::new_3d- for 3D traces.
Implementations§
Source§impl Trace
impl Trace
Sourcepub fn new_2d(x: impl Into<Vec<f64>>, y: impl Into<Vec<f64>>) -> Trace
pub fn new_2d(x: impl Into<Vec<f64>>, y: impl Into<Vec<f64>>) -> Trace
Constructor for a 2D trace.
§Arguments
x- x-axis data.y- y-axis data.
§Returns
Trace.
§Example
use plotting::{Color, LineStyle, NamedColor, Trace};
let trace = Trace::new_2d([1.0, 2.0, 3.0], [4.0, 5.0, 6.0])
.name("My Trace")
.line_color(Color::named(NamedColor::Red))
.line_width(2.0)
.line_style(LineStyle::Dot);Examples found in repository?
examples/general_2d_plot.rs (line 6)
4fn main() {
5 // Define the traces.
6 let trace_1 = Trace::new_2d([1.0, 2.0, 3.0], [1.0, 2.0, 3.0])
7 .name("y = x")
8 .line_color(Color::named(NamedColor::Red))
9 .line_width(2.0)
10 .line_style(LineStyle::Dash);
11 let trace_2 = Trace::new_2d([1.0, 2.0, 3.0], [1.0, 4.0, 9.0])
12 .name("y = x^2")
13 .line_color(Color::named(NamedColor::Blue))
14 .line_width(2.0)
15 .line_style(LineStyle::Dot);
16
17 // Figure formatting.
18 let format: Format = FormatBuilder::default()
19 .title("y vs. x")
20 .x_label("x")
21 .y_label("y")
22 .width(800)
23 .height(600)
24 .build()
25 .unwrap();
26
27 // Create the figure.
28 let fig = Figure::new(vec![trace_1, trace_2], format);
29
30 // Save the figure so it can be displayed right below this example.
31 fig.save_inline_html(Path::new("book/src/figures/general_2d_plot.html"));
32
33 // Alternatively, you can show the figure in a web browser.
34 // fig.show();
35}Sourcepub fn new_3d(
x: impl Into<Vec<f64>>,
y: impl Into<Vec<f64>>,
z: impl Into<Vec<f64>>,
) -> Trace
pub fn new_3d( x: impl Into<Vec<f64>>, y: impl Into<Vec<f64>>, z: impl Into<Vec<f64>>, ) -> Trace
Constructor for a 3D trace.
§Arguments
x- x-axis data.y- y-axis data.z- z-axis data.
§Returns
Trace.
§Example
use plotting::{Color, LineStyle, NamedColor, Trace};
let trace = Trace::new_3d([1.0, 2.0, 3.0], [4.0, 5.0, 6.0], [7.0, 8.0, 9.0])
.name("My Trace")
.line_color(Color::named(NamedColor::Red))
.line_width(2.0)
.line_style(LineStyle::Dot);Examples found in repository?
examples/general_3d_plot.rs (line 6)
4fn main() {
5 // Define the traces.
6 let trace_1 = Trace::new_3d([1.0, 2.0, 5.0], [1.0, 2.0, 3.0], [1.0, 2.0, 4.0])
7 .name("Trace 1")
8 .line_color(Color::named(NamedColor::Red))
9 .line_width(2.0)
10 .line_style(LineStyle::Dash);
11 let trace_2 = Trace::new_3d([1.0, 2.0, 5.0], [3.0, 2.0, 1.0], [1.0, 2.0, 4.0])
12 .name("Trace 2")
13 .line_color(Color::named(NamedColor::Blue))
14 .line_width(2.0)
15 .line_style(LineStyle::Dot);
16
17 // Figure formatting.
18 let format: Format = FormatBuilder::default()
19 .title("z vs. x and y")
20 .x_label("x")
21 .y_label("y")
22 .z_label("z")
23 .width(800)
24 .height(600)
25 .build()
26 .unwrap();
27
28 // Create the figure.
29 let fig = Figure::new(vec![trace_1, trace_2], format);
30
31 // Save the figure so it can be displayed right below this example.
32 fig.save_inline_html(Path::new("book/src/figures/general_3d_plot.html"));
33
34 // Alternatively, you can show the figure in a web browser.
35 // fig.show();
36}Sourcepub fn name(self, name: impl Into<String>) -> Self
pub fn name(self, name: impl Into<String>) -> Self
Set the name of this trace.
§Arguments
name- Name of the trace (i.e. appears in the legend).
§Returns
The trace with the updated name.
Examples found in repository?
examples/general_2d_plot.rs (line 7)
4fn main() {
5 // Define the traces.
6 let trace_1 = Trace::new_2d([1.0, 2.0, 3.0], [1.0, 2.0, 3.0])
7 .name("y = x")
8 .line_color(Color::named(NamedColor::Red))
9 .line_width(2.0)
10 .line_style(LineStyle::Dash);
11 let trace_2 = Trace::new_2d([1.0, 2.0, 3.0], [1.0, 4.0, 9.0])
12 .name("y = x^2")
13 .line_color(Color::named(NamedColor::Blue))
14 .line_width(2.0)
15 .line_style(LineStyle::Dot);
16
17 // Figure formatting.
18 let format: Format = FormatBuilder::default()
19 .title("y vs. x")
20 .x_label("x")
21 .y_label("y")
22 .width(800)
23 .height(600)
24 .build()
25 .unwrap();
26
27 // Create the figure.
28 let fig = Figure::new(vec![trace_1, trace_2], format);
29
30 // Save the figure so it can be displayed right below this example.
31 fig.save_inline_html(Path::new("book/src/figures/general_2d_plot.html"));
32
33 // Alternatively, you can show the figure in a web browser.
34 // fig.show();
35}More examples
examples/general_3d_plot.rs (line 7)
4fn main() {
5 // Define the traces.
6 let trace_1 = Trace::new_3d([1.0, 2.0, 5.0], [1.0, 2.0, 3.0], [1.0, 2.0, 4.0])
7 .name("Trace 1")
8 .line_color(Color::named(NamedColor::Red))
9 .line_width(2.0)
10 .line_style(LineStyle::Dash);
11 let trace_2 = Trace::new_3d([1.0, 2.0, 5.0], [3.0, 2.0, 1.0], [1.0, 2.0, 4.0])
12 .name("Trace 2")
13 .line_color(Color::named(NamedColor::Blue))
14 .line_width(2.0)
15 .line_style(LineStyle::Dot);
16
17 // Figure formatting.
18 let format: Format = FormatBuilder::default()
19 .title("z vs. x and y")
20 .x_label("x")
21 .y_label("y")
22 .z_label("z")
23 .width(800)
24 .height(600)
25 .build()
26 .unwrap();
27
28 // Create the figure.
29 let fig = Figure::new(vec![trace_1, trace_2], format);
30
31 // Save the figure so it can be displayed right below this example.
32 fig.save_inline_html(Path::new("book/src/figures/general_3d_plot.html"));
33
34 // Alternatively, you can show the figure in a web browser.
35 // fig.show();
36}Sourcepub fn line_color(self, line_color: Color) -> Self
pub fn line_color(self, line_color: Color) -> Self
Set the line color for this trace.
§Arguments
line_color- Line color.
§Returns
The trace with the updated line color.
Examples found in repository?
examples/general_2d_plot.rs (line 8)
4fn main() {
5 // Define the traces.
6 let trace_1 = Trace::new_2d([1.0, 2.0, 3.0], [1.0, 2.0, 3.0])
7 .name("y = x")
8 .line_color(Color::named(NamedColor::Red))
9 .line_width(2.0)
10 .line_style(LineStyle::Dash);
11 let trace_2 = Trace::new_2d([1.0, 2.0, 3.0], [1.0, 4.0, 9.0])
12 .name("y = x^2")
13 .line_color(Color::named(NamedColor::Blue))
14 .line_width(2.0)
15 .line_style(LineStyle::Dot);
16
17 // Figure formatting.
18 let format: Format = FormatBuilder::default()
19 .title("y vs. x")
20 .x_label("x")
21 .y_label("y")
22 .width(800)
23 .height(600)
24 .build()
25 .unwrap();
26
27 // Create the figure.
28 let fig = Figure::new(vec![trace_1, trace_2], format);
29
30 // Save the figure so it can be displayed right below this example.
31 fig.save_inline_html(Path::new("book/src/figures/general_2d_plot.html"));
32
33 // Alternatively, you can show the figure in a web browser.
34 // fig.show();
35}More examples
examples/general_3d_plot.rs (line 8)
4fn main() {
5 // Define the traces.
6 let trace_1 = Trace::new_3d([1.0, 2.0, 5.0], [1.0, 2.0, 3.0], [1.0, 2.0, 4.0])
7 .name("Trace 1")
8 .line_color(Color::named(NamedColor::Red))
9 .line_width(2.0)
10 .line_style(LineStyle::Dash);
11 let trace_2 = Trace::new_3d([1.0, 2.0, 5.0], [3.0, 2.0, 1.0], [1.0, 2.0, 4.0])
12 .name("Trace 2")
13 .line_color(Color::named(NamedColor::Blue))
14 .line_width(2.0)
15 .line_style(LineStyle::Dot);
16
17 // Figure formatting.
18 let format: Format = FormatBuilder::default()
19 .title("z vs. x and y")
20 .x_label("x")
21 .y_label("y")
22 .z_label("z")
23 .width(800)
24 .height(600)
25 .build()
26 .unwrap();
27
28 // Create the figure.
29 let fig = Figure::new(vec![trace_1, trace_2], format);
30
31 // Save the figure so it can be displayed right below this example.
32 fig.save_inline_html(Path::new("book/src/figures/general_3d_plot.html"));
33
34 // Alternatively, you can show the figure in a web browser.
35 // fig.show();
36}Sourcepub fn line_width(self, line_width: f64) -> Self
pub fn line_width(self, line_width: f64) -> Self
Set the line width for this trace.
§Arguments
line_width- Line width.
§Returns
The trace with the updated line width.
Examples found in repository?
examples/general_2d_plot.rs (line 9)
4fn main() {
5 // Define the traces.
6 let trace_1 = Trace::new_2d([1.0, 2.0, 3.0], [1.0, 2.0, 3.0])
7 .name("y = x")
8 .line_color(Color::named(NamedColor::Red))
9 .line_width(2.0)
10 .line_style(LineStyle::Dash);
11 let trace_2 = Trace::new_2d([1.0, 2.0, 3.0], [1.0, 4.0, 9.0])
12 .name("y = x^2")
13 .line_color(Color::named(NamedColor::Blue))
14 .line_width(2.0)
15 .line_style(LineStyle::Dot);
16
17 // Figure formatting.
18 let format: Format = FormatBuilder::default()
19 .title("y vs. x")
20 .x_label("x")
21 .y_label("y")
22 .width(800)
23 .height(600)
24 .build()
25 .unwrap();
26
27 // Create the figure.
28 let fig = Figure::new(vec![trace_1, trace_2], format);
29
30 // Save the figure so it can be displayed right below this example.
31 fig.save_inline_html(Path::new("book/src/figures/general_2d_plot.html"));
32
33 // Alternatively, you can show the figure in a web browser.
34 // fig.show();
35}More examples
examples/general_3d_plot.rs (line 9)
4fn main() {
5 // Define the traces.
6 let trace_1 = Trace::new_3d([1.0, 2.0, 5.0], [1.0, 2.0, 3.0], [1.0, 2.0, 4.0])
7 .name("Trace 1")
8 .line_color(Color::named(NamedColor::Red))
9 .line_width(2.0)
10 .line_style(LineStyle::Dash);
11 let trace_2 = Trace::new_3d([1.0, 2.0, 5.0], [3.0, 2.0, 1.0], [1.0, 2.0, 4.0])
12 .name("Trace 2")
13 .line_color(Color::named(NamedColor::Blue))
14 .line_width(2.0)
15 .line_style(LineStyle::Dot);
16
17 // Figure formatting.
18 let format: Format = FormatBuilder::default()
19 .title("z vs. x and y")
20 .x_label("x")
21 .y_label("y")
22 .z_label("z")
23 .width(800)
24 .height(600)
25 .build()
26 .unwrap();
27
28 // Create the figure.
29 let fig = Figure::new(vec![trace_1, trace_2], format);
30
31 // Save the figure so it can be displayed right below this example.
32 fig.save_inline_html(Path::new("book/src/figures/general_3d_plot.html"));
33
34 // Alternatively, you can show the figure in a web browser.
35 // fig.show();
36}Sourcepub fn line_style(self, line_style: LineStyle) -> Self
pub fn line_style(self, line_style: LineStyle) -> Self
Set the line style for this trace.
§Arguments
line_style- Line style.
§Returns
The trace with the updated line style.
Examples found in repository?
examples/general_2d_plot.rs (line 10)
4fn main() {
5 // Define the traces.
6 let trace_1 = Trace::new_2d([1.0, 2.0, 3.0], [1.0, 2.0, 3.0])
7 .name("y = x")
8 .line_color(Color::named(NamedColor::Red))
9 .line_width(2.0)
10 .line_style(LineStyle::Dash);
11 let trace_2 = Trace::new_2d([1.0, 2.0, 3.0], [1.0, 4.0, 9.0])
12 .name("y = x^2")
13 .line_color(Color::named(NamedColor::Blue))
14 .line_width(2.0)
15 .line_style(LineStyle::Dot);
16
17 // Figure formatting.
18 let format: Format = FormatBuilder::default()
19 .title("y vs. x")
20 .x_label("x")
21 .y_label("y")
22 .width(800)
23 .height(600)
24 .build()
25 .unwrap();
26
27 // Create the figure.
28 let fig = Figure::new(vec![trace_1, trace_2], format);
29
30 // Save the figure so it can be displayed right below this example.
31 fig.save_inline_html(Path::new("book/src/figures/general_2d_plot.html"));
32
33 // Alternatively, you can show the figure in a web browser.
34 // fig.show();
35}More examples
examples/general_3d_plot.rs (line 10)
4fn main() {
5 // Define the traces.
6 let trace_1 = Trace::new_3d([1.0, 2.0, 5.0], [1.0, 2.0, 3.0], [1.0, 2.0, 4.0])
7 .name("Trace 1")
8 .line_color(Color::named(NamedColor::Red))
9 .line_width(2.0)
10 .line_style(LineStyle::Dash);
11 let trace_2 = Trace::new_3d([1.0, 2.0, 5.0], [3.0, 2.0, 1.0], [1.0, 2.0, 4.0])
12 .name("Trace 2")
13 .line_color(Color::named(NamedColor::Blue))
14 .line_width(2.0)
15 .line_style(LineStyle::Dot);
16
17 // Figure formatting.
18 let format: Format = FormatBuilder::default()
19 .title("z vs. x and y")
20 .x_label("x")
21 .y_label("y")
22 .z_label("z")
23 .width(800)
24 .height(600)
25 .build()
26 .unwrap();
27
28 // Create the figure.
29 let fig = Figure::new(vec![trace_1, trace_2], format);
30
31 // Save the figure so it can be displayed right below this example.
32 fig.save_inline_html(Path::new("book/src/figures/general_3d_plot.html"));
33
34 // Alternatively, you can show the figure in a web browser.
35 // fig.show();
36}Auto Trait Implementations§
impl Freeze for Trace
impl RefUnwindSafe for Trace
impl Send for Trace
impl Sync for Trace
impl Unpin for Trace
impl UnsafeUnpin for Trace
impl UnwindSafe for Trace
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
Mutably borrows from an owned value. Read more