Bar Charts
The following imports have been used to produce the plots below:
#![allow(unused)] fn main() { use itertools_num::linspace; use plotly::common::{ ColorScale, ColorScalePalette, DashType, Fill, Font, Line, LineShape, Marker, Mode, Title, }; use plotly::layout::{Axis, BarMode, Layout, Legend, TicksDirection}; use plotly::{Bar, color::{NamedColor, Rgb, Rgba}, Plot, Scatter}; use rand_distr::{Distribution, Normal, Uniform}; }
The to_inline_html
method is used to produce the html plot displayed in this page.
Basic Bar Chart
#![allow(unused)] fn main() { fn basic_bar_chart(show: bool) { let animals = vec!["giraffes", "orangutans", "monkeys"]; let t = Bar::new(animals, vec![20, 14, 23]); let mut plot = Plot::new(); plot.add_trace(t); if show { plot.show(); } println!("{}", plot.to_inline_html(Some("basic_bar_chart"))); } }
Grouped Bar Chart
#![allow(unused)] fn main() { fn grouped_bar_chart(show: bool) { let animals1 = vec!["giraffes", "orangutans", "monkeys"]; let trace1 = Bar::new(animals1, vec![20, 14, 23]).name("SF Zoo"); let animals2 = vec!["giraffes", "orangutans", "monkeys"]; let trace2 = Bar::new(animals2, vec![12, 18, 29]).name("LA Zoo"); let layout = Layout::new().bar_mode(BarMode::Group); let mut plot = Plot::new(); plot.add_trace(trace1); plot.add_trace(trace2); plot.set_layout(layout); if show { plot.show(); } println!("{}", plot.to_inline_html(Some("grouped_bar_chart"))); } }
Stacked Bar Chart
#![allow(unused)] fn main() { fn stacked_bar_chart(show: bool) { let animals1 = vec!["giraffes", "orangutans", "monkeys"]; let trace1 = Bar::new(animals1, vec![20, 14, 23]).name("SF Zoo"); let animals2 = vec!["giraffes", "orangutans", "monkeys"]; let trace2 = Bar::new(animals2, vec![12, 18, 29]).name("LA Zoo"); let layout = Layout::new().bar_mode(BarMode::Stack); let mut plot = Plot::new(); plot.add_trace(trace1); plot.add_trace(trace2); plot.set_layout(layout); if show { plot.show(); } println!("{}", plot.to_inline_html(Some("stacked_bar_chart"))); } }