直方图
import numpy as np
import matplotlib.pyplot as plt
# 准备 50 个随机测试数据
scores = np.random.randint(0,100,50)#0到100之间50个随机整数
print(scores)
# 绘制直方图
plt.hist(scores, bins=9, histtype='stepfilled')
plt.show()
饼图
import numpy as np
import matplotlib.pyplot as plt
data = np.array([20, 50, 10, 15, 30, 55])
pie_labels = np.array(['A', 'B', 'C', 'D', 'E', 'F'])
# 绘制饼图 : 半径为 1.5, 数值保留 1 位小数
plt.pie(data, radius=1.5, labels=pie_labels, autopct='%3.1f%%')
plt.show()
散点图
num = 50
x = np.random.rand(num)#50个均匀正态分布的样本值
y = np.random.rand(num)
plt.scatter(x, y,color='m')