MCPcopy Create free account
hub / github.com/cpmech/plotpy / draw_with_str

Method draw_with_str

src/barplot.rs:183–208  ·  view source on GitHub ↗

Draws the bar plot with string labels on the x-axis (categorical data) # Input `x` -- string labels for each bar (e.g., `["Apple", "Banana", "Orange"]`) `y` -- bar heights (or lengths when horizontal) See also: [`draw`](Self::draw) for numeric x-axis

(&mut self, x: &[&str], y: &'a T)

Source from the content-addressed store, hash-verified

181 ///
182 /// See also: [`draw`](Self::draw) for numeric x-axis
183 pub fn draw_with_str<'a, T, U>(&mut self, x: &[&str], y: &'a T)
184 where
185 T: AsVector<'a, U>,
186 U: 'a + std::fmt::Display + Num,
187 {
188 generate_list_quoted(&mut self.buffer, "x", x);
189 vector_to_array(&mut self.buffer, "y", y);
190 let opt = self.options();
191 if self.colors.len() > 0 {
192 generate_list_quoted(&mut self.buffer, "colors", self.colors.as_slice());
193 }
194 if self.bottom.len() > 0 {
195 vector_to_array(&mut self.buffer, "bottom", &self.bottom);
196 }
197 if self.errors.len() > 0 {
198 vector_to_array(&mut self.buffer, "err", &self.errors);
199 }
200 if self.horizontal {
201 write!(&mut self.buffer, "p=plt.barh(x,y{})\n", &opt).unwrap();
202 } else {
203 write!(&mut self.buffer, "p=plt.bar(x,y{})\n", &opt).unwrap();
204 }
205 if let Some(t) = &self.with_text {
206 write!(&mut self.buffer, "plt.gca().bar_label(p,label_type='{}')\n", t).unwrap();
207 }
208 }
209
210 /// Sets the name of this bar series in the legend
211 ///

Callers 5

draw_with_str_works_1Function · 0.80
draw_with_str_works_2Function · 0.80
test_barplot_2Function · 0.80
test_barplot_4Function · 0.80
test_barplot_5Function · 0.80

Calls 3

generate_list_quotedFunction · 0.85
vector_to_arrayFunction · 0.85
optionsMethod · 0.45

Tested by 5

draw_with_str_works_1Function · 0.64
draw_with_str_works_2Function · 0.64
test_barplot_2Function · 0.64
test_barplot_4Function · 0.64
test_barplot_5Function · 0.64