Rust plotters doesn't draw

Viewed 43

I'm trying to run one of the examples from rust's plotters user guide. For some reason, whenI run the example, no image is written out to images/. I looked through the whole project structure, no images are written to examples/ or otherwise.

Here's the output from cargo run:

plotters % cargo run 
Finished dev [unoptimized + debuginfo] target(s) in 0.06s
Running `target/debug/plotters`

Here's the code:

use plotters::prelude::*;

fn main() {
    let root_drawing_area = BitMapBackend::new("images/0.1.png", (1024, 768))
        .into_drawing_area();

    root_drawing_area.fill(&WHITE).unwrap();

    let mut chart = ChartBuilder::on(&root_drawing_area)
        .build_cartesian_2d(-3.14..3.14, -1.2..1.2)
        .unwrap();

    chart.draw_series(LineSeries::new(
        (-314..314).map(|x| x as f64 / 100.0).map(|x| (x, x.sin())),
        &RED
    )).unwrap();

    root_drawing_area.present().unwrap();
}

Am I missing something?

Edit:

I added the explicit call to root_drawing_area.present().unwrap();, now I get a helpful error message:

% cargo run
   Compiling plotters v0.1.0 (/Users/sledge/Sandbox/plotters)
    Finished dev [unoptimized + debuginfo] target(s) in 0.82s
     Running `target/debug/plotters`
thread 'main' panicked at 'called `Result::unwrap()` on an `Err` value: BackendError(DrawingError(ImageError(IoError(Os { code: 2, kind: NotFound, message: "No such file or directory" }))))', src/main.rs:18:33
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
0 Answers
Related