濮阳杆衣贸易有限公司

主頁(yè) > 知識(shí)庫(kù) > matplotlib之pyplot模塊之標(biāo)題(title()和suptitle())

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

熱門標(biāo)簽:正安縣地圖標(biāo)注app 電銷機(jī)器人系統(tǒng)廠家鄭州 舉辦過(guò)冬奧會(huì)的城市地圖標(biāo)注 qt百度地圖標(biāo)注 遼寧智能外呼系統(tǒng)需要多少錢 400電話申請(qǐng)資格 地圖地圖標(biāo)注有嘆號(hào) 阿里電話機(jī)器人對(duì)話 螳螂科技外呼系統(tǒng)怎么用

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

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

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

  • label:類型為字符串,即標(biāo)題文本。
  • fontdict:類型為字典,控制文本的字體屬性。默認(rèn)值為:
{'fontsize': rcParams['axes.titlesize'],
 'fontweight': rcParams['axes.titleweight'],
 'color': rcParams['axes.titlecolor'],
 'verticalalignment': 'baseline',
 'horizontalalignment': loc}
  • loc:取值范圍為{'left', 'center', 'right'},默認(rèn)值為rcParams["axes.titlelocation"]'center'),即標(biāo)題的位置。
  • y:類型為浮點(diǎn)數(shù),默認(rèn)值為rcParams["axes.titley"] (None)。即標(biāo)題在子圖中的垂直距離,單位為子圖高度的百分比,1.0在子圖最頂部,默認(rèn)值None則自動(dòng)確定標(biāo)題位置,避免與其他元素重疊。
  • pad:類型為浮點(diǎn)數(shù),默認(rèn)值為default: rcParams["axes.titlepad"] (6.0)。即標(biāo)題與子圖的填充距離(內(nèi)邊距)。
  • **kwargsText 對(duì)象關(guān)鍵字屬性,用于控制文本的外觀屬性,如字體、文本顏色等。

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

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')注意返回指定位置的標(biāo)題文本。

案例

同時(shí)設(shè)置3個(gè)子圖標(biāo)題。

import matplotlib.pyplot as plt

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

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

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

  • t:類型為字符串,即標(biāo)題文本。
  • x:類型為浮點(diǎn)數(shù),即標(biāo)題在圖像水平方向相對(duì)位置,默認(rèn)值為0.5。
  • y:類型為浮點(diǎn)數(shù),即標(biāo)題在圖像垂直方向相對(duì)位置,默認(rèn)值為0.98。
  • fontdict:類型為字典,控制文本的字體屬性。默認(rèn)值為:
{'fontsize': rcParams['axes.titlesize'],
 'fontweight': rcParams['axes.titleweight'],
 'color': rcParams['axes.titlecolor'],
 'verticalalignment': 'baseline',
 'horizontalalignment': loc}
  • horizontalalignment, ha:類型為字符串,取值范圍{'center', 'left', right'},默認(rèn)值為'center',即相對(duì)于(x,y)的水平方向?qū)R方式。
  • verticalalignment, va:類型為字符串,取值范圍{'top', 'center', 'bottom', 'baseline'},默認(rèn)值為'top',即相對(duì)于(x,y)的垂直方向?qū)R方式。
  • fontsize, size:取值范圍為浮點(diǎn)數(shù)或{'xx-small', 'x-small', 'small', 'medium', 'large', 'x-large', 'xx-large'},默認(rèn)值為rcParams["figure.titlesize"] ('large'),文本的字體大小。
  • fontweight, weight:取值范圍詳見(jiàn)文檔,字即文本的字重。
  • **kwargsText 對(duì)象關(guān)鍵字屬性,用于控制文本的外觀屬性,如字體、文本顏色等。

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

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

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

案例

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

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模塊之標(biāo)題(title()和suptitle())的文章就介紹到這了,更多相關(guān)matplotlib title()和suptitle()內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

您可能感興趣的文章:
  • matplotlib源碼解析標(biāo)題實(shí)現(xiàn)(窗口標(biāo)題,標(biāo)題,子圖標(biāo)題不同之間的差異)
  • matplotlib subplots 設(shè)置總圖的標(biāo)題方法
  • Python使用matplotlib模塊繪制圖像并設(shè)置標(biāo)題與坐標(biāo)軸等信息示例
  • Python使用Matplotlib模塊時(shí)坐標(biāo)軸標(biāo)題中文及各種特殊符號(hào)顯示方法

標(biāo)簽:阜新 信陽(yáng) 淘寶好評(píng)回訪 興安盟 合肥 昭通 濟(jì)源 隨州

巨人網(wǎng)絡(luò)通訊聲明:本文標(biāo)題《matplotlib之pyplot模塊之標(biāo)題(title()和suptitle())》,本文關(guān)鍵詞  matplotlib,之,pyplot,模塊,標(biāo)題,;如發(fā)現(xiàn)本文內(nèi)容存在版權(quán)問(wèn)題,煩請(qǐng)?zhí)峁┫嚓P(guān)信息告之我們,我們將及時(shí)溝通與處理。本站內(nèi)容系統(tǒng)采集于網(wǎng)絡(luò),涉及言論、版權(quán)與本站無(wú)關(guān)。
  • 相關(guān)文章
  • 下面列出與本文章《matplotlib之pyplot模塊之標(biāo)題(title()和suptitle())》相關(guān)的同類信息!
  • 本頁(yè)收集關(guān)于matplotlib之pyplot模塊之標(biāo)題(title()和suptitle())的相關(guān)信息資訊供網(wǎng)民參考!
  • 推薦文章
    凌海市| 蓬溪县| 竹溪县| 龙陵县| 灵台县| 平遥县| 楚雄市| 察隅县| 韶山市| 策勒县| 新郑市| 新闻| 湖北省| 五原县| 六安市| 开阳县| 拜泉县| 小金县| 香港| 长兴县| 嵩明县| 西和县| 阿克苏市| 前郭尔| 广河县| 萨迦县| 息烽县| 利川市| 桦南县| 徐汇区| 格尔木市| 锦屏县| 濉溪县| 富阳市| 平昌县| 沁源县| 肇源县| 永修县| 武宁县| 六安市| 日照市|