Draws polyline (2D or 3D, auto-detected from point dimensions) # Input `points` -- (n × 2) or (n × 3) matrix of coordinates `closed` -- if `true`, connects the last point back to the first If points are `2D` (`ndim == 2`), uses 2D path patches (supporting `face_color` and `edge_color` fills). If `3D` (`ndim == 3`), draws as a 3D line plot.
(&mut self, points: &'a T, closed: bool)
| 529 | /// `face_color` and `edge_color` fills). If `3D` (`ndim == 3`), draws as |
| 530 | /// a 3D line plot. |
| 531 | pub fn draw_polyline<'a, T, U>(&mut self, points: &'a T, closed: bool) |
| 532 | where |
| 533 | T: AsMatrix<'a, U>, |
| 534 | U: 'a + std::fmt::Display + Num, |
| 535 | { |
| 536 | let (npoint, ndim) = points.size(); |
| 537 | if npoint < 2 { |
| 538 | return; |
| 539 | } |
| 540 | if ndim == 2 { |
| 541 | write!( |
| 542 | &mut self.buffer, |
| 543 | "dat=[[pth.Path.MOVETO,({},{})]", |
| 544 | points.at(0, 0), |
| 545 | points.at(0, 1) |
| 546 | ) |
| 547 | .unwrap(); |
| 548 | for i in 1..npoint { |
| 549 | write!( |
| 550 | &mut self.buffer, |
| 551 | ",[pth.Path.LINETO,({},{})]", |
| 552 | points.at(i, 0), |
| 553 | points.at(i, 1) |
| 554 | ) |
| 555 | .unwrap(); |
| 556 | } |
| 557 | if closed { |
| 558 | write!(&mut self.buffer, ",[pth.Path.CLOSEPOLY,(None,None)]").unwrap(); |
| 559 | } |
| 560 | let opt = self.options_shared(); |
| 561 | write!( |
| 562 | &mut self.buffer, |
| 563 | "]\n\ |
| 564 | cmd,pts=zip(*dat)\n\ |
| 565 | h=pth.Path(pts,cmd)\n\ |
| 566 | p=pat.PathPatch(h{})\n\ |
| 567 | plt.gca().add_patch(p)\n", |
| 568 | &opt |
| 569 | ) |
| 570 | .unwrap(); |
| 571 | } |
| 572 | if ndim == 3 { |
| 573 | self.polyline_3d_begin(); |
| 574 | for i in 0..npoint { |
| 575 | self.polyline_3d_add(points.at(i, 0), points.at(i, 1), points.at(i, 2)); |
| 576 | } |
| 577 | if closed && npoint > 2 { |
| 578 | self.polyline_3d_add(points.at(0, 0), points.at(0, 1), points.at(0, 2)); |
| 579 | } |
| 580 | self.polyline_3d_end(); |
| 581 | } |
| 582 | } |
| 583 | |
| 584 | /// Draws a rectangle (2D only) |
| 585 | /// |