Skip to content

Commit

Permalink
Merge pull request #82 from cpmech/impl-disable-fliers-in-boxplot
Browse files Browse the repository at this point in the history
Impl disable fliers in Boxplot
  • Loading branch information
cpmech authored Sep 19, 2024
2 parents 0c9be27 + 668bd1f commit 3b4c7a0
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
19 changes: 16 additions & 3 deletions src/boxplot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ pub struct Boxplot {
whisker: Option<f64>, // The position of the whiskers
positions: Vec<f64>, // The positions of the boxes
width: Option<f64>, // The width of the boxes
no_fliers: bool, // Disables fliers
extra: String, // Extra commands (comma separated)
buffer: String, // Buffer
}
Expand All @@ -104,6 +105,7 @@ impl Boxplot {
whisker: None,
positions: Vec::new(),
width: None,
no_fliers: false,
extra: String::new(),
buffer: String::new(),
}
Expand Down Expand Up @@ -188,6 +190,12 @@ impl Boxplot {
self
}

/// Disables the fliers
pub fn set_no_fliers(&mut self, flag: bool) -> &mut Self {
self.no_fliers = flag;
self
}

/// Sets extra matplotlib commands (comma separated)
///
/// **Important:** The extra commands must be comma separated. For example:
Expand All @@ -205,8 +213,12 @@ impl Boxplot {
/// Returns options (optional parameters) for boxplot
fn options(&self) -> String {
let mut opt = String::new();
if self.symbol != "" {
write!(&mut opt, ",sym=r'{}'", self.symbol).unwrap();
if self.no_fliers {
write!(&mut opt, ",sym=''").unwrap();
} else {
if self.symbol != "" {
write!(&mut opt, ",sym=r'{}'", self.symbol).unwrap();
}
}
if self.horizontal {
write!(&mut opt, ",vert=False").unwrap();
Expand Down Expand Up @@ -305,14 +317,15 @@ mod tests {
let mut boxes = Boxplot::new();
boxes
.set_symbol("b+")
.set_no_fliers(true)
.set_horizontal(true)
.set_whisker(1.5)
.set_positions(&[1.0, 2.0, 3.0, 4.0, 5.0])
.set_width(0.5)
.draw_mat(&x);
let b: &str = "x=np.array([[1,2,3,4,5,],[2,3,4,5,6,],[3,4,5,6,7,],[4,5,6,7,8,],[5,6,7,8,9,],[6,7,8,9,10,],],dtype=float)\n\
positions=[1,2,3,4,5,]\n\
p=plt.boxplot(x,sym=r'b+',vert=False,whis=1.5,positions=positions,widths=0.5)\n";
p=plt.boxplot(x,sym='',vert=False,whis=1.5,positions=positions,widths=0.5)\n";
assert_eq!(boxes.buffer, b);
boxes.clear_buffer();
assert_eq!(boxes.buffer, "");
Expand Down
1 change: 1 addition & 0 deletions tests/test_boxplot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ fn test_boxplot_1() -> Result<(), StrError> {
.set_positions(&positions)
.set_width(0.45)
.set_whisker(2.0)
.set_no_fliers(false)
.set_extra("notch=True")
.draw_mat(&data);

Expand Down

0 comments on commit 3b4c7a0

Please sign in to comment.