histogram2d

Function histogram2d 

Source
pub fn histogram2d<T>(
    x: ArrayView<'_, T, Ix1>,
    y: ArrayView<'_, T, Ix1>,
    bins: Option<(usize, usize)>,
    range: Option<((T, T), (T, T))>,
    weights: Option<ArrayView<'_, T, Ix1>>,
) -> Histogram2dResult<T>
where T: Clone + Float + FromPrimitive,
Expand description

Calculate a 2D histogram of data

§Arguments

  • x - The x coordinates of the data points
  • y - The y coordinates of the data points
  • bins - Either a tuple (x_bins, y_bins) for the number of bins, or None for 10 bins in each direction
  • range - Optional tuple ((x_min, x_max), (y_min, y_max)) to use. If None, the range is based on data
  • weights - Optional array of weights for each data point

§Returns

A tuple containing (histogram, x_edges, y_edges)

§Examples

use ndarray::array;
use scirs2_core::ndarray_ext::stats::histogram2d;

let x = array![0.1, 0.5, 1.3, 2.5, 3.1, 3.8, 4.2, 4.9];
let y = array![0.2, 0.8, 1.5, 2.0, 3.0, 3.2, 3.5, 4.5];
let (hist, x_edges, y_edges) = histogram2d(x.view(), y.view(), Some((4, 4)), None, None).unwrap();

assert_eq!(hist.shape(), &[4, 4]);
assert_eq!(x_edges.len(), 5);
assert_eq!(y_edges.len(), 5);