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

边栏推荐
- 低代码是开发的未来吗?浅谈低代码平台
- Password key hard coding check
- np. The data returned from delete details is the data after deleting the specified dimension
- ADB environment configuration
- Bio annotation of emotion analysis aste triples extraction
- 【sylar】框架篇-Chapter15-Stream 模块
- [Sylar] framework chapter -chapter21- environment variable module
- Cmake usage base summary
- Harmony's Application on the shelves reported an error. The solution of "please use the API of the released version to develop the application and apply for listing"
- High number_ Chapter 4__ Curvilinear integral_ Exercise solution
猜你喜欢
![[每日一氵]上古年代的 Visual Studio2015 安装](/img/b1/066ed0b9e93b8f378c89ee974163e5.png)
[每日一氵]上古年代的 Visual Studio2015 安装

Jupyter Notebook安装代码提示功能

Web渗透之域名(子域名)收集方法

Mysql database -- first knowledge database

提升学生群体中的STEAM教育核心素养

Is low code the future of development? On low code platform

《KG-BERT: BERT for Knowledge Graph Completion》

(clone virtual machine steps)

Jupyter notebook installation code prompt function

Constructor of member function
随机推荐
Explain initialization list
[Sylar] framework Chapter 6 collaborative scheduling module
transform: failed to synchronize: cudaErrorAssert: device-side assert triggered
Depth traversal and breadth traversal of tree structure in JS
启发国内学子学习少儿机器人编程教育
Sort - cardinal sort
[函数文档] torch.histc 与 paddle.histogram 与 numpy.histogram
01-Node-Express系统框架搭建(express-generator)
机器人教育在STEM课程中的设计研究
字符串0123456789abcdef,子串(非空且非同串本身)的个数是多少【杭州多测师】【杭州多测师_王sir】...
Jupyter notebook installation code prompt function
Chuangyuan will join hands with 50+ cloud native enterprises to explore new models to cross the digital divide
[Sylar] framework -chapter20- daemon module
Niuke, convert string to integer
(克隆虚拟机步骤)
np. The data returned from delete details is the data after deleting the specified dimension
【sylar】框架篇-Chapter9-hook 模块
Elementary level of C language -- while, for, do while
动态sql和分页
Practice and thinking of AI standardization engine in pink client