欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

matplotlib之pyplot模塊坐標(biāo)軸標(biāo)簽設(shè)置使用(xlabel()、ylabel())

 更新時(shí)間:2021年02月22日 15:25:51   作者:mighty13  
這篇文章主要介紹了matplotlib之pyplot模塊坐標(biāo)軸標(biāo)簽設(shè)置使用(xlabel()、ylabel()),文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧

在pyplot模塊中可以使用xlabel()ylabel()函數(shù)設(shè)置xy軸的標(biāo)簽。這兩個(gè)函數(shù)的使用方法非常相似。

使用xlabel()設(shè)置x軸標(biāo)簽

函數(shù)簽名為matplotlib.pyplot.xlabel(xlabel, fontdict=None, labelpad=None, *, loc=None, **kwargs)
參數(shù)作用及取值如下:

  • xlabel:類型為字符串,即標(biāo)簽的文本。
  • labelpad:類型為浮點(diǎn)數(shù),默認(rèn)值為None,即標(biāo)簽與坐標(biāo)軸的距離。
  • loc:取值范圍為{'left', 'center', 'right'},默認(rèn)值為rcParams["xaxis.labellocation"]'center'),即標(biāo)簽的位置。
  • **kwargsText 對(duì)象關(guān)鍵字屬性,用于控制文本的外觀屬性,如字體、文本顏色等。

返回值為Text對(duì)象。

xlabel()相關(guān)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}

底層相關(guān)函數(shù)為:
Axes.set_xlabel(xlabel, fontdict=None, labelpad=None, *, loc=None, **kwargs)
Axes.get_xlabel()

案例

設(shè)置x軸標(biāo)簽,并輸出xlabel函數(shù)的返回值。
返回值為Text對(duì)象,輸出返回值的屬性可知,標(biāo)簽文本的屬性為_text。如果想獲取標(biāo)簽文本,可使用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()設(shè)置y軸標(biāo)簽

函數(shù)簽名為matplotlib.pyplot.ylabel(ylabel, fontdict=None, labelpad=None, *, loc=None, **kwargs)
參數(shù)作用及取值如下:

  • ylabel:類型為字符串,即標(biāo)簽的文本。
  • labelpad:類型為浮點(diǎn)數(shù),默認(rèn)值為None,即標(biāo)簽與坐標(biāo)軸的距離。
  • loc:取值范圍為{'bottom', 'center', 'top'},默認(rèn)值為rcParams["yaxis.labellocation"]'center'),即標(biāo)簽的位置。
  • **kwargsText 對(duì)象關(guān)鍵字屬性,用于控制文本的外觀屬性,如字體、文本顏色等。

返回值為Text對(duì)象。

xlabel()相關(guān)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}

底層相關(guān)函數(shù)為:
Axes.set_ylabel(ylabel, fontdict=None, labelpad=None, *, loc=None, **kwargs)
Axes.get_ylabel()

案例

添加y軸標(biāo)簽,并設(shè)置字體屬性和背景色。

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()

在這里插入圖片描述

到此這篇關(guān)于matplotlib之pyplot模塊坐標(biāo)軸標(biāo)簽設(shè)置使用(xlabel()、ylabel())的文章就介紹到這了,更多相關(guān)matplotlib 坐標(biāo)軸標(biāo)簽內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

最新評(píng)論