课程评价 (0)

请对课程作出评价:
0/300

学员评价

暂无精选评价
20分钟

Figure 的一些方法

  1. 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:一个数值,指定xy轴每个单位的尺寸比例。也可以设定为字符串'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-axesplot_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:一个数值,指定xy轴每个单位的尺寸比例。也可以设定为字符串'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):设置acurrent 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:设定subplotfigure edge之间的距离。单位为font-size
  • h_pad/w_padsubplot之间的高距/宽距。