设置x轴的数值显示范围
设置x轴的标签文本
绘制刻度线的网格线
绘制平行于x轴的水平参考线
绘制垂直于x轴的参考区域
添加图形内容细节的指向型注释文本
添加图形内容细节的无指向型注释文本
添加图形内容的标题
标示不同图形的文本标签图例
用于绘制柱状图
用于绘制条形图
用于绘制直方图
用于绘制饼图
用于绘制极线图
用于绘制气泡图
用于绘制棉棒图
用于绘制箱线图
用于绘制误差棒图
import matplotlib.pyplot as plt import numpy as np x=np.linspace(0.1,0.6,10) y=np.exp(x) error=0.05+0.15*x lower_error=error upper_error=0.3*error error_limit=[lower_error,upper_error] plt.errorbar(x,y,yerr=error_limit,fmt=":o", ecolor="y",elinewidth=4, ms=5,mfc="c",mec='r', capthick=1,capsize=2) plt.xlim(0,0.7) plt.show()
绘制堆积折线图
绘制间断条形图
import matplotlib as mpl import matplotlib.pyplot as plt import numpy as np mpl.rcParams["font.sans-serif"]=["LiSu"] mpl.rcParams["axes.unicode_minus"]=False plt.broken_barh([(30,100),(180,50),(260,70)],(20,8),facecolors="#1f78b4") plt.broken_barh([(60,90),(190,20),(230,30),(280,60)],(10,8),facecolors=("#7fc97f","#beaed4","#fdc086","#ffff99")) plt.xlim(0,360) plt.ylim(5,35) plt.xlabel("演出时间") plt.xticks(np.arange(0,361,60)) plt.yticks([15,25],["歌剧院A","歌剧院B"]) plt.grid(ls='-',lw=1,color="gray") plt.title("不同地区的歌剧院的演出时间比较") plt.show()
绘制阶梯图
import matplotlib.pyplot as plt import numpy as np x=np.linspace(1,10,10) y=np.sin(x) plt.step(x,y,color="#8dd3c7",where="pre",lw=2) plt.xlim(0,11) plt.xticks(np.arange(1,11,1)) plt.ylim(-1.2,1.2) plt.show()
legend()
title()
xlim()
xticks()
import matplotlib as mpl import matplotlib.pyplot as plt mpl.rcParams["font.sans-serif"]=["SimHei"] mpl.rcParams["axes.unicode_minus"]=False labels = "A难度水平","B难度水平","C难度水平","D难度水平" students = [0.35,0.15,0.20,0.30] explode = (0.1,0.1,0.1,0.1) colors = ["#377eb8","#e41a1c","#4daf4a","#984ea3"] plt.pie(students, explode=explode, labels=labels, autopct="%1.1f%%", startangle=45, shadow=True, colors=colors) plt.title("选择不同难度测试试卷的学生百分比") colLabels = ["A难度水平","B难度水平","C难度水平","D难度水平"] rowLabels = ["学生选择试卷人数"] studentValues = [[350,150,200,300]] colColors = ["#377eb8","#e41a1c","#4daf4a","#984ea3"] plt.table(cellText=studentValues, cellLoc="center", colWidths=[0.1]*4, colLabels=colLabels, colColours=colColors, rowLabels=rowLabels, rowLoc="center", loc="bottom") plt.show()
定位器(locator)——设置刻度线的位置
刻度格式器(formatter)——设置刻度标签的显示样式