黑松山资源网 Design By www.paidiu.com
在pyplot模块中可以使用xlabel()
和ylabel()
函数设置x
轴y
轴的标签。这两个函数的使用方法非常相似。
使用xlabel()设置x轴标签
函数签名为matplotlib.pyplot.xlabel(xlabel, fontdict=None, labelpad=None, *, loc=None, **kwargs)
参数作用及取值如下:
xlabel
:类型为字符串,即标签的文本。labelpad
:类型为浮点数,默认值为None
,即标签与坐标轴的距离。loc
:取值范围为{'left', 'center', 'right'}
,默认值为rcParams["xaxis.labellocation"]
('center'
),即标签的位置。**kwargs
:Text
对象关键字属性,用于控制文本的外观属性,如字体、文本颜色等。
返回值为Text
对象。
xlabel()
相关rcParams
为:
#axes.labelsize: medium # fontsize of the x any y labels #axes.labelpad: 4.0 # space between label and axis #axes.labelweight: normal # weight of the x and y labels #axes.labelcolor: black #xaxis.labellocation: center # alignment of the xaxis label: {left, right, center}
底层相关函数为:
Axes.set_xlabel(xlabel, fontdict=None, labelpad=None, *, loc=None, **kwargs)
Axes.get_xlabel()
案例
设置x
轴标签,并输出xlabel
函数的返回值。
返回值为Text
对象,输出返回值的属性可知,标签文本的属性为_text
。如果想获取标签文本,可使用Axes.get_xlabel
方法获取。
import matplotlib.pyplot as plt plt.plot([1, 1]) a = plt.xlabel("x") print(a) print(vars(a)) print(a._text) print(plt.gca().get_xlabel()) plt.show()
输出:
Text(0.5, 0, 'x') {'_stale': True, 'stale_callback': None, '_axes': None, 'figure': <Figure size 640x480 with 1 Axes>, '_transform': <matplotlib.transforms.BlendedAffine2D object at 0x0000019EC1471F98>, '_transformSet': True, '_visible': True, '_animated': False, '_alpha': None, 'clipbox': None, '_clippath': None, '_clipon': True, '_label': '', '_picker': None, '_contains': None, '_rasterized': None, '_agg_filter': None, '_mouseover': False, 'eventson': False, '_oid': 0, '_propobservers': {}, '_remove_method': None, '_url': None, '_gid': None, '_snap': None, '_sketch': None, '_path_effects': [], '_sticky_edges': _XYPair(x=[], y=[]), '_in_layout': True, '_x': 0.5, '_y': 0, '_text': 'x', '_color': 'black', '_fontproperties': <matplotlib.font_manager.FontProperties object at 0x0000019EC1471BE0>, '_usetex': False, '_wrap': False, '_verticalalignment': 'top', '_horizontalalignment': 'center', '_multialignment': None, '_rotation': None, '_bbox_patch': None, '_renderer': None, '_linespacing': 1.2, '_rotation_mode': None} x x
使用ylabel()设置y轴标签
函数签名为matplotlib.pyplot.ylabel(ylabel, fontdict=None, labelpad=None, *, loc=None, **kwargs)
参数作用及取值如下:
ylabel
:类型为字符串,即标签的文本。labelpad
:类型为浮点数,默认值为None
,即标签与坐标轴的距离。loc
:取值范围为{'bottom', 'center', 'top'}
,默认值为rcParams["yaxis.labellocation"]
('center'
),即标签的位置。**kwargs
:Text
对象关键字属性,用于控制文本的外观属性,如字体、文本颜色等。
返回值为Text
对象。
xlabel()
相关rcParams
为:
#axes.labelsize: medium # fontsize of the x any y labels #axes.labelpad: 4.0 # space between label and axis #axes.labelweight: normal # weight of the x and y labels #axes.labelcolor: black #yaxis.labellocation: center # alignment of the yaxis label: {bottom, top, center}
底层相关函数为:
Axes.set_ylabel(ylabel, fontdict=None, labelpad=None, *, loc=None, **kwargs)
Axes.get_ylabel()
案例
添加y
轴标签,并设置字体属性和背景色。
import matplotlib.pyplot as plt font = {'family': 'serif', 'color': 'darkred', 'weight': 'normal', 'size': 16, } plt.plot([1, 1]) plt.ylabel("y", fontdict=font, backgroundcolor='grey') plt.show()
黑松山资源网 Design By www.paidiu.com
广告合作:本站广告合作请联系QQ:858582 申请时备注:广告合作(否则不回)
免责声明:本站资源来自互联网收集,仅供用于学习和交流,请遵循相关法律法规,本站一切资源不代表本站立场,如有侵权、后门、不妥请联系本站删除!
免责声明:本站资源来自互联网收集,仅供用于学习和交流,请遵循相关法律法规,本站一切资源不代表本站立场,如有侵权、后门、不妥请联系本站删除!
黑松山资源网 Design By www.paidiu.com
暂无评论...
更新日志
2024年07月03日
2024年07月03日
- 原画壁纸及美图第255期,无水印可自取
- 群星.1991-宝丽金冬日浓情【宝丽金】【WAV+CUE】
- 胡杨林.2006-香水有毒【太格印象】【WAV+CUE】
- 陈晓东.2002-从未忘记2CD【环球】【WAV+CUE】
- 绝区零珂蕾妲阵容怎么搭配好 珂蕾妲队伍搭配攻略
- 绝区零暴击鸣徽有哪些 绝区零暴击鸣徽效果介绍
- 魔兽世界奥格瑞玛法师训练师在哪 奥格瑞玛法师训练师位置介绍
- 《艾尔登法环》dlc带电祷告位置介绍
- 《幻兽帕鲁》泰锋boss坐标位置介绍
- 《山河旅探》6月份更新内容介绍
- 群星.2012《高雄国际Hi-End音响大展纪念发烧金碟(最响宣言)》[WAV分轨].
- 黄宣2021-Beanstalk[否极泰来][WAV+CUE]
- 康康1999-催泪[阿尔法][WAV+CUE]
- 人总有崩溃的时候:你玩过哪些能治愈人心的游戏?
- SteamDeck新增最热玩榜单:综合衡量玩家数和时长