python axes get_Python Matplotlib.axes.Axes.get_title()用法及代码示例

Matplotlib是Python中的一个库,它是数字的-NumPy库的数学扩展。轴类包含大多数图形元素:Axis,Tick,Line2D,Text,Polygon等,并设置坐标系。 Axes实例通过callbacks属性支持回调。

matplotlib.axes.Axes.get_title()功能

matplotlib库的axiss模块中的Axes.get_title()函数用于获取轴标题。

用法: Axes.get_title(self, loc=’center’)

参数:此方法接受以下参数。

loc:此参数是可选参数,用于获取哪个标题。

返回:此函数返回标题文本字符串。

以下示例说明了matplotlib.axes中的matplotlib.axes.Axes.get_title()函数:

范例1:

# Implementation of matplotlib function

import os

from matplotlib import font_manager as fm, rcParams

import matplotlib.pyplot as plt

fig, ax = plt.subplots()

fpath = os.path.join(rcParams["datapath"],

"fonts / ttf / cmr10.ttf")

prop = fm.FontProperties(fname = fpath)

fname = os.path.split(fpath)[1]

ax.set_title('Title with special font:{}'.format(fname),

fontproperties = prop, fontsize = 14)

w = ax.get_title()

ax.text(0.2, 0.6, "Previously assigned title:\n\n"+str(w),

fontsize = 14)

ax.set_title("matplotlib.axes.Axes.get_title() \

function Example\n", fontweight ="bold")

plt.show()

输出:

d9723ad79e047c5455dbca386de03f99.png

范例2:

# Implementation of matplotlib function

import numpy as np

import matplotlib.pyplot as plt

x = np.arange(0.1, 5, 0.1)

y = np.exp(-x)

yerr = 0.1 + 0.1 * np.sqrt(x)

fig, (ax, ax1) = plt.subplots(nrows = 1,

ncols = 2,

sharex = True)

ax.errorbar(x, y, yerr = yerr, color ="green")

ax.set_title('Title of Axes 1', fontweight ="bold")

ax1.errorbar(x, y, yerr = yerr, errorevery = 5,

color ="green")

ax1.set_title('Title of Axes 2', fontweight ="bold")

w = ax.get_title()

ww = ax1.get_title()

ax.set_title("")

ax1.set_title("")

ax.set_xlabel(w)

ax1.set_xlabel(ww)

fig.suptitle("Previously assigned title of each Axes is\

used at labels\n", fontweight ="bold")

plt.show()

输出:

5b77a9b62eb90404fbbcd6729a9cbaa6.png

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值