matplotlib
import matplotlib.pyplot as plt
subplot绘图区域
plt.subplot(nrows,ncols,plot_number)
plot_number从左上角开始,起始为1
plt.plot(x,y,format_string,**kwargs)
- x:x轴数据,列表或数组。可选
- y:y轴数据,列表或数组
- format_string:控制曲线的格式字符串,可选。颜色、风格字符(虚实)、标记字符(△)ex:‘go-’
- **kwargs:第二组或更多的(x,y,format_string) color,linestyle,marker,makerfacecolor
显示中文
matplotlib.rcParams[‘font.family’]=‘SimHei’(改变的是全局字体)
方法二(推荐)
在有中文输出的地方,增加一个属性fontproperties
plt.xlabel('横轴:时间',fontproperties='SimHei',fontsize=20)
文本显示
函数 | 说明 |
---|---|
plt.xlabel() | |
plt.ylabel() | |
plt.title() | |
plt.text | 在任意位置增加文本 |
plt.annotate(s,xy=arrow_crd,xytext_crd,arrowprops=dict) | 在图形中增加带箭头的注释 |
子绘图区域
plt.subplot2grid(Gridspec,CurSpec,colspan=1,rowspan=1)
设定网格,选中网格,确定选中行列区域数量,编号从0开始
import matplotlib.gridspec as gridspec
gs = gridspec.Gridspec(3,3)
ax1=plt.subplot(gs[0,:])
基础图标函数
函数 | 说明 |
---|---|
plt.plot(x,y,fmt,…) | 坐标图 |
plt.boxplot(data,notch,position) | 箱型图 |
plt.bar(left,height,width,bottom) | 条形图 |
plt.barh(width,bottom,left,height) | 横向条形图 |
plt.polar(theta,r) | 极坐标图 |
plt.pie(data,explode) | 饼图 |
plt.scatter(x,y) | 散点图 |
plt.hist(x,bins,normed) | 直方图 |