Change language

sciPy function stats.histogram () | python

scipy.stats.histogram (a, numbins, defaultreallimits, weights, printextras) works to split a range into multiple bins and then returns the number of instances in each bin. This function is used to build a histogram.

Parameters:
arr: [array_like] input array.
numbins: [int] number of bins to use for the histogram. [Default = 10]
defaultlimits: (lower, upper) range of the histogram.
weights: [array_like] weights for each array element.
printextras: [array_like] to print the no, if extra points to the standard output, if true

Results:
- cumulative frequency binned values ​​
- width of each bin
- lower real limit
- extra points.

Code # 1:

# building histogram

import scipy

import numpy as np 

import matplotlib.pyplot as plt

 

hist, bin_edges = scipy.histogram ([ 1 , 1 , 2 , 2 , 2 , 2 , 3 ],

bins = range ( 5 ))

 
# Checking results

print ( "No. of points in each bin: " , hist)

print ( "Size of the bins :" , bin_edges)

 
# building a histogram

plt.bar (bin_edges [: - 1 ], hist, width = 1 )

plt.xlim ( min (bin_edges), max (bin_edges))

plt.show ()

Output:

 No. of points in each bin: [0 2 4 1] Size of the bins: [0 1 2 3 4] 

Shop

Gifts for programmers

Learn programming in R: courses

$FREE
Gifts for programmers

Best Python online courses for 2022

$FREE
Gifts for programmers

Best laptop for Fortnite

$399+
Gifts for programmers

Best laptop for Excel

$
Gifts for programmers

Best laptop for Solidworks

$399+
Gifts for programmers

Best laptop for Roblox

$399+
Gifts for programmers

Best computer for crypto mining

$499+
Gifts for programmers

Best laptop for Sims 4

$

Latest questions

PythonStackOverflow

Common xlabel/ylabel for matplotlib subplots

1947 answers

PythonStackOverflow

Check if one list is a subset of another in Python

1173 answers

PythonStackOverflow

How to specify multiple return types using type-hints

1002 answers

PythonStackOverflow

Printing words vertically in Python

909 answers

PythonStackOverflow

Python Extract words from a given string

798 answers

PythonStackOverflow

Why do I get "Pickle - EOFError: Ran out of input" reading an empty file?

606 answers

PythonStackOverflow

Python os.path.join () method

384 answers

PythonStackOverflow

Flake8: Ignore specific warning for entire file

360 answers

News


Wiki

Python | How to copy data from one Excel sheet to another

Common xlabel/ylabel for matplotlib subplots

Check if one list is a subset of another in Python

How to specify multiple return types using type-hints

Printing words vertically in Python

Python Extract words from a given string

Cyclic redundancy check in Python

Finding mean, median, mode in Python without libraries

Python add suffix / add prefix to strings in a list

Why do I get "Pickle - EOFError: Ran out of input" reading an empty file?

Python - Move item to the end of the list

Python - Print list vertically