matplotlib 源码解析标题实现(窗口标题,标题,子图标题不同之间的差异)添加链接描述简单比较了matplotlib
中的标题。
使用title()设置子图标题
title()
可同时在子图中显示中间、左侧、右侧3个标题。
函数签名为matplotlib.pyplot.title(label, fontdict=None, loc=None, pad=None, *, y=None, **kwargs)
参数作用及取值如下:
label
:类型为字符串,即标题文本。fontdict
:类型为字典,控制文本的字体属性。默认值为:
{'fontsize': rcParams['axes.titlesize'], 'fontweight': rcParams['axes.titleweight'], 'color': rcParams['axes.titlecolor'], 'verticalalignment': 'baseline', 'horizontalalignment': loc}
loc
:取值范围为{'left', 'center', 'right'}
,默认值为rcParams["axes.titlelocation"]
('center'
),即标题的位置。y
:类型为浮点数,默认值为rcParams["axes.titley"] (None)
。即标题在子图中的垂直距离,单位为子图高度的百分比,1.0
在子图最顶部,默认值None
则自动确定标题位置,避免与其他元素重叠。pad
:类型为浮点数,默认值为default: rcParams["axes.titlepad"] (6.0)
。即标题与子图的填充距离(内边距)。**kwargs
:Text
对象关键字属性,用于控制文本的外观属性,如字体、文本颜色等。
返回值为Text
对象。
title()
相关rcParams
为:
#axes.titlelocation: center # alignment of the title: {left, right, center} #axes.titlesize: large # fontsize of the axes title #axes.titleweight: normal # font weight of title #axes.titlecolor: auto # color of the axes title, auto falls back to # text.color as default value #axes.titley: None # position title (axes relative units). None implies auto #axes.titlepad: 6.0 # pad between axes and title in points
底层相关方法为:
Axes.set_title(self, label, fontdict=None, loc=None, pad=None, *, y=None, **kwargs)
Axes.get_title(self, loc='center')
:注意返回指定位置的标题文本。
案例
同时设置3个子图标题。
import matplotlib.pyplot as plt # 注意,子图可以同时设置中间、左侧、右侧3个标题 plt.plot([1, 1]) # 在右侧底部显示子图标题 plt.title("right bottom",y=0,loc='right') # 在左侧顶部显示子图标题 plt.title("left top",y=1,loc='left') # 显示默认子图标题 plt.title("default") plt.show()
使用suptitle()设置图像标题
为图像添加一个居中标题。
函数签名为matplotlib.pyplot.suptitle(t, **kwargs)
参数作用及取值如下:
t
:类型为字符串,即标题文本。x
:类型为浮点数,即标题在图像水平方向相对位置,默认值为0.5
。y
:类型为浮点数,即标题在图像垂直方向相对位置,默认值为0.98
。fontdict
:类型为字典,控制文本的字体属性。默认值为:
{'fontsize': rcParams['axes.titlesize'], 'fontweight': rcParams['axes.titleweight'], 'color': rcParams['axes.titlecolor'], 'verticalalignment': 'baseline', 'horizontalalignment': loc}
horizontalalignment, ha
:类型为字符串,取值范围{'center', 'left', right'}
,默认值为'center'
,即相对于(x,y)
的水平方向对齐方式。verticalalignment, va
:类型为字符串,取值范围{'top', 'center', 'bottom', 'baseline'}
,默认值为'top'
,即相对于(x,y)
的垂直方向对齐方式。fontsize, size
:取值范围为浮点数或{'xx-small', 'x-small', 'small', 'medium', 'large', 'x-large', 'xx-large'}
,默认值为rcParams["figure.titlesize"] ('large')
,文本的字体大小。fontweight, weight
:取值范围详见文档,字即文本的字重。**kwargs
:Text
对象关键字属性,用于控制文本的外观属性,如字体、文本颜色等。
返回值为Text
对象。
suptitle()
相关rcParams
为:
#figure.titlesize: large # size of the figure title (``Figure.suptitle()``) #figure.titleweight: normal # weight of the figure title
案例
添加图像标题,并设置坐标、字体大小、文本颜色等属性。
import matplotlib.pyplot as plt plt.plot([1, 1]) plt.title("title") plt.suptitle("suptitle", x=0.1, y=0.98, fontsize=16, color='red') plt.show()
免责声明:本站文章均来自网站采集或用户投稿,网站不提供任何软件下载或自行开发的软件!
如有用户或公司发现本站内容信息存在侵权行为,请邮件告知! 858582#qq.com
白云城资源网 Copyright www.dyhadc.com
暂无“matplotlib之pyplot模块之标题(title()和suptitle())”评论...
更新日志
2024年07月03日
2024年07月03日
- 绝区零强袭鸣徽有哪些 绝区零强袭鸣徽效果介绍
- 魔兽世界奥格瑞玛怎么去幽暗城 奥格瑞玛去幽暗城方法介绍
- 《间谍过家家日记大作战》成就攻略一览
- 完美的音乐品质-群星《红酒杯发烧酒廊情歌》2CD[WAV]
- 群星.2011《高雄国际Hi-End音响大展纪念发烧金碟》[WAV分轨]
- 康康1999-催泪[阿尔法][WAV+CUE]
- 和守望先锋太像?《星鸣特攻》开发商:我们与众不同
- 速通玩家有福了!夏季游戏速通大会正在火热进行中
- 《使命召唤》新处决动作曝光 或联动《死侍3》?
- 《陈百强出道35周年 文质翩翩》4CD[WAV+CUE][1.8GB]
- 邓丽君《思君集》3CD[WAV+CUE][1.2GB]
- 华语流行S.H.E《12CD》2001~2010[APE+CUE][3.7GB]
- 北风之望饮品怎么调配?饮品调酒配方分享
- 原画壁纸及美图第254期,无水印可自取
- 原画壁纸及美图第255期,无水印可自取