Skip to content

Commit 2d917a5

Browse files
committed
Add new example
1 parent 8216337 commit 2d917a5

File tree

6 files changed

+80
-1
lines changed

6 files changed

+80
-1
lines changed

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,10 @@ To view the source code for each example, please click on the example image.
122122
<img src="https://plotters-rs.github.io/plotters-doc-data/3d-plot.svg" class="galleryItem" width=200px></img>
123123
</a>
124124

125+
<a href="https://github.com/38/plotters/blob/master/examples/3d-plot2.rs">
126+
<img src="https://plotters-rs.github.io/plotters-doc-data/3d-plot2.gif" class="galleryItem" width=200px></img>
127+
</a>
128+
125129

126130
## Table of Contents
127131
* [Gallery](#gallery)

doc-template/readme/gallery

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,3 +92,7 @@ To view the source code for each example, please click on the example image.
9292
<a href="https://github.com/38/plotters/blob/master/examples/3d-plot.rs">
9393
<img src="https://plotters-rs.github.io/plotters-doc-data/3d-plot.svg" class="galleryItem" width=200px></img>
9494
</a>
95+
96+
<a href="https://github.com/38/plotters/blob/master/examples/3d-plot2.rs">
97+
<img src="https://plotters-rs.github.io/plotters-doc-data/3d-plot2.gif" class="galleryItem" width=200px></img>
98+
</a>

doc-template/rustdoc/gallery

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -217,3 +217,13 @@
217217
<a href="https://github.com/38/plotters/blob/master/examples/3d-plot.rs">[code]</a>
218218
</div>
219219
</div>
220+
221+
<div class="galleryItem">
222+
<a href="https://plotters-rs.github.io/plotters-doc-data/3d-plot2.gif">
223+
<img src="https://plotters-rs.github.io/plotters-doc-data/3d-plot2.gif" class="galleryItem"></img>
224+
</a>
225+
<div class="galleryText">
226+
2-Var Gussian Distribution PDF
227+
<a href="https://github.com/38/plotters/blob/master/examples/3d-plot2.rs">[code]</a>
228+
</div>
229+
</div>

examples/3d-plot2.rs

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
use plotters::prelude::*;
2+
fn pdf(x: f64, y: f64) -> f64 {
3+
const SDX: f64 = 0.1;
4+
const SDY: f64 = 0.1;
5+
const A: f64 = 5.0;
6+
let x = x as f64 / 10.0;
7+
let y = y as f64 / 10.0;
8+
A * (-x * x / 2.0 / SDX / SDX - y * y / 2.0 / SDY / SDY).exp()
9+
}
10+
11+
fn main() -> Result<(), Box<dyn std::error::Error>> {
12+
let root =
13+
BitMapBackend::gif("plotters-doc-data/3d-plot2.gif", (600, 400), 100)?.into_drawing_area();
14+
15+
for pitch in 0..157 {
16+
root.fill(&WHITE)?;
17+
18+
let mut chart = ChartBuilder::on(&root)
19+
.caption("2D Guassian PDF", ("sans-serif", 20))
20+
.build_cartesian_3d(-3.0..3.0, 0.0..6.0, -3.0..3.0)?;
21+
chart.with_projection(|mut p| {
22+
p.pitch = 1.57 - (1.57 - pitch as f64 / 50.0).abs();
23+
p.scale = 0.7;
24+
p.into_matrix() // build the projection matrix
25+
});
26+
27+
chart.configure_axes().draw()?;
28+
29+
let series = (-15..15)
30+
.map(|x| std::iter::repeat(x).zip(-15..15))
31+
.flatten()
32+
.map(|(x, z)| {
33+
let x = x as f64 / 5.0;
34+
let z = z as f64 / 5.0;
35+
Polygon::new(
36+
vec![
37+
(x, pdf(x, z), z),
38+
(x + 0.2, pdf(x + 0.2, z), z),
39+
(x + 0.2, pdf(x + 0.2, z + 0.2), z + 0.2),
40+
(x, pdf(x, z + 0.2), z + 0.2),
41+
],
42+
&HSLColor(240.0 / 360.0 - 240.0 / 360.0 * pdf(x, z) / 5.0, 1.0, 0.7),
43+
)
44+
});
45+
46+
chart.draw_series(series)?;
47+
root.present()?;
48+
}
49+
50+
Ok(())
51+
}

plotters-doc-data

src/lib.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,16 @@ including bitmap, vector graph, piston window, GTK/Cairo and WebAssembly.
249249
</div>
250250
</div>
251251
252+
<div class="galleryItem">
253+
<a href="https://plotters-rs.github.io/plotters-doc-data/3d-plot2.gif">
254+
<img src="https://plotters-rs.github.io/plotters-doc-data/3d-plot2.gif" class="galleryItem"></img>
255+
</a>
256+
<div class="galleryText">
257+
2-Var Gussian Distribution PDF
258+
<a href="https://github.com/38/plotters/blob/master/examples/3d-plot2.rs">[code]</a>
259+
</div>
260+
</div>
261+
252262
253263
## Table of Contents
254264
* [Gallery](#gallery)

0 commit comments

Comments
 (0)