| 245 | |
| 246 | #[test] |
| 247 | fn test_plot_log() -> Result<(), StrError> { |
| 248 | // curves |
| 249 | let mut curve1 = Curve::new(); |
| 250 | let mut curve2 = Curve::new(); |
| 251 | let mut curve3 = Curve::new(); |
| 252 | let mut curve4 = Curve::new(); |
| 253 | |
| 254 | // draw curve |
| 255 | let x = linspace(1.0, 11.0, 11); |
| 256 | let y: Vec<_> = x.iter().map(|v| f64::exp(*v)).collect(); |
| 257 | curve1.draw(&x, &x); |
| 258 | curve2.draw(&x, &y); |
| 259 | curve3.draw(&y, &x); |
| 260 | curve4.draw(&y, &y); |
| 261 | |
| 262 | // configure plot |
| 263 | let mut plot = Plot::new(); |
| 264 | |
| 265 | // add curve to subplots |
| 266 | plot.set_subplot(2, 2, 1); |
| 267 | plot.set_log_x(false); |
| 268 | plot.set_log_y(false); |
| 269 | plot.add(&curve1); |
| 270 | |
| 271 | plot.set_subplot(2, 2, 2); |
| 272 | plot.set_log_x(false); |
| 273 | plot.set_log_y(true); |
| 274 | plot.add(&curve2); |
| 275 | |
| 276 | plot.set_subplot(2, 2, 3); |
| 277 | plot.set_log_x(true); |
| 278 | plot.set_log_y(false); |
| 279 | plot.add(&curve3); |
| 280 | |
| 281 | plot.set_subplot(2, 2, 4); |
| 282 | plot.set_log_x(true); |
| 283 | plot.set_log_y(true); |
| 284 | plot.add(&curve4); |
| 285 | |
| 286 | // save figure |
| 287 | let path = Path::new(OUT_DIR).join("integ_plot_log.svg"); |
| 288 | plot.save(&path)?; |
| 289 | |
| 290 | // check number of lines |
| 291 | let file = File::open(path).map_err(|_| "cannot open file")?; |
| 292 | let buffered = BufReader::new(file); |
| 293 | let lines_iter = buffered.lines(); |
| 294 | assert!(lines_iter.count() > 980); |
| 295 | Ok(()) |
| 296 | } |
| 297 | |
| 298 | #[test] |
| 299 | fn test_plot_multiple_of_pi() -> Result<(), StrError> { |