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