Skip to content

Commit

Permalink
Merge pull request #559 from JaminMartin/evcxr-jupyter-saving
Browse files Browse the repository at this point in the history
added saving of figures as a new function in evxcr.rs issue #552
  • Loading branch information
AaronErhardt authored Apr 3, 2024
2 parents 8f14c1e + 8261bc9 commit d15b0c0
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions plotters/src/evcxr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ use crate::coord::Shift;
use crate::drawing::{DrawingArea, IntoDrawingArea};
use plotters_backend::DrawingBackend;
use plotters_svg::SVGBackend;
use std::fs::File;
use std::io::Write;

#[cfg(feature = "evcxr_bitmap")]
#[cfg_attr(doc_cfg, doc(cfg(feature = "evcxr_bitmap")))]
Expand Down Expand Up @@ -46,6 +48,25 @@ pub fn evcxr_figure<
SVGWrapper(buffer, "".to_string())
}

// An evcxr figure that can save to the local file system and render in a notebook.

pub fn evcxr_figure_with_saving<

Check warning on line 53 in plotters/src/evcxr.rs

View workflow job for this annotation

GitHub Actions / cargo-doc

missing documentation for a function
Draw: FnOnce(DrawingArea<SVGBackend, Shift>) -> Result<(), Box<dyn std::error::Error>>,
>(
filename: &str,
size: (u32, u32),
draw: Draw,
) -> SVGWrapper {
let mut buffer = "".to_string();
let root = SVGBackend::with_string(&mut buffer, size).into_drawing_area();
draw(root).expect("Drawing failure");

let mut file = File::create(filename).expect("Unable to create file");
file.write_all(buffer.as_bytes())
.expect("Unable to write data");

SVGWrapper(buffer, "".to_string())
}
/// Start drawing an evcxr figure
#[cfg(feature = "evcxr_bitmap")]
#[cfg_attr(doc_cfg, doc(cfg(feature = "evcxr_bitmap")))]
Expand Down

0 comments on commit d15b0c0

Please sign in to comment.