当前位置:网站首页>Histogram of pyplot module of Matplotlib (hist(): basic parameter, return value)
Histogram of pyplot module of Matplotlib (hist(): basic parameter, return value)
2022-07-28 04:45:00 【If you believe in orange, you will be in good spirits】
List of articles
Histogram
Concept : Histogram is used to measure the probability distribution of continuous variables .
Parameters,
Use matplotlib Draw histogram :
Histogram has only one parameter x!!! Unlike a bar chart that needs to be passed in x,y
plt.hist(
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,
*,
data=None,
**kwargs,
)
hist() Parameters of
x: input databins: It could be a bins The integer value of the quantity , It can also meanbinsA sequence of . The default value is 10
bins( Divide the value into equal parts ), That is to say, we need to divide the continuous value into different equal parts first , Then calculate the amount of data in each copy .
range
Set up X Start and end scales of axis scaledensity: If the value is True, The value of histogram will be normalized , Formation probability density , The default value is Falsecolor: Specifies the color of the histogram . Can be a single color value or a sequence of colors . If more than one data set is specified , The color sequence will be set to the same order . If not specified , A default line color will be usedorientation: By settingorientationbyhorizontalCreate a horizontal histogram . The default value isverticalalign:{'left', 'mid', 'right'}, default: 'mid'left: The bar chart is located on the left edge .'mid': The bar graph is in the center .'right': The bar chart is located on the right edge .
label: Add legendrwidth: The relative width of the bar
Parameter examples and explanations
import numpy as np
x = np.random.randint(1,10,size = 10)
# Show me rwidth The role of
print(x)
plt.hist(x, bins=5, rwidth=0.5, range = (0, 10), color = "red", label=' Statistics ') # Divide the histogram into 5 Share , Show the distribution frequency
plt.legend()
plt.show()
label: After declaring the legend , Use legend(), To display
rwidth: Set the proportion of graphics x The proportion of the shaft
range: Set up X The interval of the axis scale
Code run results 
bins Analyze by setting the list as interval and return value
print(x)
n, bins, patches = plt.hist(x, bins=[1,3,5,8,10], rwidth=0.5)
plt.show()
- What we specify is the edge of the interval , Each interval is [1,3) [3,5) [5,8) [8,10],
rwidth: Will follow the interval 0.5 To display , such as x Axis 1 To 3 Half of ,5 To 8 Half of ,- Except for the last interval , All intervals are left closed and right open
- And the length of each interval need not be equal
- Data outside our specified interval will be directly ignored
notes : If
binsIn list form , berangeIt has no effect
print(' Number distribution :', n)
print(' Interval division :', bins)
print(patches)
n: Means falling into eachbinsNumber of samples inbins: Partition interval of table intervalpatches:Patch objects, I don't understand
Code run results 
density
print(x)
n, bins, patches = plt.hist(x, bins=[1,3,5,8,10], rwidth=0.5, density=True)
plt.show()
print(' Number distribution :', n)
print(' Interval division :', bins)
print(patches)
densitySet toTruewhen , The vertical axis shows the distribution frequencynThis is the value of the distribution frequency
Reference article
Matplotlib Official Manual address
python Draw histogram matplotlib.pyplot.hist( ) Methods common parameters are explained in detail
Welcome to leave a message in the comment area , To know everything , can . If it feels good , Don't forget to like the collection !

边栏推荐
- scipy.stats.chi2
- Space complexity calculation super full sorting!! (calculation of hand tearing complexity
- Important SQL server functions - numeric functions
- 吉利AI面试题【杭州多测师】【杭州多测师_王sir】
- 01 node express system framework construction (express generator)
- CMake使用基础汇总
- Take out system file upload
- Zhejiang University and other recent review papers on deep learning new drug design
- Select sorting method
- Study notes of Gu Yujia on July 27, 2022
猜你喜欢

吉利AI面试题【杭州多测师】【杭州多测师_王sir】

The first artificial intelligence security competition starts. Three competition questions are waiting for you to fight

Ma Yi, Shen Xiangyang, Cao Ying's latest AI overview is hot! It took 3 months to build, netizens: required papers
![[函数文档] torch.histc 与 paddle.histogram 与 numpy.histogram](/img/ee/ea918f79dc659369fde5394b333226.png)
[函数文档] torch.histc 与 paddle.histogram 与 numpy.histogram

解析智能扫地机器人中蕴含的情感元素

Use and expansion of fault tolerance and fusing

Internet of things industrial serial port to WiFi module wireless routing WiFi module selection

Important SQL server functions - numeric functions

Redis类型

Jupyter notebook installation code prompt function
随机推荐
Password key hard coding check
Reading of a unified generic framework for aspect based sentimental analysis
字符串0123456789abcdef,子串(非空且非同串本身)的个数是多少【杭州多测师】【杭州多测师_王sir】...
[Sylar] framework -chapter24- support business modularization
[Sylar] framework -chapter12 bytearray module
Practice and thinking of AI standardization engine in pink client
[Sylar] framework -chapter15 stream module
gerrit操作-回退掉某个patch_set
Destructor of member function
[daily one] visual studio2015 installation in ancient times
Reading the paper "learning span level interactions for aspect sentimental triple extraction"
【sylar】框架篇-Chapter15-Stream 模块
[Hongke technology] Application of network Multimeter in data center
【sylar】框架篇-Chapter24-支持业务模块化
Domain name (subdomain name) collection method of Web penetration
How to upgrade a pair of 12.2 RAC(primary) and a pair of 12.2 RAC(dataguard) to 19c
Pyqt based grouping tool
Angr(十一)——官方文档(Part2)
String 0123456789abcdef, what is the number of substrings (not empty and not the same string itself) [Hangzhou multi tester] [Hangzhou multi tester _ Wang Sir]
【sylar】框架篇-Chapter12-ByteArray 模块