Struct pgfplots::Picture

source ·
pub struct Picture {
    pub axes: Vec<Axis>,
    /* private fields */
}
Expand description

Picture environment.

Creating a Picture is equivalent to the TikZ graphics environment:

\begin{tikzpicture}[PictureKeys]
    % axis environments
\end{tikzpicture}

Fields§

§axes: Vec<Axis>

Implementations§

Create a new, empty picture environment.

Examples
use pgfplots::Picture;

let picture = Picture::new();

Add a key to control the appearance of the picture. This will overwrite any previous mutually exclusive key.

Examples
use pgfplots::{Picture, PictureKey};

let mut picture = Picture::new();
picture.add_key(PictureKey::Custom(String::from("baseline")));

Return a String with valid LaTeX code that generates a standalone PDF with the picture environment.

Note

Passing this string directly to e.g. pdflatex will fail to generate a PDF document. It is usually necessary to str::replace all the occurrences of \n and \t with white space before sending this string as an argument to a LaTeX compiler.

Examples
use pgfplots::Picture;

let picture = Picture::new();
assert_eq!(
r#"\documentclass{standalone}
\usepackage{pgfplots}
\begin{document}
\begin{tikzpicture}
\end{tikzpicture}
\end{document}"#,
picture.standalone_string());

Compile the picture environment into a standalone PDF document. This will create the file jobname.pdf in the specified working_dir (additional files will be created in the same directory e.g. .log and .aux files). Return a Result with the path to the generated PDF file or a CompileError.

Examples
use pgfplots::{Engine, Picture};

let picture = Picture::new();
let pdf_path = picture.to_pdf(std::env::temp_dir(), "jobname", Engine::PdfLatex)?;

assert_eq!(pdf_path, std::env::temp_dir().join("jobname.pdf"));

Show the picture environment in a standalone PDF document. This will create a file in the location returned by std::env::temp_dir and open it with the default PDF viewer.

Examples
use pgfplots::{Engine, Picture};

let picture = Picture::new();
picture.show_pdf(Engine::PdfLatex)?;
Examples found in repository?
examples/snowflake.rs (line 31)
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
fn main() {
    let mut vertices = {
        let mut current: Vec<(f64, f64)> = vec![
            (0.0, 1.0),
            ((3.0f64).sqrt() / 2.0, -0.5),
            (-(3.0f64).sqrt() / 2.0, -0.5),
        ];
        for _ in 0..5 {
            current = snowflake_iter(&current[..]);
        }
        current
    };
    vertices.push(vertices[0]);

    // Set snowflake
    let mut plot = Plot2D::new();
    plot.coordinates = vertices.into_iter().map(|v| v.into()).collect();
    plot.add_key(PlotKey::Custom(String::from("fill=gray!20")));

    // Customise axis environment
    let mut axis = Axis::from(plot);
    axis.set_title("Kloch Snowflake");
    axis.add_key(AxisKey::Custom(String::from("hide axis")));

    #[cfg(feature = "tectonic")]
    Picture::from(axis).show_pdf(Engine::Tectonic).unwrap();
    #[cfg(not(feature = "tectonic"))]
    Picture::from(axis).show_pdf(Engine::PdfLatex).unwrap();
}
More examples
Hide additional examples
examples/rectangle_integration.rs (line 42)
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
fn main() {
    // Set line
    let mut line = Plot2D::new();
    line.coordinates = (0..101)
        .into_iter()
        .map(|i| (f64::from(i), f64::from(i * i)).into())
        .collect();

    // Set rectangles
    let mut rectangles = Plot2D::new();
    rectangles.coordinates = (0..101)
        .into_iter()
        .step_by(10)
        .map(|i| (f64::from(i), f64::from(i * i)).into())
        .collect();
    // Currently have to "guess" the bar width in pt units
    // Still pending the \compat key
    rectangles.add_key(PlotKey::Type2D(Type2D::YBar {
        bar_width: 19.5,
        bar_shift: 0.0,
    }));
    rectangles.add_key(PlotKey::Custom(String::from("fill=gray!20")));
    rectangles.add_key(PlotKey::Custom(String::from("draw opacity=0.5")));

    // Customise axis environment
    let mut axis = Axis::new();
    axis.set_title("Rectangle Integration");
    axis.set_x_label("$x$");
    axis.set_y_label("$y = x^2$");
    axis.plots.push(rectangles);
    axis.plots.push(line);
    axis.add_key(AxisKey::Custom(String::from("axis lines=middle")));
    axis.add_key(AxisKey::Custom(String::from("xlabel near ticks")));
    axis.add_key(AxisKey::Custom(String::from("ylabel near ticks")));

    #[cfg(feature = "tectonic")]
    Picture::from(axis).show_pdf(Engine::Tectonic).unwrap();
    #[cfg(not(feature = "tectonic"))]
    Picture::from(axis).show_pdf(Engine::PdfLatex).unwrap();
}
examples/fitted_line.rs (line 51)
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
fn main() {
    // Set the straight dotted line
    let mut line = Plot2D::new();
    line.coordinates = (0..11)
        .into_iter()
        .map(|i| (f64::from(i), 2.0 * PI * f64::from(i)).into())
        .collect();
    line.add_key(PlotKey::Custom(String::from("dashed")));

    // Set the points with error bars
    let mut points = Plot2D::new();
    points
        .coordinates
        .push((1.0, 8.0, Some(0.2), Some(0.9)).into());
    points
        .coordinates
        .push((3.0, 16.0, Some(0.4), Some(1.4)).into());
    points
        .coordinates
        .push((5.0, 33.0, Some(0.2), Some(3.4)).into());
    points
        .coordinates
        .push((7.0, 41.0, Some(0.2), Some(3.4)).into());
    points
        .coordinates
        .push((9.0, 58.0, Some(0.5), Some(1.4)).into());
    points.add_key(PlotKey::Type2D(Type2D::OnlyMarks));
    points.add_key(PlotKey::XError(ErrorCharacter::Absolute));
    points.add_key(PlotKey::XErrorDirection(ErrorDirection::Both));
    points.add_key(PlotKey::YError(ErrorCharacter::Absolute));
    points.add_key(PlotKey::YErrorDirection(ErrorDirection::Both));
    points.add_key(PlotKey::Custom(String::from("mark size=1pt")));

    // Customize axis environment
    let mut axis = Axis::new();
    axis.set_title("Slope is $2\\pi$");
    axis.set_x_label("Radius~[m]");
    axis.set_y_label("Circumference~[m]");
    axis.plots.push(line);
    axis.plots.push(points);
    axis.add_key(AxisKey::Custom(String::from("legend entries={fit,data}")));
    axis.add_key(AxisKey::Custom(String::from("legend pos=north west")));

    #[cfg(feature = "tectonic")]
    Picture::from(axis).show_pdf(Engine::Tectonic).unwrap();
    #[cfg(not(feature = "tectonic"))]
    Picture::from(axis).show_pdf(Engine::PdfLatex).unwrap();
}

Trait Implementations§

Returns a copy of the value. Read more
Performs copy-assignment from source. Read more
Formats the value using the given formatter. Read more
Returns the “default value” for a type. Read more
Formats the value using the given formatter. Read more
Converts to this type from the input type.
Converts to this type from the input type.

Auto Trait Implementations§

Blanket Implementations§

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Instruments this type with the current Span, returning an Instrumented wrapper. Read more

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Should always be Self
The resulting type after obtaining ownership.
Creates owned data from borrowed data, usually by cloning. Read more
Uses borrowed data to replace owned data, usually by cloning. Read more
Converts the given value to a String. Read more
The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.
Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more