Matplotlib.axes.axes.set

您所在的位置:网站首页 rat880-d Matplotlib.axes.axes.set

Matplotlib.axes.axes.set

#Matplotlib.axes.axes.set| 来源: 网络整理| 查看: 265

Matplotlib.axes.axes.set_title()

Matplotlib是Python中的一个库,它是NumPy库的数值-数学扩展。Axes包含了大多数图形元素:Axis、Tick、Line2D、Text、Polygon等,并设置坐标系。Axes的实例通过callbacks属性支持回调。

函数:Matplotlib.axes.axes.set_title()

matplotlib库的Axes模块中的Axes.set_title()函数用于设置坐标轴的标题。

语法:Axes.set_title(self, label, fontdict=None,loc= ‘ center ‘, pad=None,**kwargs)

参数:该方法接受以下参数。

label:这个参数是用于标题的文本。 fontdict:这个参数是控制标题文本外观的字典。 loc:该参数用于设置标题的位置{‘ center ‘, ‘ left ‘, ‘ right ‘}。 pad:这个参数是标题从坐标轴顶部的偏移量,单位为点。

Returns:该方法返回表示标题的matplotlib文本实例。

下面的例子演示了matplotlib.axes.axes.set_title()函数在matplotlib.axes中的作用:

示例1 # Implementation of matplotlib function import os from matplotlib import font_manager as fm, rcParams import matplotlib.pyplot as plt    fig, ax = plt.subplots()    fpath = os.path.join(rcParams["datapath"],                       "fonts/ttf/cmr10.ttf")    prop = fm.FontProperties(fname = fpath) fname = os.path.split(fpath)[1] ax.set_title('Title with special font: {}'.format(fname),              fontproperties = prop,               fontsize = 14)    plt.show()

输出:

Matplotlib.axes.axes.set_title()

示例2 # Implementation of matplotlib function import numpy as np import matplotlib.pyplot as plt    x = np.arange(0.1, 5, 0.1) y = np.exp(-x)    yerr = 0.1 + 0.1 * np.sqrt(x)    fig, axs = plt.subplots(nrows = 1,                         ncols = 2,                          sharex = True) ax = axs[0] ax.errorbar(x, y, yerr = yerr,              color ="green") ax.set_title('Title of Axes 1',               fontweight ="bold")    ax = axs[1] ax.errorbar(x, y, yerr = yerr,             errorevery = 5,              color ="green")    ax.set_title('Title of Axes 2',              fontweight ="bold")          fig.suptitle('matplotlib.axes.Axes.set_title() \ function Example\n')    plt.show()

输出:

Matplotlib.axes.axes.set_title()



【本文地址】


今日新闻


推荐新闻


CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3