MCPcopy Index your code
hub / github.com/matplotlib/matplotlib / hist

Method hist

lib/matplotlib/axes/_axes.py:7195–7688  ·  view source on GitHub ↗

Compute and plot a histogram. This method uses `numpy.histogram` to bin the data in *x* and count the number of values in each bin, then draws the distribution either as a `.BarContainer` or `.Polygon`. The *bins*, *range*, *density*, and *weights* parameter

(self, x, bins=None, range=None, density=False, weights=None,
             cumulative=False, bottom=None, histtype='bar', align='mid',
             orientation='vertical', rwidth=None, log=False,
             color=None, label=None, stacked=False, **kwargs)

Source from the content-addressed store, hash-verified

7193 @_api.make_keyword_only("3.10", "range")
7194 @_preprocess_data(replace_names=["x", 'weights'], label_namer="x")
7195 def hist(self, x, bins=None, range=None, density=False, weights=None,
7196 cumulative=False, bottom=None, histtype='bar', align='mid',
7197 orientation='vertical', rwidth=None, log=False,
7198 color=None, label=None, stacked=False, **kwargs):
7199 """
7200 Compute and plot a histogram.
7201
7202 This method uses `numpy.histogram` to bin the data in *x* and count the
7203 number of values in each bin, then draws the distribution either as a
7204 `.BarContainer` or `.Polygon`. The *bins*, *range*, *density*, and
7205 *weights* parameters are forwarded to `numpy.histogram`.
7206
7207 If the data has already been binned and counted, use `~.bar` or
7208 `~.stairs` to plot the distribution::
7209
7210 counts, bins = np.histogram(x)
7211 plt.stairs(counts, bins)
7212
7213 Alternatively, plot pre-computed bins and counts using ``hist()`` by
7214 treating each bin as a single point with a weight equal to its count::
7215
7216 plt.hist(bins[:-1], bins, weights=counts)
7217
7218 The data input *x* can be a singular array, a list of datasets of
7219 potentially different lengths ([*x0*, *x1*, ...]), or a 2D ndarray in
7220 which each column is a dataset. Note that the ndarray form is
7221 transposed relative to the list form. If the input is an array, then
7222 the return value is a tuple (*n*, *bins*, *patches*); if the input is a
7223 sequence of arrays, then the return value is a tuple
7224 ([*n0*, *n1*, ...], *bins*, [*patches0*, *patches1*, ...]).
7225
7226 Masked arrays are not supported.
7227
7228 Parameters
7229 ----------
7230 x : (n,) array or sequence of (n,) arrays
7231 Input values, this takes either a single array or a sequence of
7232 arrays which are not required to be of the same length.
7233
7234 bins : int or sequence or str, default: :rc:`hist.bins`
7235 If *bins* is an integer, it defines the number of equal-width bins
7236 in the range.
7237
7238 If *bins* is a sequence, it defines the bin edges, including the
7239 left edge of the first bin and the right edge of the last bin;
7240 in this case, bins may be unequally spaced. All but the last
7241 (righthand-most) bin is half-open. In other words, if *bins* is::
7242
7243 [1, 2, 3, 4]
7244
7245 then the first bin is ``[1, 2)`` (including 1, but excluding 2) and
7246 the second ``[2, 3)``. The last bin, however, is ``[3, 4]``, which
7247 *includes* 4.
7248
7249 If *bins* is a string, it is one of the binning strategies
7250 supported by `numpy.histogram_bin_edges`: 'auto', 'fd', 'doane',
7251 'scott', 'stone', 'rice', 'sturges', or 'sqrt'.
7252

Callers 15

histFunction · 0.80
test_histMethod · 0.80
test_histFunction · 0.80
test_legend_auto4Function · 0.80
test_alpha_handlesFunction · 0.80
test_hist_logFunction · 0.80
test_hist_log_2Function · 0.80
test_hist_log_barstackedFunction · 0.80
test_hist_bar_emptyFunction · 0.80

Calls 10

fillMethod · 0.95
_process_unit_infoMethod · 0.80
set_xscaleMethod · 0.80
_internal_updateMethod · 0.80
get_next_colorMethod · 0.45
clipMethod · 0.45
set_yscaleMethod · 0.45
copyMethod · 0.45
updateMethod · 0.45
set_labelMethod · 0.45

Tested by 15

test_histMethod · 0.64
test_histFunction · 0.64
test_legend_auto4Function · 0.64
test_alpha_handlesFunction · 0.64
test_hist_logFunction · 0.64
test_hist_log_2Function · 0.64
test_hist_log_barstackedFunction · 0.64
test_hist_bar_emptyFunction · 0.64
test_hist_float16Function · 0.64