matplotlib.pyplot.suptitle()函数
Matplotlib是Python中的一个库,它是NumPy库的数学扩展。Pyplot是一个基于状态的Matplotlib模块接口,该模块提供了一个类似matlab的接口。
matplotlib.pyplot.suptitle()函数
使用matplotlib库pyplot模块中的suptitle()函数向图形添加标题。
语法:matplotlib.pyplot.suptitle (t, * * kwargs)
参数:该函数将有以下参数:
- t:你想添加到图表中的标题文本。
- x:文本在图形坐标中的x位置。默认值为0.5。
- y:文本在图形坐标中的y位置。默认值是0.98。
- horizontalalignment (ha): {‘ center ‘, ‘ left ‘, ‘ right ‘},文本的水平对齐是相对于(x, y)。它的默认值是’ center ‘。
- verticalalignment (va): {‘ top ‘, ‘ center ‘, ‘ bottom ‘, ‘ baseline ‘},文本的垂直对齐相对于(x, y)。它的默认值是’ top ‘。
- fontsize, size: {size in points, ‘ xx-small ‘, ‘ x-small ‘, ‘ small ‘, ‘ medium ‘, ‘ large ‘, ‘ x-large ‘, ‘ xx-large ‘},文本的字体大小。它的默认值是’ large ‘。
- fontweight, weight:{0-1000范围内的数值,’ ultralight ‘, ‘ light ‘, ‘ normal ‘, ‘ regular ‘, ‘ book ‘, ‘ medium ‘, ‘ roman ‘, ‘ semi – bold ‘, ‘ demibold ‘, ‘ demi ‘, ‘ bold ‘, ‘ heavy ‘, ‘ extra bold ‘, ‘ black ‘},文本的字体重量。它的默认值是’ normal ‘。
- fontproperties:None或dict,一个字体属性的dict。如果给定了fontproperties,字体大小和粗细的默认值将取自fontproperties的默认值。rcParams[” figure.titlesize “] = ‘ large ‘和rcParams[” figure.titleweight “] = ‘ normal ‘在本例中被忽略。
- **kwargs:额外的kwargs是matplotlib.text# @text属性。
返回:标题的Text实例。
下面的例子演示了matplotlib.pyplot.suptitle()函数在matplotlib.pyplot中的作用:
示例1
向图形添加一个字体大小为12的标题。
输出:
示例2
向左侧水平对齐和字体大小为12的图形添加标题。
输出:
示例3
向图形添加带有加粗字体和大字体的title。
输出: