File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ use std:: collections:: btree_map:: BTreeMap ;
2+ use plotlib:: style:: BoxStyle ;
3+
4+ fn main ( ) {
5+ let mut data = Vec :: new ( ) ;
6+ let message: & str = "This is a long message" ;
7+ let mut count = BTreeMap :: new ( ) ;
8+
9+ for c in message. trim ( ) . to_lowercase ( ) . chars ( ) {
10+ if c. is_alphabetic ( ) {
11+ * count. entry ( c) . or_insert ( 0 ) += 1
12+ }
13+ }
14+
15+ println ! ( "Number of occurences per character" ) ;
16+ for ( ch, count) in & count {
17+ println ! ( "{:?}: {}" , ch, count) ;
18+ let count = * count as f64 ;
19+ data. push ( plotlib:: repr:: BarChart :: new ( count) . label ( ch. to_string ( ) ) ) ;
20+ }
21+ // Add data to the view
22+ let v = data
23+ . into_iter ( )
24+ . fold ( plotlib:: view:: CategoricalView :: new ( ) , |view, datum| {
25+ view. add ( datum)
26+ } ) ;
27+
28+ plotlib:: page:: Page :: single ( & v)
29+ . save ( "barchart.svg" )
30+ . expect ( "saving svg" ) ;
31+ }
You can’t perform that action at this time.
0 commit comments