一、初始化。
plt.figure()用来初始化一个图像对象。 可通过设定figsize=(width,height)来设定图像的大小。
figure(num=None,figsize=None,dip=None,facecolor=None,edgecolor=None, frameon=True,FigureClass=<class 'matplotlib.figure.Figure'>,clear=False,**kwargs)
具体参数如下:num:图像编号或名称,可以是int或者str。
figsize:(float,float):以英寸为单位的width,height。默认为rcParams["figure.figsize"]=[6.4,4.8]
dpi:分辨率。默认为rcParams["figure.dip"]=100
facecolor:背景颜色,默认为rcParams["figure.facecolor"]='w'
edgecolor:边框颜色,默认为rcParams["figure.edgecolor"]='w'
frameon:bool,默认为True,如果为false,suppress drawing the figure frame,不显示边框。
FigureClass:Figure的子类,可以客户化Figure实例。
clear:bool,默认False,如果为True,如果图像已经存在,清除它。
二、plt.subplot()
使用plt.subplot():为当前Figure增加一个子图。
subplot(nrows,ncols,index,**kwargs)
subplot(pos,**kwargs)
subplot(ax)
三、plt.subplots():
plt.subplots():创建一个Figure对象和一系列子图。参数:
参数:nrows,ncols:子图行列的数量。
sharex,sharey: 是否共享x,y轴
例如:fig, axarr = plt.subplots(3,4,sharex=True,sharey=True)

四、plt.subplot2grid()
plt.subplot2grid()与 plt.subplots()不同,可以创建大小不同的子图。使用rowspan和colspan布局。
五、plt.figure().add_subplot()
plt.figure().add_subplot():add an Axes to the figure as part of a subplot arragement。
网友评论