@@ -822,6 +822,76 @@ <h2><a class="header" href="#draw-a-3d-bar-chart" id="draw-a-3d-bar-chart">Draw
822
822
}
823
823
</ code > </ pre > </ pre >
824
824
< 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("images/3d-surface.png", (640, 480)).into_drawing_area();
830
+
831
+ root.fill(&WHITE).unwrap();
832
+
833
+ let mut chart = ChartBuilder::on(&root)
834
+ .margin(20)
835
+ .caption("3D Surface", ("sans-serif", 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
+ ], &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("images/3d-surface-series.png", (640, 480)).into_drawing_area();
873
+
874
+ root.fill(&WHITE).unwrap();
875
+
876
+ let mut chart = ChartBuilder::on(&root)
877
+ .margin(20)
878
+ .caption("3D Surface", ("sans-serif", 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(&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 >
825
895
< h1 > < a class ="header " href ="#animation-and-realtime-rendering " id ="animation-and-realtime-rendering "> Animation and realtime rendering</ a > </ h1 >
826
896
< h1 > < a class ="header " href ="#tweaking-the-figure " id ="tweaking-the-figure "> Tweaking the figure</ a > </ h1 >
827
897
< h1 > < a class ="header " href ="#layout-tweaks " id ="layout-tweaks "> Layout Tweaks</ a > </ h1 >
0 commit comments