blob: f2704658bf815f3accc8c453541672cc0b9d7d2e [file] [log] [blame]
use plotters::prelude::*;
fn pdf(x: f64, y: f64) -> f64 {
const SDX: f64 = 0.1;
const SDY: f64 = 0.1;
const A: f64 = 5.0;
let x = x as f64 / 10.0;
let y = y as f64 / 10.0;
A * (-x * x / 2.0 / SDX / SDX - y * y / 2.0 / SDY / SDY).exp()
}
fn main() -> Result<(), Box<dyn std::error::Error>> {
let root =
BitMapBackend::gif("plotters-doc-data/3d-plot2.gif", (600, 400), 100)?.into_drawing_area();
for pitch in 0..157 {
root.fill(&WHITE)?;
let mut chart = ChartBuilder::on(&root)
.caption("2D Guassian PDF", ("sans-serif", 20))
.build_cartesian_3d(-3.0..3.0, 0.0..6.0, -3.0..3.0)?;
chart.with_projection(|mut p| {
p.pitch = 1.57 - (1.57 - pitch as f64 / 50.0).abs();
p.scale = 0.7;
p.into_matrix() // build the projection matrix
});
chart.configure_axes().draw()?;
chart.draw_series(
SurfaceSeries::xoz(
(-15..=15).map(|x| x as f64 / 5.0),
(-15..=15).map(|x| x as f64 / 5.0),
pdf,
)
.style_func(&|&v| {
(&HSLColor(240.0 / 360.0 - 240.0 / 360.0 * v / 5.0, 1.0, 0.7)).into()
}),
)?;
root.present()?;
}
Ok(())
}
#[test]
fn entry_point() {
main().unwrap()
}