hist

hist(bins, y, /, axis=0)[source]

Get the histogram along axis axis.

Parameters
  • bins (array-like) – The bin location.

  • y (array-like) – The data.

  • axis (int, optional) – Axis along which count is taken.

  • dim (str, optional) – For `xarray.DataArray` input only. Named dimension along which count is taken.

Examples

>>> import numpy as np
>>> import xarray as xr
>>> import climopy as climo
>>> from climopy import ureg
>>> state = np.random.RandomState(51423)
>>> data = xr.DataArray(
...     state.rand(20, 1000) * ureg.m,
...     name='distance',
...     dims=('x', 'y'),
...     coords={'x': np.arange(20), 'y': np.arange(1000) * 0.1}
... )
>>> bins = np.linspace(0, 1, 11) * ureg.m
>>> hist = climo.hist(bins, data, axis=1)
>>> bins
<Quantity([0.  0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1. ], 'meter')>
>>> hist
<xarray.DataArray 'count' (x: 20, distance: 10)>
<Quantity([[100. 102. 101. 112.  99.  98.  93.  97.  84. 114.]
 [ 96.  94. 117.  81.  93. 111.  99.  92. 116. 101.]
 [116.  92. 101.  93. 100. 100. 101. 106.  95.  96.]
 [101. 113. 100.  96. 103. 112.  99.  85.  96.  95.]
 [102.  97.  85. 111.  94. 116. 101.  98.  94. 102.]
 [ 95. 112.  93. 105. 104.  87. 101. 103.  95. 105.]
 [103.  86.  98.  89. 110. 100. 101.  81. 132. 100.]
 [ 90.  98.  99. 130.  97. 106.  86.  97. 101.  96.]
 [ 95. 110.  96.  92.  88.  87. 118. 101. 112. 101.]
 [ 97.  85.  77. 102.  97. 119.  90. 106. 108. 119.]
 [ 87.  96.  95. 105.  91. 118. 109.  97.  99. 103.]
 [113.  99. 102.  97.  91.  97.  89. 110. 104.  98.]
 [100. 107. 110.  97.  85. 114. 104.  95.  97.  91.]
 [110. 102.  87.  98.  84.  99. 119.  92. 109. 100.]
 [ 95.  96. 101. 118. 103.  93.  89. 102.  90. 113.]
 [ 94.  87. 119. 102. 106. 100. 110. 108.  83.  91.]
 [ 98.  85.  96. 101. 101. 122.  85.  95. 111. 106.]
 [ 93. 111.  87.  95.  93. 103. 107. 111.  92. 108.]
 [ 86.  95.  89. 109.  90.  98. 119.  90. 116. 108.]
 [103. 100. 106.  87. 102.  88. 103. 121.  93.  97.]], 'count')>
Coordinates:
  * x         (x) int64 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
  * distance  (distance) float64 0.05 0.15 0.25 0.35 ... 0.65 0.75 0.85 0.95