diff --git a/gnuplot/Cargo.toml b/gnuplot/Cargo.toml index e9b5193b..ac2a7c7e 100644 --- a/gnuplot/Cargo.toml +++ b/gnuplot/Cargo.toml @@ -120,6 +120,11 @@ path = "examples/multiple_axes.rs" name = "text" path = "examples/text.rs" +[[example]] + +name = "polygons" +path = "examples/polygons.rs" + [dependencies] byteorder = "1.4.3" tempfile = "3.9" diff --git a/gnuplot/examples/polygons.rs b/gnuplot/examples/polygons.rs new file mode 100644 index 00000000..8980a078 --- /dev/null +++ b/gnuplot/examples/polygons.rs @@ -0,0 +1,31 @@ +// This file is released into Public Domain. +use crate::common::*; +use gnuplot::*; + +mod common; + +fn example(c: Common) +{ + let coords = [[0., 0.], [2., 0.], [3., 3.], [4., 4.], [-1., 3.], [0., 0.]]; + + let mut fg = Figure::new(); + + let ax = fg.axes2d(); + ax.polygons( + coords.iter().map(|x| x[0]), + coords.iter().map(|x| x[1]), + &[], + ); + ax.lines( + coords.iter().map(|x| x[0]), + coords.iter().map(|x| x[1]), + &[], + ); + + c.show(&mut fg, "polygons"); +} + +fn main() +{ + Common::new().map(|c| example(c)); +} diff --git a/gnuplot/src/axes2d.rs b/gnuplot/src/axes2d.rs index 9de698d7..baa48eb4 100644 --- a/gnuplot/src/axes2d.rs +++ b/gnuplot/src/axes2d.rs @@ -607,6 +607,25 @@ impl Axes2D self } + pub fn polygons< + 'l, + Tx: DataType, + X: IntoIterator, + Ty: DataType, + Y: IntoIterator, + >( + &'l mut self, x: X, y: Y, options: &[PlotOption<&str>], + ) -> &'l mut Self + { + self.common.elems.push(PlotElement::new_plot2( + FillBetween, + x, + y, + options.to_one_way_owned(), + )); + self + } + /// Plot a 2D scatter-plot using boxes of automatic width. Box widths are set so that there are no gaps between successive boxes (i.e. each box may have a different width). /// Boxes start at the x-axis and go towards the y value of the datapoint. /// # Arguments