from matplotlib import pyplot as plt import matplotlib matplotlib.rcParams['font.sans-serif'] = ['SimHei'] #显示中文
plt.bar(range(5),[100,200,300,400,500],color="red")
plt.xticks(range(5),['A','B','C','D','E'])
plt.xlabel('姓名')
plt.ylabel('得分')
plt.title('学生分数')
plt.show()
plt.plot([100,200,300,400,500],color='green') #画线
plt.savefig('a.jpg') #保存图片
饼图
labels = ['A','B','C','D'] plt.pie([50,30,50,20],labels=labels,autopct='%1.1f%%') plt.title('人口比例')
autopct='%1.1f%%' 显示百分比
直方图
heights = [180,160,177,177] plt.hist(heights,color="green",alpha=0.5) plt.xlabel('身高') plt.ylabel('人数') plt.title('身高统计')
alpha=0.5 透明度
散点图
import numpy as np np.random.seed(10) #随机种子 吧你的随机数给固定住 heights=[] weights=[] heights.append(np.random.randint(50,100,size=50)) weights.append(np.random.randint(50,100,size=50)) plt.scatter(heights,weights,marker='*',color='green')
marker='*'改变形状
折线图
x = [2,16,84,5,2] y = [3,12,5,6,7] plt.plot(x,y)