Overview of pyplot basic chart functions

Function overview

Insert picture description here
Insert picture description here
Insert picture description here

1. Pyplot pie chart drawing

plt.pie ()

import matplotlib.pyplot as plt

labels = 'Frogs','Hogs','Dogs','Logs'
#labels给出每块对应的标签
sizes = [15,30,45,10]
explode = (0,0.1,0,0)
#explode指出应该突出哪一块

plt.pie(sizes,
	explode=explode, 
	labels=labels,
	autopct='%1.1f%%',
	shadow=False, #表示是二维还是带阴影
	startangle=90)
plt.show()

Result:
Insert picture description here
Add a sentence to the above code:

plt.axis('equal')

You can get a circular pie chart.
Insert picture description here

2. Pyplot histogram drawing

import matplotlib.pyplot as plt
import numpy as np

np.random.seed(0)
mu, sigma = 100, 20
#均值和标准差
a = np.random.normal(mu,sigma,size=100)

plt.hist(a,20,
         normed=1,
         histtype='stepfilled',
         facecolor='b',
         alpha=0.75)#20是直方图个数
#normed=1表示将出现在直方图中的数据个数转换为概率
#normed=0,纵坐标就是出现在直方图中的数据个数。
plt.title('Histogram')
plt.show()

.

3. Drawing of scatter plot

Object-oriented approach:

import matplotlib.pyplot as plt
import numpy as np

fig, ax = plt.subplots()#默认(1,1,1)
ax.plot(10*np.random.randn(100),10*np.random.randn(100),'o')
ax.set_title('Simple Scatter')
plt.show()

Insert picture description here

Guess you like

Origin blog.csdn.net/weixin_42253964/article/details/106872871