@@ -231,6 +231,22 @@ impl Axes {
231231 Bar :: new ( self , x, height)
232232 }
233233
234+ /// Create a stem plot.
235+ ///
236+ /// A stem plot draws lines perpendicular to a baseline at each
237+ /// location locs from the baseline to heads, and places a marker
238+ /// there. For vertical stem plots (the default), the locs are
239+ /// `x` positions, and the heads are `y` values. For horizontal
240+ /// stem plots, the locs are `y` positions, and the heads are `x`
241+ /// values.
242+ pub fn stem < ' a , D1 , D2 > ( & ' a mut self , x : D1 , y : D2 ) -> Stem < ' a >
243+ where
244+ D1 : AsRef < [ f64 ] > + ' a ,
245+ D2 : AsRef < [ f64 ] > + ' a ,
246+ {
247+ Stem :: new ( self , x, y)
248+ }
249+
234250 /// Set the title to `txt` for the Axes.
235251 pub fn set_title ( & mut self , txt : impl AsRef < str > ) -> & mut Self {
236252 meth ! ( self . ax, set_title, ( txt. as_ref( ) , ) ) . unwrap ( ) ;
@@ -966,6 +982,63 @@ impl<'a> Bar<'a> {
966982 }
967983}
968984
985+ pub struct Stem < ' a > {
986+ axes : & ' a Axes ,
987+ x : Box < dyn AsRef < [ f64 ] > + ' a > ,
988+ y : Box < dyn AsRef < [ f64 ] > + ' a > ,
989+ linefmt : & ' a str , // FIXME: enum
990+ markerfmt : & ' a str ,
991+ basefmt : & ' a str ,
992+ }
993+
994+ impl < ' a > Stem < ' a > {
995+ fn new < D1 , D2 > ( axes : & ' a Axes , x : D1 , y : D2 ) -> Self
996+ where
997+ D1 : AsRef < [ f64 ] > + ' a ,
998+ D2 : AsRef < [ f64 ] > + ' a ,
999+ {
1000+ Self {
1001+ axes,
1002+ x : Box :: new ( x) ,
1003+ y : Box :: new ( y) ,
1004+ linefmt : "C0-" ,
1005+ markerfmt : "o" ,
1006+ basefmt : "C3-" ,
1007+ }
1008+ }
1009+
1010+ pub fn linefmt ( mut self , fmt : & ' a str ) -> Self {
1011+ self . linefmt = fmt;
1012+ self
1013+ }
1014+
1015+ pub fn markerfmt ( mut self , fmt : & ' a str ) -> Self {
1016+ self . markerfmt = fmt;
1017+ self
1018+ }
1019+
1020+ pub fn basefmt ( mut self , fmt : & ' a str ) -> Self {
1021+ self . basefmt = fmt;
1022+ self
1023+ }
1024+
1025+ pub fn plot ( self ) {
1026+ Python :: attach ( |py| {
1027+ let x = self . x . as_ref ( ) . as_ref ( ) . to_pyarray ( py) ;
1028+ let y = self . y . as_ref ( ) . as_ref ( ) . to_pyarray ( py) ;
1029+ let kwargs = PyDict :: new ( py) ;
1030+ kwargs. set_item ( "linefmt" , self . linefmt ) . unwrap ( ) ;
1031+ kwargs. set_item ( "markerfmt" , self . markerfmt ) . unwrap ( ) ;
1032+ kwargs. set_item ( "basefmt" , self . basefmt ) . unwrap ( ) ;
1033+ self . axes . ax . bind ( py)
1034+ . call_method ( intern ! ( py, "stem" ) ,
1035+ ( x, y) ,
1036+ Some ( & kwargs) )
1037+ . unwrap ( ) ;
1038+ } )
1039+ }
1040+ }
1041+
9691042pub struct QuadContourSet {
9701043 contours : Py < PyAny > ,
9711044}
0 commit comments