最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

matplotlib之pyplot模塊之標題(title()和suptitle())

 更新時間:2021年02月22日 15:11:19   作者:mighty13  
這篇文章主要介紹了matplotlib之pyplot模塊之標題(title()和suptitle()),文中通過示例代碼介紹的非常詳細,對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧

matplotlib 源碼解析標題實現(xiàn)(窗口標題,標題,子圖標題不同之間的差異)添加鏈接描述簡單比較了matplotlib中的標題。

使用title()設(shè)置子圖標題

title()同時在子圖中顯示中間、左側(cè)、右側(cè)3個標題
函數(shù)簽名為matplotlib.pyplot.title(label, fontdict=None, loc=None, pad=None, *, y=None, **kwargs)
參數(shù)作用及取值如下:

  • 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:類型為浮點數(shù),默認值為rcParams["axes.titley"] (None)。即標題在子圖中的垂直距離,單位為子圖高度的百分比,1.0在子圖最頂部,默認值None則自動確定標題位置,避免與其他元素重疊。
  • pad:類型為浮點數(shù),默認值為default: rcParams["axes.titlepad"] (6.0)。即標題與子圖的填充距離(內(nèi)邊距)。
  • **kwargsText 對象關(guān)鍵字屬性,用于控制文本的外觀屬性,如字體、文本顏色等。

返回值為Text對象。

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

底層相關(guān)方法為:
Axes.set_title(self, label, fontdict=None, loc=None, pad=None, *, y=None, **kwargs)
Axes.get_title(self, loc='center')注意返回指定位置的標題文本。

案例

同時設(shè)置3個子圖標題。

import matplotlib.pyplot as plt

# 注意,子圖可以同時設(shè)置中間、左側(cè)、右側(cè)3個標題
plt.plot([1, 1])
# 在右側(cè)底部顯示子圖標題
plt.title("right bottom",y=0,loc='right')
# 在左側(cè)頂部顯示子圖標題
plt.title("left top",y=1,loc='left')
# 顯示默認子圖標題
plt.title("default")
plt.show()

在這里插入圖片描述

使用suptitle()設(shè)置圖像標題

為圖像添加一個居中標題。
函數(shù)簽名為matplotlib.pyplot.suptitle(t, **kwargs)
參數(shù)作用及取值如下:

  • t:類型為字符串,即標題文本。
  • x:類型為浮點數(shù),即標題在圖像水平方向相對位置,默認值為0.5。
  • y:類型為浮點數(shù),即標題在圖像垂直方向相對位置,默認值為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)的水平方向?qū)R方式。
  • verticalalignment, va:類型為字符串,取值范圍{'top', 'center', 'bottom', 'baseline'},默認值為'top',即相對于(x,y)的垂直方向?qū)R方式。
  • fontsize, size:取值范圍為浮點數(shù)或{'xx-small', 'x-small', 'small', 'medium', 'large', 'x-large', 'xx-large'},默認值為rcParams["figure.titlesize"] ('large'),文本的字體大小。
  • fontweight, weight:取值范圍詳見文檔,字即文本的字重。
  • **kwargsText 對象關(guān)鍵字屬性,用于控制文本的外觀屬性,如字體、文本顏色等。

返回值為Text對象。

suptitle()相關(guān)rcParams為:

#figure.titlesize:  large   # size of the figure title (``Figure.suptitle()``)
#figure.titleweight: normal  # weight of the figure title

案例

添加圖像標題,并設(shè)置坐標、字體大小、文本顏色等屬性。

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

在這里插入圖片描述

到此這篇關(guān)于matplotlib之pyplot模塊之標題(title()和suptitle())的文章就介紹到這了,更多相關(guān)matplotlib title()和suptitle()內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

最新評論

齐河县| 雷州市| 屯留县| 普洱| 宝兴县| 巴彦淖尔市| 苍梧县| 自治县| 霸州市| 英山县| 武平县| 大丰市| 五原县| 施秉县| 织金县| 仙游县| 江源县| 襄垣县| 黄大仙区| 徐水县| 湖州市| 晋州市| 湖南省| 凉城县| 灌阳县| 栾城县| 宣恩县| 洛南县| 九寨沟县| 延津县| 伊宁市| 揭东县| 曲周县| 宁陵县| 酒泉市| 呈贡县| 阿巴嘎旗| 大姚县| 买车| 枞阳县| 望谟县|