Skip to main content

generate2d

Function generate2d 

Source
pub fn generate2d(
    xmin: f64,
    xmax: f64,
    ymin: f64,
    ymax: f64,
    nx: usize,
    ny: usize,
) -> (Vec<Vec<f64>>, Vec<Vec<f64>>)
Expand description

Generates 2d meshgrid points

This is analogous to numpy.meshgrid with indexing='ij'. Produces two (ny × nx) matrices where each row has the same y value and each column has the same x value.

§Input

  • xmin, xmax – range along x
  • ymin, ymax – range along y
  • nx – number of points along x (must be >= 2)
  • ny – number of points along y (must be >= 2)

§Output

  • x, y – (ny by nx) 2D arrays such that x[i][j] = xmin + j·dx and y[i][j] = ymin + i·dy

§Example

use plotpy::generate2d;

let (x, y) = generate2d(-1.0, 1.0, -3.0, 3.0, 2, 3);
assert_eq!(x, vec![vec![-1.0, 1.0], vec![-1.0, 1.0], vec![-1.0, 1.0]]);
assert_eq!(y, vec![vec![-3.0, -3.0], vec![0.0, 0.0], vec![3.0, 3.0]]);

See also: generate3d