Skip to content

Commit

Permalink
Add polygons to draw filled polygons
Browse files Browse the repository at this point in the history
  • Loading branch information
SiegeLordEx authored and SiegeLord committed Jun 24, 2024
1 parent bcb592a commit 9e23cb1
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 0 deletions.
5 changes: 5 additions & 0 deletions gnuplot/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
31 changes: 31 additions & 0 deletions gnuplot/examples/polygons.rs
Original file line number Diff line number Diff line change
@@ -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));
}
19 changes: 19 additions & 0 deletions gnuplot/src/axes2d.rs
Original file line number Diff line number Diff line change
Expand Up @@ -607,6 +607,25 @@ impl Axes2D
self
}

pub fn polygons<
'l,
Tx: DataType,
X: IntoIterator<Item = Tx>,
Ty: DataType,
Y: IntoIterator<Item = Ty>,
>(
&'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
Expand Down

0 comments on commit 9e23cb1

Please sign in to comment.