:dep tagu :dep poloto use tagu::prelude::*; use poloto::prelude::*; use poloto::build; :dep poloto-evcxr use poloto_evcxr::prelude::*; { // Hello world example let data = vec![[0, 0], [1, 2], [2, 3]]; let a = build::plot("label").line(data); poloto::frame_build() .data(a) .build_and_label(("hello world", "x", "y")) .append_to(poloto::header().light_theme()) .render_evcxr_img(); } { // Custom Ticks Example // hourly trend over one day. let trend = vec![ 0, 0, 0, 0, 0, 3, 5, 5, 10, 20, 50, 60, 70, 50, 40, 34, 34, 20, 10, 20, 10, 4, 2, 0, ]; let plots = poloto::plots!( build::plot("").histogram((0..).zip(trend)), build::markers([24], []) ); let data = poloto::frame_build().data(plots); let ticks = poloto::ticks::from_iter((0..).step_by(6)).with_tick_fmt(|&v| format_move!("{} hr", v)); data.map_xticks(|_| ticks) .build_and_label(("title", "x", "y")) .append_to(poloto::header().light_theme()) .render_evcxr_img(); } { // Custom Tick Format Example // hourly trend over one day. let trend = vec![ 0, 0, 0, 0, 0, 3, 5, 5, 10, 20, 50, 60, 70, 50, 40, 34, 34, 20, 10, 20, 10, 4, 2, 0, ]; let plots = poloto::plots!( build::plot("").histogram((0..).zip(trend)), build::markers([24], []) ); let data = poloto::frame_build().data(plots); let data = data.map_xticks(|orig| { poloto::ticks::from_closure(|a, b, c| { let orig = poloto::ticks::gen_ticks(orig, a, b, c); poloto::ticks::from_iter(orig.iter).with_tick_fmt(|&v| format_move!("{} hr", v)) }) }); data.build_and_label(("title", "x", "y")) .append_to(poloto::header().light_theme()) .render_evcxr_img(); } { // Gaussian Example // See https://en.wikipedia.org/wiki/Gaussian_function let gau = |sigma: f64, mu: f64| { use std::f64::consts::TAU; let s = sigma.powi(2); let k = (sigma * TAU).sqrt().recip(); move |x: f64| [x, (-0.5 * (x - mu).powi(2) / s).exp() * k] }; let xs = poloto::util::range_iter([-5.0, 5.0], 200); let plots = poloto::plots!( build::plot("σ=1.0").line(xs.clone().map(gau(1.0, 0.0))), build::plot("σ=0.5").line(xs.clone().map(gau(0.5, 0.0))), build::plot("σ=0.3").line(xs.clone().map(gau(0.3, 0.0))) ); poloto::frame_build() .data(poloto::plots!(build::origin(), plots)) .build_and_label(("gaussian", "x", "y")) .append_to(poloto::header().light_theme()) .render_evcxr_img(); } { // Collatz Example let collatz = |mut a: i128| { std::iter::from_fn(move || { if a == 1 { None } else { a = if a % 2 == 0 { a / 2 } else { 3 * a + 1 }; Some(a) } }) .fuse() }; let svg = poloto::header().with_viewbox_width(1200.0); let style = poloto::render::Theme::dark().append(tagu::build::raw(".poloto_line{stroke-dasharray:2;stroke-width:2;}")); let a = (1000..1006).map(|i| build::plot(format!("c({})", i)).line((0..).zip(collatz(i)))); poloto::frame() .with_tick_lines([true, true]) .with_viewbox(svg.get_viewbox()) .build() .data(poloto::plots!(poloto::build::origin(), a)) .build_and_label(("collatz", "x", "y")) .append_to(svg.append(style)) .render_evcxr_img(); } { // Styling Example use tagu::prelude::*; use poloto::{build, prelude::OutputZip}; let theme = poloto::render::Theme::light(); // Style the first plot and its legend image if it is a histogram. let theme = theme.append(tagu::build::raw(".poloto0.poloto_histo.poloto_imgs{fill:red;stroke:black;stroke-width:2px}")); // Some attributes have to accessed directly , so use >* to select the rects directly. let theme = theme.append(tagu::build::raw(".poloto0.poloto_histo.poloto_imgs>*{rx:20px;ry:20px}")); // Style the text of the first legend let theme = theme.append(tagu::build::raw(".poloto0.poloto_legend.poloto_text{fill:blue;}")); // Style all line plots but not legend img. let theme = theme.append(tagu::build::raw(".poloto_line.poloto_imgs.poloto_plot{stroke:purple;stroke-width:20px;stroke-dasharray:40px}")); // Style all line plot legend imgs. let theme = theme.append(tagu::build::raw(".poloto_line.poloto_imgs.poloto_legend{stroke:purple;stroke-width:10px;stroke-dasharray:10px}")); // Style the scatter plots but not legend img let theme = theme.append(tagu::build::raw(".poloto_scatter.poloto_plot{fill:purple;stroke-width:20px;}")); // Style the scatter plots but not legend img let theme = theme.append(tagu::build::raw(".poloto_scatter.poloto_plot{fill:purple;stroke-width:20px;}")); // Style the xaxis name let theme = theme.append( tagu::build::raw( ".poloto_name.poloto_x{fill:orange;stroke-width:20px;font-size:30px;font-style: italic;}",) ); // Style the background let theme = theme.append(tagu::build::raw(".poloto_background{fill:darkslategray;}")); // Style the text let theme = theme.append(tagu::build::raw(".poloto_text{fill: peru;}")); // Style the ticks let theme = theme.append(tagu::build::raw(".poloto_imgs.poloto_ticks{stroke:springgreen;}")); let x = (0..50).map(|x| (x as f64 / 50.0) * 10.0); let data = poloto::plots!( build::plot("sin-10").histogram(x.clone().step_by(3).zip_output(|x| x.sin() - 10.)), build::plot("cos").line(x.clone().zip_output(|x| x.cos())), build::plot("sin-5").scatter(x.clone().step_by(3).zip_output(|x| x.sin() - 5.)) ); poloto::frame_build() .data(data) .build_and_label(( "Demo: you can change the style of the svg file itself!", "x axis", "y axis", )) .append_to(poloto::header().append(theme)) .render_evcxr_img(); } { // Bar Example let data = [ (20, "potato"), (14, "broccoli"), (53, "pizza"), (30, "avocado"), ]; poloto::build::bar::gen_simple("", data, [0]) .label(("Comparison of Food Tastiness", "Tastiness", "Foods")) .append_to(poloto::header().light_theme()) .render_evcxr_img(); } { // Heart Example // https://mathworld.wolfram.com/HeartCurve.html let heart = |t: f64| { [ 16.0 * t.sin().powi(3), 13.0 * t.cos() - 5.0 * (2.0 * t).cos() - 2.0 * (3.0 * t).cos() - (4.0 * t).cos(), ] }; let range = (0..100).map(|x| x as f64 / 100.0).map(|x| x * 6.0 - 3.0); let canvas = poloto::frame().preserve_aspect().build(); let plots = poloto::plots!( build::plot("").line_fill_raw(range.map(heart)), poloto::build::markers([-20.0, 20.0], [-20.0, 20.0]) ); canvas .data(plots) .build_and_label(("Heart Graph", "x", "y")) .append_to(poloto::header().dark_theme()) .render_evcxr_img() } :dep chrono :dep poloto-chrono { use poloto::build; use poloto_chrono::UnixTime; let timezone = &chrono::Utc; use chrono::TimeZone; //Source https://en.wikipedia.org/wiki/Men%27s_long_jump_world_record_progression let data = [ (7.61, "05 August 1901"), (7.69, "23 July 1921"), (7.76, "07 July 1924"), (7.89, "13 June 1925"), (7.90, "07 July 1928"), (7.93, "09 September 1928"), (7.98, "27 October 1931"), (8.13, "25 May 1935"), (8.21, "12 August 1960"), (8.24, "27 May 1961"), (8.28, "16 July 1961"), (8.31, "10 June 1962"), (8.33, "25 May 1963"), (8.34, "12 September 1964"), (8.35, "29 May 1965"), (8.35, "19 October 1967"), (8.90, "18 October 1968"), (8.95, "30 August 1991"), ]; let data = data.map(|(x, y)| { let d = timezone.from_utc_datetime( &chrono::NaiveDate::parse_from_str(y, "%d %B %Y") .unwrap() .and_hms_opt(0, 0, 0) .unwrap(), ); (UnixTime::from(d), x) }); let plots = poloto::plots!(build::plot("").line(data), build::markers([], [0.0])); poloto::frame_build() .data(plots) .build_and_label(( "Long Jump world record progression", "Date", "Mark (in meters)", )) .append_to(poloto::header().light_theme()) .render_evcxr_img() }