当前位置:网站首页>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 !

边栏推荐
- linux下安装mysql
- NAT基本原理与私有IP
- Tiantian AMADA CNC bending machine touch screen maintenance rgm21003 host circuit board maintenance
- 外卖系统 文件上传
- excel实战应用案例100讲(十一)-Excel插入图片小技巧
- 欧拉路/欧拉回路
- Rendering process, how the code becomes a page (2)
- 【sylar】框架篇-Chapter6-协程调度模块
- Reading of a unified generic framework for aspect based sentimental analysis
- Use and expansion of fault tolerance and fusing
猜你喜欢
![[practice] use the web animations API to realize a clock with accurate timing](/img/cd/9b9ab27ea6a9909725371eaa809b9f.jpg)
[practice] use the web animations API to realize a clock with accurate timing
![[每日一氵]上古年代的 Visual Studio2015 安装](/img/b1/066ed0b9e93b8f378c89ee974163e5.png)
[每日一氵]上古年代的 Visual Studio2015 安装

Machine learning and deep learning -- normalization processing

Reading of a unified generic framework for aspect based sentimental analysis

Important SQL server functions - string utilities

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

Reading of seq2path: generating sentimental tuples as paths of a tree

Domain name (subdomain name) collection method of Web penetration

Jupyter notebook installation code prompt function

(clone virtual machine steps)
随机推荐
[Sylar] practical part - redis based parameter query service
pytorch打包exe出现WARNING: file already exists but should not: C:\Users\workAI\AppData\Local\Temp\_MEI13
Euler road / Euler circuit
Blooming old trees -- quickly build a map bed application with imageprocessor
Jupyter Notebook安装代码提示功能
High number_ Chapter 4__ curvilinear integral
Cloud native Devops status survey questionnaire solicitation: kodelurover launched jointly with oschina
【sylar】框架篇-Chapter22-辅助模块
Basic knowledge of network security - password (I)
Object locking in relational database transactions
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] framework Chapter 6 collaborative scheduling module
[Sylar] framework -chapter15 stream module
吉利AI面试题【杭州多测师】【杭州多测师_王sir】
【sylar】框架篇-Chapter20-守护进程模块
10 more advanced open source command line tools
Web渗透之域名(子域名)收集方法
[Sylar] framework -chapter24- support business modularization
25 openwrt guest network add
High number_ Chapter 4__ Curvilinear integral_ Exercise solution