You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hello I'm having troubles using your library, I'm hoping maybe you could help me and we could add the code to your examples.
I'm trying to reimplement this python
importmatplotlib.pyplotaspltalphabet="abcdefghijklmnopqrstuvwxyz"# Get Message from usermessage="This is a long message"letter_counts= [message.count(l) forlinalphabet]
letter_colors=plt.cm.hsv([0.8*i/max(letter_counts) foriinletter_counts])
plt.bar(range(26), letter_counts, color=letter_colors)
plt.xticks(range(26), alphabet) # letter labels on x-axisplt.tick_params(axis="x", bottom=False) # no ticks, only labels on x-axisplt.title("Frequency of each letter")
plt.savefig("output.png")
into rust
so far what I'm working with is
use std::collections::btree_map::BTreeMap;use plotlib::style::BarChart;fnmain(){let message:&str = "This is a long message";letmut 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 asf64;
plotlib::barchart::BarChart::new(count).label(ch.to_string());}let v = plotlib::view::CategoricalView::new();
plotlib::page::Page::single(&v).save("barchart.svg").expect("saving svg");}
I'm not sure how to use data in the btree with plotlib,
I'm using version 0.4.0 by the way
The text was updated successfully, but these errors were encountered:
Th3Whit3Wolf
changed the title
Letter Frequency Counter Issue
[SOLVED]Letter Frequency Counter Issue
Jun 8, 2019
use std::collections::btree_map::BTreeMap;use plotlib::style::BarChart;fnmain(){letmut data = Vec::new();let message:&str = "This is a long message";letmut 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 asf64;
data.push(plotlib::barchart::BarChart::new(count).label(ch.to_string()));}// Add data to the viewlet v = data
.iter().fold(plotlib::view::CategoricalView::new(), |view, datum| {
view.add(datum)});
plotlib::page::Page::single(&v).save("barchart.svg").expect("saving svg");}
Hello I'm having troubles using your library, I'm hoping maybe you could help me and we could add the code to your examples.
I'm trying to reimplement this python
into rust
so far what I'm working with is
I'm not sure how to use data in the btree with plotlib,
I'm using version 0.4.0 by the way
The text was updated successfully, but these errors were encountered: