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

Method draw

src/barplot.rs:148–173  ·  view source on GitHub ↗

Draws the bar plot with numeric x-axis # Input `x` -- bar positions on the x-axis (or values when horizontal) `y` -- bar heights (or lengths when horizontal) See also: [`draw_with_str`](Self::draw_with_str) for string-labeled categories

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

Source from the content-addressed store, hash-verified

146 ///
147 /// See also: [`draw_with_str`](Self::draw_with_str) for string-labeled categories
148 pub fn draw<'a, T, U>(&mut self, x: &'a T, y: &'a T)
149 where
150 T: AsVector<'a, U>,
151 U: 'a + std::fmt::Display + Num,
152 {
153 vector_to_array(&mut self.buffer, "x", x);
154 vector_to_array(&mut self.buffer, "y", y);
155 let opt = self.options();
156 if self.colors.len() > 0 {
157 generate_list_quoted(&mut self.buffer, "colors", self.colors.as_slice());
158 }
159 if self.bottom.len() > 0 {
160 vector_to_array(&mut self.buffer, "bottom", &self.bottom);
161 }
162 if self.errors.len() > 0 {
163 vector_to_array(&mut self.buffer, "err", &self.errors);
164 }
165 if self.horizontal {
166 write!(&mut self.buffer, "p=plt.barh(x,y{})\n", &opt).unwrap();
167 } else {
168 write!(&mut self.buffer, "p=plt.bar(x,y{})\n", &opt).unwrap();
169 }
170 if let Some(t) = &self.with_text {
171 write!(&mut self.buffer, "plt.gca().bar_label(p,label_type='{}')\n", t).unwrap();
172 }
173 }
174
175 /// Draws the bar plot with string labels on the x-axis (categorical data)
176 ///

Callers 2

draw_works_1Function · 0.45
draw_works_2Function · 0.45

Calls 3

vector_to_arrayFunction · 0.85
generate_list_quotedFunction · 0.85
optionsMethod · 0.45

Tested by 2

draw_works_1Function · 0.36
draw_works_2Function · 0.36