Skip to content

Commit ef648b8

Browse files
committed
Allow to set contour levels
1 parent dea6af1 commit ef648b8

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

src/lib.rs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -450,7 +450,9 @@ impl Axes {
450450
/// }
451451
/// }
452452
/// let (fig, [[mut ax]]) = plt::subplots()?;
453-
/// ax.contour(x.as_slice().unwrap(), y.as_slice().unwrap(), &z).plot();
453+
/// ax.contour(x.as_slice().unwrap(), y.as_slice().unwrap(), &z)
454+
/// .levels(&[0.2, 0.5, 0.8])
455+
/// .plot();
454456
/// fig.save().to_file("target/contour.pdf")?;
455457
/// # Ok::<(), matplotlib::Error>(())
456458
/// ```
@@ -876,6 +878,13 @@ impl QuadContourSet {
876878
}
877879
}
878880

881+
macro_rules! set_contour_options { () => {
882+
pub fn levels(mut self, levels: &'a [f64]) -> Self {
883+
self.levels = Some(levels);
884+
self
885+
}
886+
}}
887+
879888
#[must_use]
880889
pub struct Contour<'a, D> {
881890
axes: &'a Axes,
@@ -889,6 +898,7 @@ pub struct Contour<'a, D> {
889898
impl<'a, D> Contour<'a, D>
890899
where D: AsRef<[f64]> {
891900
set_plotoptions!();
901+
set_contour_options!();
892902

893903
pub fn plot(&self) -> QuadContourSet {
894904
Python::with_gil(|py| {
@@ -926,6 +936,7 @@ pub struct ContourFun<'a, F> {
926936
impl<'a, F> ContourFun<'a, F>
927937
where F: FnMut(f64, f64) -> f64 {
928938
set_plotoptions!();
939+
set_contour_options!();
929940

930941
pub fn plot(&mut self) -> QuadContourSet {
931942
let mut x = Vec::with_capacity(self.n1);

0 commit comments

Comments
 (0)