container Artist:
a. Figure
matplotlib.figure.Figure
是最顶层的container Artist
,它包含了图表中的所有元素。Figure.patch
属性:Figure
的背景矩形Figure.axes
属性:持有的一个Axes
实例的列表(包括Subplot
)Figure.images
属性:持有的一个FigureImages patch
列表Figure.lines
属性:持有一个Line2D
实例的列表(很少使用)Figure.legends
属性:持有的一个Figure Legend
实例列表(不同于Axes.legends
)Figure.patches
属性:持有的一个Figure pathes
实例列表(很少使用)Figure.texts
属性:持有的Figure Text
实例列表
其他的属性:
Figure.figsize
属性:图像的尺寸,(w,h)
,以英寸为单位Figure.dpi
属性:图像分辨率Figure.facecolor
属性:背景色Figure.edgecolor
属性:edge color
Figure.linewidth
:edge linewidth
Figure.frameon
:如果为False
,则不绘制图像Figure.subplotpars
:一个SubplotParams
实例Figure.tight_layout
:如果为False
,则使用subplotpars
;否则使用tight_layout()
调整subplot parameters
2. 当你执行Figure.add_subplot()
或者Figure.add_axes()
时,这些新建的Axes
都被添加到Figure.axes
列表中。
3. 由于Figure
维持了current axes
,因此你不应该手动的从Figure.axes
列表中添加删除元素,而是要通过Figure.add_subplot()
、Figure.add_axes()
来添加元素,通过Figure.delaxes()
来删除元素。但是你可以迭代或者访问Figure.axes
中的Axes
,然后修改这个Axes
的属性。
4. 可以通过Figure.gca()
获取current axes
,通过Figure.sca()
设置current axes
。
5. Figure
也有它自己的text
、line
、patch
、image
。你可以直接通过add primitive
语句直接添加。但是注意Figure
默认的坐标系是以像素为单位,你可能需要转换成figure
坐标系:(0,0)表示左下点,(1,1)表示右上点。
6. 创建Figure
的方法:
matplotlib.pyplot.figure(num=None, figsize=None, dpi=None, facecolor=None, edgecolor=None, frameon=True, FigureClass=<class 'matplotlib.figure.Figure'>, **kwargs)
num
:一个整数或者字符串。- 若未提供,则创建一个新的
figure
。 - 如果给出了一个整数,而且某个现有的
figure
对象的number
属性刚好等于这个整数,则激活该figure
并且返回该figure
;否则创建一个新的figure
- 如果是个字符串,则创建一个新的
figure
,并且将window title
设置为该字符串。
- 若未提供,则创建一个新的
figsize
:一对整数的元组。给出了英寸为单位的高度和宽度。默认由rc
的figure.figsize
给出dpi
:一个整数,给出figure
的分辨率。默认由rc
的figure.dpi
给出facecolor
:背景色。若未提供,则由rc
的figure.facecolor
给出edgecolor
:border color
。若未提供,则由rc
的figure.edgecolor
给出
返回一个figure
学员评价