Skip to content

Commit 1939051

Browse files
committed
update
1 parent bbc2ffa commit 1939051

File tree

6 files changed

+142
-2
lines changed

6 files changed

+142
-2
lines changed

book/basic/draw_3d_plots.html

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,76 @@ <h2><a class="header" href="#draw-a-3d-bar-chart" id="draw-a-3d-bar-chart">Draw
227227
}
228228
</code></pre></pre>
229229
<p><img src="../../images/3d-bar.png" alt="3d-env.png" /></p>
230+
<h2><a class="header" href="#3d-surface" id="3d-surface">3D Surface</a></h2>
231+
<p>We can draw 3d surface as well by drawing a series of polygon. Here's an example of how to draw a surface plot.</p>
232+
<pre><pre class="playground"><code class="language-rust">use plotters::prelude::*;
233+
fn main() {
234+
let root = BitMapBackend::new(&quot;images/3d-surface.png&quot;, (640, 480)).into_drawing_area();
235+
236+
root.fill(&amp;WHITE).unwrap();
237+
238+
let mut chart = ChartBuilder::on(&amp;root)
239+
.margin(20)
240+
.caption(&quot;3D Surface&quot;, (&quot;sans-serif&quot;, 40))
241+
.build_cartesian_3d(-3.0..3.0, -3.0..3.0, -3.0..3.0)
242+
.unwrap();
243+
244+
chart.configure_axes().draw().unwrap();
245+
246+
let mut data = vec![];
247+
248+
for x in (-25..25).map(|v| v as f64 / 10.0) {
249+
let mut row = vec![];
250+
for z in (-25..25).map(|v| v as f64 / 10.0) {
251+
row.push((x, (x * x + z * z).cos(), z));
252+
}
253+
data.push(row);
254+
}
255+
256+
chart.draw_series(
257+
(0..49)
258+
.map(|x| std::iter::repeat(x).zip(0..49))
259+
.flatten()
260+
.map(|(x,z)| {
261+
Polygon::new(vec![
262+
data[x][z],
263+
data[x+1][z],
264+
data[x+1][z+1],
265+
data[x][z+1],
266+
], &amp;BLUE.mix(0.3))
267+
})
268+
).unwrap();
269+
270+
}
271+
</code></pre></pre>
272+
<p><img src="../../images/3d-surface.png" alt="surface" /></p>
273+
<h3><a class="header" href="#drawing-with-surface-series" id="drawing-with-surface-series">Drawing with surface series</a></h3>
274+
<p><strong>Note: This feature is only avaiable in development version</strong></p>
275+
<pre><pre class="playground"><code class="language-rust">use plotters_nightly::prelude::*;
276+
fn main() {
277+
let root = BitMapBackend::new(&quot;images/3d-surface-series.png&quot;, (640, 480)).into_drawing_area();
278+
279+
root.fill(&amp;WHITE).unwrap();
280+
281+
let mut chart = ChartBuilder::on(&amp;root)
282+
.margin(20)
283+
.caption(&quot;3D Surface&quot;, (&quot;sans-serif&quot;, 40))
284+
.build_cartesian_3d(-3.0..3.0, -3.0..3.0, -3.0..3.0)
285+
.unwrap();
286+
287+
chart.configure_axes().draw().unwrap();
288+
289+
chart.draw_series(SurfaceSeries::xoz(
290+
(-25..25).map(|v| v as f64 / 10.0),
291+
(-25..25).map(|v| v as f64 / 10.0),
292+
|x:f64,z:f64|(x * x + z * z).cos()).style(&amp;BLUE.mix(0.2))
293+
).unwrap();
294+
295+
}
296+
</code></pre></pre>
297+
<p><img src="../../images/3d-surface-series.png" alt="surface" /></p>
298+
<h2><a class="header" href="#customize-perspective-matrix" id="customize-perspective-matrix">Customize perspective matrix</a></h2>
299+
<p>Plotters also allows user override the default prespective matrix</p>
230300

231301
</main>
232302

book/print.html

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -822,6 +822,76 @@ <h2><a class="header" href="#draw-a-3d-bar-chart" id="draw-a-3d-bar-chart">Draw
822822
}
823823
</code></pre></pre>
824824
<p><img src="basic/../../images/3d-bar.png" alt="3d-env.png" /></p>
825+
<h2><a class="header" href="#3d-surface" id="3d-surface">3D Surface</a></h2>
826+
<p>We can draw 3d surface as well by drawing a series of polygon. Here's an example of how to draw a surface plot.</p>
827+
<pre><pre class="playground"><code class="language-rust">use plotters::prelude::*;
828+
fn main() {
829+
let root = BitMapBackend::new(&quot;images/3d-surface.png&quot;, (640, 480)).into_drawing_area();
830+
831+
root.fill(&amp;WHITE).unwrap();
832+
833+
let mut chart = ChartBuilder::on(&amp;root)
834+
.margin(20)
835+
.caption(&quot;3D Surface&quot;, (&quot;sans-serif&quot;, 40))
836+
.build_cartesian_3d(-3.0..3.0, -3.0..3.0, -3.0..3.0)
837+
.unwrap();
838+
839+
chart.configure_axes().draw().unwrap();
840+
841+
let mut data = vec![];
842+
843+
for x in (-25..25).map(|v| v as f64 / 10.0) {
844+
let mut row = vec![];
845+
for z in (-25..25).map(|v| v as f64 / 10.0) {
846+
row.push((x, (x * x + z * z).cos(), z));
847+
}
848+
data.push(row);
849+
}
850+
851+
chart.draw_series(
852+
(0..49)
853+
.map(|x| std::iter::repeat(x).zip(0..49))
854+
.flatten()
855+
.map(|(x,z)| {
856+
Polygon::new(vec![
857+
data[x][z],
858+
data[x+1][z],
859+
data[x+1][z+1],
860+
data[x][z+1],
861+
], &amp;BLUE.mix(0.3))
862+
})
863+
).unwrap();
864+
865+
}
866+
</code></pre></pre>
867+
<p><img src="basic/../../images/3d-surface.png" alt="surface" /></p>
868+
<h3><a class="header" href="#drawing-with-surface-series" id="drawing-with-surface-series">Drawing with surface series</a></h3>
869+
<p><strong>Note: This feature is only avaiable in development version</strong></p>
870+
<pre><pre class="playground"><code class="language-rust">use plotters_nightly::prelude::*;
871+
fn main() {
872+
let root = BitMapBackend::new(&quot;images/3d-surface-series.png&quot;, (640, 480)).into_drawing_area();
873+
874+
root.fill(&amp;WHITE).unwrap();
875+
876+
let mut chart = ChartBuilder::on(&amp;root)
877+
.margin(20)
878+
.caption(&quot;3D Surface&quot;, (&quot;sans-serif&quot;, 40))
879+
.build_cartesian_3d(-3.0..3.0, -3.0..3.0, -3.0..3.0)
880+
.unwrap();
881+
882+
chart.configure_axes().draw().unwrap();
883+
884+
chart.draw_series(SurfaceSeries::xoz(
885+
(-25..25).map(|v| v as f64 / 10.0),
886+
(-25..25).map(|v| v as f64 / 10.0),
887+
|x:f64,z:f64|(x * x + z * z).cos()).style(&amp;BLUE.mix(0.2))
888+
).unwrap();
889+
890+
}
891+
</code></pre></pre>
892+
<p><img src="basic/../../images/3d-surface-series.png" alt="surface" /></p>
893+
<h2><a class="header" href="#customize-perspective-matrix" id="customize-perspective-matrix">Customize perspective matrix</a></h2>
894+
<p>Plotters also allows user override the default prespective matrix</p>
825895
<h1><a class="header" href="#animation-and-realtime-rendering" id="animation-and-realtime-rendering">Animation and realtime rendering</a></h1>
826896
<h1><a class="header" href="#tweaking-the-figure" id="tweaking-the-figure">Tweaking the figure</a></h1>
827897
<h1><a class="header" href="#layout-tweaks" id="layout-tweaks">Layout Tweaks</a></h1>

book/searchindex.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

book/searchindex.json

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

images/3d-surface-series.png

96.9 KB
Loading

images/3d-surface.png

95.6 KB
Loading

0 commit comments

Comments
 (0)