python的title函数_Title函数--Matplotlib
函数语法:
Title(label, fontdict=None, loc=None, pad=None, *, y=None, **kwargs)
函数功能:
Set a title for the axes.
设置坐标系标题
函数参数:
**label:**str ,Text to use for the title
字符串,⽤于标题⽂本内容
fontdictdict: A dictionary controlling the appearance of the title text, the default fontdict is:
字体字典项:控制标题⽂本外观,默认设置如下:
{'fontsize': rcParams['axes.titlesize'],
'fontweight': rcParams['axes.titleweight'],
'color': rcParams['axes.titlecolor'],
'verticalalignment': 'baseline',
'horizontalalignment': loc}
loc: {‘center’, ‘left’, ‘right’}, default: rcParams[“axes.titlelocation”] (default: ‘center’)。Which title to set
标题⽂本的位置,默认’center’,可以设置’center’, ‘left’, ‘right’,控制标题的左右移动
y: float, default: rcParams[“axes.titley”] (default: None)
Vertical axes loation for the title (1.0 is the top). If None (the default), y is determined automatically to avoid decorators on the axes.
浮点型,标题的垂直位置(顶部是1.0)。 如果为None(默认),则⾃动确定,控制标题的上下移动
pad: float, default: rcParams[“axes.titlepad”] (default: 6.0)。The offset of the title from the top of the axes, in points.
浮点型,标题离轴顶部的偏移量,默认6
Other Parameters:
**kwargs: Text properties 。Other keyword arguments are text properties
其他参数 : 设置其他⽂本属性,控制标签⽂本的展⽰外观
增加图形标题:Title
设置标题字体:fontdict
import matplotlib.pyplot as plt
import numpy as np
x = np.linspace(0.05, 10, 1000)
y = np.cos(x)
plt.plot(x, y,ls = '--',lw = 2,label = 'plot figure')
plt.legend(loc = 'lower left') #指定图例位置
plt.xlabel('x-axis') #增加x轴标签
plt.ylabel('y-label') #设置标签字体字典
plt.title('y = cos(x)',fontdict = {'fontsize': 18,'fontweight':100,'color': 'green',
'verticalalignment':'bottom','horizontalalignment':'left'}) #设置标题字体
plt.show()
fonsize: float or {‘xx-small’, ‘x-small’, ‘small’, ‘medium’, ‘large’, ‘x-large’, ‘xx-large’}linspace函数python
字体⼤⼩: 浮点型,或者取值为{‘xx-small’, ‘x-small’, ‘small’, ‘medium’, ‘large’, ‘x-large’, ‘xx-large’}
fonweight: {a numeric value in range 0-1000, ‘ultralight’, ‘light’, ‘normal’, ‘regular’, ‘book’, ‘medium’,
‘roman’, ‘semibold’, ‘demibold’, ‘demi’, ‘bold’, ‘heavy’, ‘extra bold’, ‘black’}
字体粗细: 可取值:0-1000之间的数值, ‘ultralight’, ‘light’, ‘normal’, ‘regular’, ‘book’, ‘medium’, ‘roman’,‘semibold’, ‘demibold’, ‘demi’, ‘bold’, ‘heavy’, ‘extra bold’, ‘black’
color: 字体颜⾊
verticalalignment: 垂直对齐,可取值:‘center’, ‘top’, ‘bottom’, ‘baseline’, ‘center_baseline’horizontalalignment: ⽔平对齐,可取值: ‘center’, ‘right’, ‘left’
关于verticalalignment和horizontalalignment的使⽤仍需要后期了解发现。
loc参数设置标签的左右移动位置,loc = ‘right’
设置标签的垂直位置,y = 0.5
设置标签的垂直位置,y = 0.0
设置标签的垂直位置,y =1.0(默认设置)
通过pad设置标题偏离图顶部的距离 pad =26
更改pad参数,标题偏离图顶部的距离发⽣改变,pad=6(默认值)

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。