Figure 的一些方法
add_axes(*args, **kwargs)
:创建一个Axes
对象。如果已经存在同样位置同样参数的一个Axes
,则返回该Axes
,并将其设为current Axes
。其参数有:rect
:一个元组,代表了(left,bottom,width,height)
,它是第一个位置参数axisbg
:一个color
,背景色frameon
:布尔值,是否display frame
sharex
:另一个Axes
对象,与该Axes
共享xaxis
sharey
:另一个Axes
对象,与该Axes
共享yaxis
projection
:坐标系类型。projection='polar'
也等价于polar=True
aspect
:一个数值,指定x
和y
轴每个单位的尺寸比例。也可以设定为字符串'equal'/'auto'
- 关键字参数为
projection
+Axes
的合法关键字
如果你想在同样的一个
rect
创建两个Axes
,那么你需要设置label
参数。不同的Axes
通过不同的label
鉴别。 如果你使用了fig.delaxes()
从Figure
中移除了ax
,那么你可以通过fig.add_exes(ax)
来将其放回。2.
add_subplot(*args,**kwargs)
:创建一个subplot
。如果已经存在同样位置同样参数的一个subplot
,则返回该subplot
,并将其设为current Axes
。- 关键字参数为
projection
+Axes
的合法关键字。projection
:坐标系类型。projection='polar'
也等价于polar=True
- 位置参数为:
add_subplot(nrows, ncols, plot_number)
。表示nrows
行,nclos
列每个单元格是一个sub-axes
。plot_number
给出了指定的sub-axes
,从 1开始。最大为nrows*ncols
。当这三个数字都是个位数时,可以使用一个三位数代替,每位代表一个数。 axisbg
:一个color
,背景色frameon
:布尔值,是否display frame
sharex
:另一个Axes
对象,与该Axes
共享xaxis
sharey
:另一个Axes
对象,与该Axes
共享yaxis
projection
:坐标系类型。projection='polar'
也等价于polar=True
aspect
:一个数值,指定x
和y
轴每个单位的尺寸比例。也可以设定为字符串'equal'/'auto'
3.autofmt_xdate(bottom=0.2, rotation=30, ha='right')
:用于设置Date ticklabel
的位置。bottom
设置距离subplot
底部的位置。rotation
设置了xtick label
的旋转角度。ha
设置xtick label
的对其方式。该函数主要用于当xtick
为日期,可能会重叠,因此可以旋转一个角度
4.clear()
:清除一个figure
5. clf(keep_observers=False)
:清除一个figure
。如果keep_observers=True
,则gui
仍然会跟踪figure
中的axes
6. colorbar(mappable, cax=None, ax=None, use_gridspec=True, **kw)
:为mappable
创建一个colorbar
。其中:
mapple
:一个ScalarMapple
实例。它可以是Image/ContourSet...
。cax
:指定在哪个axes
中绘制colorbar
。也可以是None
ax
:None | parent axes object(s) from which space for a new colorbar axes will be stolen.use_gridspec
:False | If cax is None, a new cax is created as an instance of Axes. If ax is an instance of Subplot and use_gridspec is True, cax is created as an instance of Subplot using the grid_spec module
7.delaxes(a)
:从figure
中移除xes
8.gca(**kwargs)
:返回current axes
。如果不存在则创建一个
9. get_children()
:获取figure
中包含的artists
10. get_dpi/get_edgecolor/get_facecolor/get_figheight/get_figwidth/get_frameon/get_tight_layout...
:获取对应的属性值
11. get_size_inches()
:返回fig
的当前尺寸(单位为英寸。1in=2.54cm
)
12. legend(handles, labels, *args, **kwargs)
:创建图例。
handles
:是一个Lin2D/Patch
等实例的一个序列labels
:是个字符串序列,用于给上述实例添加图例说明loc
:指定图例的位置。可以是字符串'best'
/'upper right'
/'upper left'
/'lower left'
/'lower right'
/'right'
/'center left'
/'center right'
/'lower center'
/'upper center'
/'center'
。你也可以指定坐标(x,y)
,其中(0,0)
是左下角,(1,1)
是右上角numpoint
/scatterpoints
:图例上每个图例线的点数fancybox
:如果为True
,图例的边框采用圆角矩形shadow
:如果为True
,图例添加背影ncol
:列数title
:图例的标题framealpha
:一个浮点数,从0到 1,图例的透明度frameon
:一个布尔值,如果为True
,则绘制图例的背景框。否则不绘制。
13. legend(handles, labels, *args, **kwargs)
:创建图例。
handles
:是一个Lin2D/Patch
等实例的一个序列labels
:是个字符串序列,用于给上述实例添加图例说明loc
:指定图例的位置。可以是字符串'best'
/'upper right'
/'upper left'
/'lower left'
/'lower right'
/'right'
/'center left'
/'center right'
/'lower center'
/'upper center'
/'center'
。你也可以指定坐标(x,y)
,其中(0,0)
是左下角,(1,1)
是右上角numpoint
/scatterpoints
:图例上每个图例线的点数fancybox
:如果为True
,图例的边框采用圆角矩形shadow
:如果为True
,图例添加背影ncol
:列数title
:图例的标题framealpha
:一个浮点数,从0到 1,图例的透明度frameon
:一个布尔值,如果为True
,则绘制图例的背景框。否则不绘制。
14. sca(a)
:设置a
为current axes
并返回它
15. set_dpi/set_edgecolor...
:设置相关属性
16. show(warn=True)
:显示图像。如果warn=True
,则开启警报
17. subplots_adjust(left=None, bottom=None, right=None, top=None,wspace=None, hspace=None)
:调整subplot
的位置。
18. suptitle(t, **kwargs)
:设置图像标题。t
为标题字符串。关键字参数就是Text
对象的参数:
x
:在图形坐标系中,标题的横坐标(范围 0~1)y
:在图形坐标系中,标题的纵坐标(范围 0~1)horizontalalignment
:标题水平对齐方式,默认为'center'
verticalalignment
:标题垂直对齐方式,默认为'top'
fontsize
:字体大小
19. text(x, y, s, *args, **kwargs)
:添加文本。
x
:在图形坐标系中,标题的横坐标(范围 0~1)y
:在图形坐标系中,标题的纵坐标(范围 0~1)s
:文本字符串
20. tight_layout(renderer=None, pad=1.08, h_pad=None, w_pad=None, rect=None)
:调整subplot
的间距。
pad
:设定subplot
和figure edge
之间的距离。单位为font-size
h_pad/w_pad
:subplot
之间的高距/宽距。
学员评价