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 colorFigure.linewidth:edge linewidthFigure.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
学员评价